From 4f6fda558cb1f1b2b02cb6d276a6e57ac0e5dabb Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 27 Jan 2019 06:47:27 -0800 Subject: [PATCH] Add a grisu test stub --- src/format.cc | 4 ++++ test/CMakeLists.txt | 1 + test/grisu-test.cc | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/grisu-test.cc diff --git a/src/format.cc b/src/format.cc index 33a97ffc..4e71fde6 100644 --- a/src/format.cc +++ b/src/format.cc @@ -10,6 +10,10 @@ FMT_BEGIN_NAMESPACE template struct internal::basic_data; +// Workaround a bug in MSVC2013 that prevents instantiation of grisu2_format. +bool (*instantiate_grisu2_format)(double, internal::buffer&, + core_format_specs) = internal::grisu2_format; + #ifndef FMT_STATIC_THOUSANDS_SEPARATOR template FMT_API internal::locale_ref::locale_ref(const std::locale& loc); template FMT_API std::locale internal::locale_ref::get() const; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 759b43ed..0f349122 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -87,6 +87,7 @@ endfunction() add_fmt_test(assert-test) add_fmt_test(chrono-test) add_fmt_test(core-test) +add_fmt_test(grisu-test) add_fmt_test(gtest-extra-test) add_fmt_test(format-test mock-allocator.h) if (NOT (MSVC AND BUILD_SHARED_LIBS)) diff --git a/test/grisu-test.cc b/test/grisu-test.cc new file mode 100644 index 00000000..bc4601ee --- /dev/null +++ b/test/grisu-test.cc @@ -0,0 +1,29 @@ +// Formatting library for C++ - Grisu tests +// +// Copyright (c) 2012 - present, Victor Zverovich +// All rights reserved. +// +// For the license information refer to format.h. + +#define FMT_USE_GRISU std::numeric_limits::is_iec559 +#include "fmt/format.h" +#include "gtest.h" + +bool reported_skipped; + +#undef TEST +#define TEST(test_fixture, test_name) \ + void test_fixture##test_name(); \ + GTEST_TEST(test_fixture, test_name) { \ + if (FMT_USE_GRISU) { \ + test_fixture##test_name(); \ + } else if (!reported_skipped) { \ + reported_skipped = true; \ + fmt::print("Skipping Grisu tests.\n"); \ + } \ + } \ + void test_fixture##test_name() + +TEST(GrisuTest, NaN) { + EXPECT_EQ("nan", fmt::format("{}", std::numeric_limits::quiet_NaN())); +}