aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/fmt/test/compile-fp-test.cc
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-11-07 14:49:13 +0100
committerGitHub Enterprise <[email protected]>2025-11-07 14:49:13 +0100
commit24e43a913f29ac3b314354e8ce5175f135bcc64f (patch)
treeca442937ceeb63461012b33a4576e9835099f106 /thirdparty/fmt/test/compile-fp-test.cc
parentget oplog attachments (#622) (diff)
downloadzen-24e43a913f29ac3b314354e8ce5175f135bcc64f.tar.xz
zen-24e43a913f29ac3b314354e8ce5175f135bcc64f.zip
switch to xmake for package management (#611)
This change removes our dependency on vcpkg for package management, in favour of bringing some code in-tree in the `thirdparty` folder as well as using the xmake build-in package management feature. For the latter, all the package definitions are maintained in the zen repo itself, in the `repo` folder. It should now also be easier to build the project as it will no longer depend on having the right version of vcpkg installed, which has been a common problem for new people coming in to the codebase. Now you should only need xmake to build. * Bumps xmake requirement on github runners to 2.9.9 to resolve an issue where xmake on Windows invokes cmake with `v144` toolchain which does not exist * BLAKE3 is now in-tree at `thirdparty/blake3` * cpr is now in-tree at `thirdparty/cpr` * cxxopts is now in-tree at `thirdparty/cxxopts` * fmt is now in-tree at `thirdparty/fmt` * robin-map is now in-tree at `thirdparty/robin-map` * ryml is now in-tree at `thirdparty/ryml` * sol2 is now in-tree at `thirdparty/sol2` * spdlog is now in-tree at `thirdparty/spdlog` * utfcpp is now in-tree at `thirdparty/utfcpp` * xmake package repo definitions is in `repo` * implemented support for sanitizers. ASAN is supported on windows, TSAN, UBSAN, MSAN etc are supported on Linux/MacOS though I have not yet tested it extensively on MacOS * the zencore encryption implementation also now supports using mbedTLS which is used on MacOS, though for now we still use openssl on Linux * crashpad * bumps libcurl to 8.11.0 (from 8.8.0) which should address a rare build upload bug
Diffstat (limited to 'thirdparty/fmt/test/compile-fp-test.cc')
-rw-r--r--thirdparty/fmt/test/compile-fp-test.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/thirdparty/fmt/test/compile-fp-test.cc b/thirdparty/fmt/test/compile-fp-test.cc
new file mode 100644
index 000000000..e1522c728
--- /dev/null
+++ b/thirdparty/fmt/test/compile-fp-test.cc
@@ -0,0 +1,62 @@
+// Formatting library for C++ - formatting library tests
+//
+// Copyright (c) 2012 - present, Victor Zverovich
+// All rights reserved.
+//
+// For the license information refer to format.h.
+
+#include "fmt/compile.h"
+#include "gmock/gmock.h"
+
+#if FMT_USE_CONSTEVAL
+
+template <size_t max_string_length, typename Char = char> struct test_string {
+ Char buffer[max_string_length] = {};
+
+ template <typename T> constexpr bool operator==(const T& rhs) const noexcept {
+ return fmt::basic_string_view<Char>(rhs).compare(buffer) == 0;
+ }
+};
+
+template <size_t max_string_length, typename Char = char, typename... Args>
+consteval auto test_format(auto format, const Args&... args) {
+ test_string<max_string_length, Char> string{};
+ fmt::format_to(string.buffer, format, args...);
+ return string;
+}
+
+TEST(compile_time_formatting_test, floating_point) {
+ EXPECT_EQ("0", test_format<2>(FMT_COMPILE("{}"), 0.0f));
+ EXPECT_EQ("392.500000", test_format<11>(FMT_COMPILE("{0:f}"), 392.5f));
+
+ EXPECT_EQ("0", test_format<2>(FMT_COMPILE("{:}"), 0.0));
+ EXPECT_EQ("0.000000", test_format<9>(FMT_COMPILE("{:f}"), 0.0));
+ EXPECT_EQ("0", test_format<2>(FMT_COMPILE("{:g}"), 0.0));
+ EXPECT_EQ("392.65", test_format<7>(FMT_COMPILE("{:}"), 392.65));
+ EXPECT_EQ("392.65", test_format<7>(FMT_COMPILE("{:g}"), 392.65));
+ EXPECT_EQ("392.65", test_format<7>(FMT_COMPILE("{:G}"), 392.65));
+ EXPECT_EQ("4.9014e+06", test_format<11>(FMT_COMPILE("{:g}"), 4.9014e6));
+ EXPECT_EQ("-392.650000", test_format<12>(FMT_COMPILE("{:f}"), -392.65));
+ EXPECT_EQ("-392.650000", test_format<12>(FMT_COMPILE("{:F}"), -392.65));
+
+ EXPECT_EQ("3.926500e+02", test_format<13>(FMT_COMPILE("{0:e}"), 392.65));
+ EXPECT_EQ("3.926500E+02", test_format<13>(FMT_COMPILE("{0:E}"), 392.65));
+ EXPECT_EQ("+0000392.6", test_format<11>(FMT_COMPILE("{0:+010.4g}"), 392.65));
+ EXPECT_EQ("9223372036854775808.000000",
+ test_format<27>(FMT_COMPILE("{:f}"), 9223372036854775807.0));
+
+ constexpr double nan = std::numeric_limits<double>::quiet_NaN();
+ EXPECT_EQ("nan", test_format<4>(FMT_COMPILE("{}"), nan));
+ EXPECT_EQ("+nan", test_format<5>(FMT_COMPILE("{:+}"), nan));
+ if (std::signbit(-nan))
+ EXPECT_EQ("-nan", test_format<5>(FMT_COMPILE("{}"), -nan));
+ else
+ fmt::print("Warning: compiler doesn't handle negative NaN correctly");
+
+ constexpr double inf = std::numeric_limits<double>::infinity();
+ EXPECT_EQ("inf", test_format<4>(FMT_COMPILE("{}"), inf));
+ EXPECT_EQ("+inf", test_format<5>(FMT_COMPILE("{:+}"), inf));
+ EXPECT_EQ("-inf", test_format<5>(FMT_COMPILE("{}"), -inf));
+}
+
+#endif // FMT_USE_CONSTEVAL