diff --git a/test/format-test.cc b/test/format-test.cc index c75d31d2..f79c4cf0 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -72,15 +72,31 @@ using fmt::pad; namespace { +// Format value using the standard library. +template +std::basic_string std_format(const T &value) { + std::basic_ostringstream os; + os << value; + return os.str(); +} + +#ifdef __MINGW32__ +// Workaround a bug in formatting long double in MinGW. +template +std::basic_string std_format(long double value) { + char buffer[100]; + sprintf_s(buffer, sizeof(buffer), "%Lg", value); + return buffer; +} +#endif + // Checks if writing value to BasicWriter produces the same result // as writing it to std::basic_ostringstream. template ::testing::AssertionResult check_write(const T &value, const char *type) { - std::basic_ostringstream os; - os << value; - std::basic_string expected = os.str(); std::basic_string actual = (fmt::BasicMemoryWriter() << value).str(); + std::basic_string expected = std_format(value); if (expected == actual) return ::testing::AssertionSuccess(); return ::testing::AssertionFailure()