From 34c1491418989da7da8fe5e64ba672800ecb5a37 Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Thu, 3 Dec 2020 13:04:26 -0800 Subject: [PATCH] Add test --- test/CMakeLists.txt | 4 ++++ test/enforce-compiletime-test.cc | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/enforce-compiletime-test.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 45721a6d..e6f95733 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -106,6 +106,10 @@ add_fmt_test(printf-test) add_fmt_test(ranges-test) add_fmt_test(scan-test) + +add_fmt_test(enforce-compiletime-test) +target_compile_definitions(enforce-compiletime-test PRIVATE "-DFMT_ENFORCE_COMPILE_STRING") + if (NOT DEFINED MSVC_STATIC_RUNTIME AND MSVC) foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE diff --git a/test/enforce-compiletime-test.cc b/test/enforce-compiletime-test.cc new file mode 100644 index 00000000..8428bcc5 --- /dev/null +++ b/test/enforce-compiletime-test.cc @@ -0,0 +1,29 @@ +// Formatting library for C++ - formatting library tests +// +// Copyright (c) 2012 - present, Victor Zverovich +// All rights reserved. +// +// For the license information refer to format.h. + + +#ifdef WIN32 +# define _CRT_SECURE_NO_WARNINGS +#endif + +#include "fmt/chrono.h" +#include "fmt/format.h" + +#include "gmock.h" +#include "gtest-extra.h" + +#ifndef FMT_STATIC_THOUSANDS_SEPARATOR + +TEST(ChronoTest, FormatDefault) { + EXPECT_EQ("42s", fmt::format(FMT_STRING("{}"), std::chrono::seconds(42))); +} + +TEST(ChronoTest, FormatWide) { + EXPECT_EQ(L"42s", fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42))); +} + +#endif // FMT_STATIC_THOUSANDS_SEPARATOR