diff options
| author | Stefan Boberg <[email protected]> | 2025-11-07 14:49:13 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-11-07 14:49:13 +0100 |
| commit | 24e43a913f29ac3b314354e8ce5175f135bcc64f (patch) | |
| tree | ca442937ceeb63461012b33a4576e9835099f106 /thirdparty/ryml/test/test_number.cpp | |
| parent | get oplog attachments (#622) (diff) | |
| download | zen-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/ryml/test/test_number.cpp')
| -rw-r--r-- | thirdparty/ryml/test/test_number.cpp | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/thirdparty/ryml/test/test_number.cpp b/thirdparty/ryml/test/test_number.cpp new file mode 100644 index 000000000..41c388ae6 --- /dev/null +++ b/thirdparty/ryml/test/test_number.cpp @@ -0,0 +1,217 @@ +#include "./test_group.hpp" + +namespace c4 { +namespace yml { + +template<class I> +auto mkvals() -> typename std::enable_if<std::is_signed<I>::value, std::vector<I>>::type +{ + return std::vector<I>({std::numeric_limits<I>::min(), -10, -5, -1, 0, 1, 5, 10, std::numeric_limits<I>::max(),}); +} +template<class I> +auto mkvals() -> typename std::enable_if<!std::is_signed<I>::value, std::vector<I>>::type +{ + return std::vector<I>({0, 1, 5, 10, std::numeric_limits<I>::max(),}); +} +template<class I> +void test_ints() +{ + C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast") + std::vector<I> values = mkvals<I>(); + Tree t = parse_in_arena("{dec: [], hex: [], bin: [], oct: [], versions: ['0.1', 0.1.2, 0.1.2.3, 0.1.2.3.4]}"); + NodeRef r = t.rootref(); + for(I val : values) + { + I out; + r["dec"].append_child() << val; + r["hex"].append_child() << fmt::hex(val); + r["bin"].append_child() << fmt::bin(val); + r["oct"].append_child() << fmt::oct(val); + out = (I)(val + I(1)); + r["dec"].last_child() >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + r["hex"].last_child() >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + r["bin"].last_child() >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + r["oct"].last_child() >> out; + EXPECT_EQ(out, val); + } + { + std::string emitted = emitrs_yaml<std::string>(t); + Tree parsed = parse_in_place(to_substr(emitted)); + ASSERT_EQ(parsed["dec"].num_children(), values.size()); + ASSERT_EQ(parsed["hex"].num_children(), values.size()); + ASSERT_EQ(parsed["bin"].num_children(), values.size()); + ASSERT_EQ(parsed["oct"].num_children(), values.size()); + ASSERT_EQ(parsed["versions"].num_children(), 4u); + size_t pos = 0; + for(I val : values) + { + I out = (I)(val + I(1)); + parsed["dec"][pos] >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + parsed["hex"][pos] >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + parsed["bin"][pos]>> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + parsed["oct"][pos] >> out; + EXPECT_EQ(out, val); + ++pos; + } + EXPECT_EQ(parsed["versions"][0], "0.1"); + EXPECT_EQ(parsed["versions"][1], "0.1.2"); + EXPECT_EQ(parsed["versions"][2], "0.1.2.3"); + EXPECT_EQ(parsed["versions"][3], "0.1.2.3.4"); + } + { + std::string emitted = emitrs_json<std::string>(t); + Tree parsed = parse_in_place(to_substr(emitted)); + ASSERT_EQ(parsed["dec"].num_children(), values.size()); + ASSERT_EQ(parsed["hex"].num_children(), values.size()); + ASSERT_EQ(parsed["bin"].num_children(), values.size()); + ASSERT_EQ(parsed["oct"].num_children(), values.size()); + ASSERT_EQ(parsed["versions"].num_children(), 4u); + size_t pos = 0; + for(I val : values) + { + I out = (I)(val + I(1)); + parsed["dec"][pos] >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + parsed["hex"][pos] >> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + parsed["bin"][pos]>> out; + EXPECT_EQ(out, val); + out = (I)(val + I(1)); + parsed["oct"][pos] >> out; + EXPECT_EQ(out, val); + ++pos; + } + EXPECT_EQ(parsed["versions"][0], "0.1"); + EXPECT_EQ(parsed["versions"][1], "0.1.2"); + EXPECT_EQ(parsed["versions"][2], "0.1.2.3"); + EXPECT_EQ(parsed["versions"][3], "0.1.2.3.4"); + } + C4_SUPPRESS_WARNING_GCC_POP +} + +TEST(number, idec) +{ + test_ints<int8_t>(); + test_ints<int16_t>(); + test_ints<int32_t>(); + test_ints<int64_t>(); + test_ints<uint8_t>(); + test_ints<uint16_t>(); + test_ints<uint32_t>(); + test_ints<uint64_t>(); +} + + + +CASE_GROUP(NUMBER) +{ + +ADD_CASE_TO_GROUP("integer numbers, flow", JSON_ALSO, +R"(translation: [-2, -2, 5, 0xa, -0xb, 0XA, -0XA, 0b10, -0b10, 0B10, -0B10, 0o17, -0o17, 0O17, -0O17])", +L{N("translation", L{ + N("-2"), N("-2"), N("5"), + N("0xa"), N("-0xb"), + N("0XA"), N("-0XA"), + N("0b10"), N("-0b10"), + N("0B10"), N("-0B10"), + N("0o17"), N("-0o17"), + N("0O17"), N("-0O17"), +})}); + +ADD_CASE_TO_GROUP("integer numbers, block", JSON_ALSO, +R"(translation: + - -2 + - -2 + - -5 +)", +L{N("translation", L{N("-2"), N("-2"), N("-5")})} +); + +ADD_CASE_TO_GROUP("floating point numbers, flow", JSON_ALSO, +R"([-2.0, -2.1, 0.1, .1, -.2, -2.e+6, -3e-6, 1.12345e+011])", +L{N("-2.0"), N("-2.1"), N("0.1"), N(".1"), N("-.2"), N("-2.e+6"), N("-3e-6"), N("1.12345e+011")} +); + +ADD_CASE_TO_GROUP("floating point numbers, block", JSON_ALSO, +R"( +- -2.0 +- -2.1 +- 0.1 +- .1 +- -.2 +- -2.e+6 +- -3e-6 +- 1.12345e+011 +)", +L{N("-2.0"), N("-2.1"), N("0.1"), N(".1"), N("-.2"), N("-2.e+6"), N("-3e-6"), N("1.12345e+011")} +); + +ADD_CASE_TO_GROUP("hex floating point numbers, block", JSON_ALSO, +R"( +- -2.0 +- -2.1 +- 0.1 +- .1 +- -.2 +- -2.e+6 +- -3e-6 +- 1.12345e+011 +)", +L{N("-2.0"), N("-2.1"), N("0.1"), N(".1"), N("-.2"), N("-2.e+6"), N("-3e-6"), N("1.12345e+011")} +); + +ADD_CASE_TO_GROUP("version numbers", JSON_ALSO, +R"( +- 1.2.3 +- 1.2.3.4 +- [1.2.3, 4.5.6] +- [1.2.3.4, 4.5.6.7] +- - 1.2.3 + - 4.5.6 +- - 1.2.3.4 + - 4.5.6.7 +- a: 1.2.3 +- a: 1.2.3.4 +- {a: 1.2.3} +- {a: 1.2.3.4} +- a: 1.2.3 + b: 4.5.6 +- a: 1.2.3.4 + b: 4.5.6.7 +- {a: 1.2.3, b: 4.5.6} +- {a: 1.2.3.4, b: 4.5.6.7} +)", +L{ + N("1.2.3"), + N("1.2.3.4"), + N(L{N("1.2.3"), N("4.5.6")}), + N(L{N("1.2.3.4"), N("4.5.6.7")}), + N(L{N("1.2.3"), N("4.5.6")}), + N(L{N("1.2.3.4"), N("4.5.6.7")}), + N(L{N("a", "1.2.3")}), + N(L{N("a", "1.2.3.4")}), + N(L{N("a", "1.2.3")}), + N(L{N("a", "1.2.3.4")}), + N(L{N("a", "1.2.3"), N("b", "4.5.6")}), + N(L{N("a", "1.2.3.4"), N("b", "4.5.6.7")}), + N(L{N("a", "1.2.3"), N("b", "4.5.6")}), + N(L{N("a", "1.2.3.4"), N("b", "4.5.6.7")}), +}); +} + +} // namespace yml +} // namespace c4 |