1c5f01b2fSopenharmony_ci// __ _____ _____ _____ 2c5f01b2fSopenharmony_ci// __| | __| | | | JSON for Modern C++ (supporting code) 3c5f01b2fSopenharmony_ci// | | |__ | | | | | | version 3.11.2 4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___| https://github.com/nlohmann/json 5c5f01b2fSopenharmony_ci// 6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT 8c5f01b2fSopenharmony_ci 9c5f01b2fSopenharmony_ci// cmake/test.cmake selects the C++ standard versions with which to build a 10c5f01b2fSopenharmony_ci// unit test based on the presence of JSON_HAS_CPP_<VERSION> macros. 11c5f01b2fSopenharmony_ci// When using macros that are only defined for particular versions of the standard 12c5f01b2fSopenharmony_ci// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding 13c5f01b2fSopenharmony_ci// version macro in a comment close by, like this: 14c5f01b2fSopenharmony_ci// JSON_HAS_CPP_<VERSION> (do not remove; see note at top of file) 15c5f01b2fSopenharmony_ci 16c5f01b2fSopenharmony_ci#include "doctest_compatibility.h" 17c5f01b2fSopenharmony_ci 18c5f01b2fSopenharmony_ci#define JSON_TESTS_PRIVATE 19c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp> 20c5f01b2fSopenharmony_ciusing nlohmann::json; 21c5f01b2fSopenharmony_ci 22c5f01b2fSopenharmony_ci#if JSON_HAS_THREE_WAY_COMPARISON 23c5f01b2fSopenharmony_ci// this can be replaced with the doctest stl extension header in version 2.5 24c5f01b2fSopenharmony_cinamespace doctest 25c5f01b2fSopenharmony_ci{ 26c5f01b2fSopenharmony_citemplate<> struct StringMaker<std::partial_ordering> 27c5f01b2fSopenharmony_ci{ 28c5f01b2fSopenharmony_ci static String convert(const std::partial_ordering& order) 29c5f01b2fSopenharmony_ci { 30c5f01b2fSopenharmony_ci if (order == std::partial_ordering::less) 31c5f01b2fSopenharmony_ci { 32c5f01b2fSopenharmony_ci return "std::partial_ordering::less"; 33c5f01b2fSopenharmony_ci } 34c5f01b2fSopenharmony_ci if (order == std::partial_ordering::equivalent) 35c5f01b2fSopenharmony_ci { 36c5f01b2fSopenharmony_ci return "std::partial_ordering::equivalent"; 37c5f01b2fSopenharmony_ci } 38c5f01b2fSopenharmony_ci if (order == std::partial_ordering::greater) 39c5f01b2fSopenharmony_ci { 40c5f01b2fSopenharmony_ci return "std::partial_ordering::greater"; 41c5f01b2fSopenharmony_ci } 42c5f01b2fSopenharmony_ci if (order == std::partial_ordering::unordered) 43c5f01b2fSopenharmony_ci { 44c5f01b2fSopenharmony_ci return "std::partial_ordering::unordered"; 45c5f01b2fSopenharmony_ci } 46c5f01b2fSopenharmony_ci return "{?}"; 47c5f01b2fSopenharmony_ci } 48c5f01b2fSopenharmony_ci}; 49c5f01b2fSopenharmony_ci} // namespace doctest 50c5f01b2fSopenharmony_ci#endif 51c5f01b2fSopenharmony_ci 52c5f01b2fSopenharmony_cinamespace 53c5f01b2fSopenharmony_ci{ 54c5f01b2fSopenharmony_ci// helper function to check std::less<json::value_t> 55c5f01b2fSopenharmony_ci// see https://en.cppreference.com/w/cpp/utility/functional/less 56c5f01b2fSopenharmony_citemplate <typename A, typename B, typename U = std::less<json::value_t>> 57c5f01b2fSopenharmony_cibool f(A a, B b, U u = U()) 58c5f01b2fSopenharmony_ci{ 59c5f01b2fSopenharmony_ci return u(a, b); 60c5f01b2fSopenharmony_ci} 61c5f01b2fSopenharmony_ci} // namespace 62c5f01b2fSopenharmony_ci 63c5f01b2fSopenharmony_ciTEST_CASE("lexicographical comparison operators") 64c5f01b2fSopenharmony_ci{ 65c5f01b2fSopenharmony_ci constexpr auto f_ = false; 66c5f01b2fSopenharmony_ci constexpr auto _t = true; 67c5f01b2fSopenharmony_ci constexpr auto nan = std::numeric_limits<json::number_float_t>::quiet_NaN(); 68c5f01b2fSopenharmony_ci#if JSON_HAS_THREE_WAY_COMPARISON 69c5f01b2fSopenharmony_ci constexpr auto lt = std::partial_ordering::less; 70c5f01b2fSopenharmony_ci constexpr auto gt = std::partial_ordering::greater; 71c5f01b2fSopenharmony_ci constexpr auto eq = std::partial_ordering::equivalent; 72c5f01b2fSopenharmony_ci constexpr auto un = std::partial_ordering::unordered; 73c5f01b2fSopenharmony_ci#endif 74c5f01b2fSopenharmony_ci 75c5f01b2fSopenharmony_ci#if JSON_HAS_THREE_WAY_COMPARISON 76c5f01b2fSopenharmony_ci INFO("using 3-way comparison"); 77c5f01b2fSopenharmony_ci#endif 78c5f01b2fSopenharmony_ci 79c5f01b2fSopenharmony_ci#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 80c5f01b2fSopenharmony_ci INFO("using legacy comparison"); 81c5f01b2fSopenharmony_ci#endif 82c5f01b2fSopenharmony_ci 83c5f01b2fSopenharmony_ci //REQUIRE(std::numeric_limits<json::number_float_t>::has_quiet_NaN); 84c5f01b2fSopenharmony_ci REQUIRE(std::isnan(nan)); 85c5f01b2fSopenharmony_ci 86c5f01b2fSopenharmony_ci SECTION("types") 87c5f01b2fSopenharmony_ci { 88c5f01b2fSopenharmony_ci std::vector<json::value_t> j_types = 89c5f01b2fSopenharmony_ci { 90c5f01b2fSopenharmony_ci json::value_t::null, 91c5f01b2fSopenharmony_ci json::value_t::boolean, 92c5f01b2fSopenharmony_ci json::value_t::number_integer, 93c5f01b2fSopenharmony_ci json::value_t::number_unsigned, 94c5f01b2fSopenharmony_ci json::value_t::number_float, 95c5f01b2fSopenharmony_ci json::value_t::object, 96c5f01b2fSopenharmony_ci json::value_t::array, 97c5f01b2fSopenharmony_ci json::value_t::string, 98c5f01b2fSopenharmony_ci json::value_t::binary, 99c5f01b2fSopenharmony_ci json::value_t::discarded 100c5f01b2fSopenharmony_ci }; 101c5f01b2fSopenharmony_ci 102c5f01b2fSopenharmony_ci std::vector<std::vector<bool>> expected_lt = 103c5f01b2fSopenharmony_ci { 104c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 105c5f01b2fSopenharmony_ci {f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0 106c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1 107c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 2 108c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3 109c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 4 110c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5 111c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, _t, _t, f_}, // 6 112c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7 113c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 114c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 115c5f01b2fSopenharmony_ci }; 116c5f01b2fSopenharmony_ci 117c5f01b2fSopenharmony_ci SECTION("comparison: less") 118c5f01b2fSopenharmony_ci { 119c5f01b2fSopenharmony_ci REQUIRE(expected_lt.size() == j_types.size()); 120c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_types.size(); ++i) 121c5f01b2fSopenharmony_ci { 122c5f01b2fSopenharmony_ci REQUIRE(expected_lt[i].size() == j_types.size()); 123c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_types.size(); ++j) 124c5f01b2fSopenharmony_ci { 125c5f01b2fSopenharmony_ci CAPTURE(i) 126c5f01b2fSopenharmony_ci CAPTURE(j) 127c5f01b2fSopenharmony_ci // check precomputed values 128c5f01b2fSopenharmony_ci#if JSON_HAS_THREE_WAY_COMPARISON 129c5f01b2fSopenharmony_ci // JSON_HAS_CPP_20 (do not remove; see note at top of file) 130c5f01b2fSopenharmony_ci CHECK((j_types[i] < j_types[j]) == expected_lt[i][j]); 131c5f01b2fSopenharmony_ci#else 132c5f01b2fSopenharmony_ci CHECK(operator<(j_types[i], j_types[j]) == expected_lt[i][j]); 133c5f01b2fSopenharmony_ci#endif 134c5f01b2fSopenharmony_ci CHECK(f(j_types[i], j_types[j]) == expected_lt[i][j]); 135c5f01b2fSopenharmony_ci } 136c5f01b2fSopenharmony_ci } 137c5f01b2fSopenharmony_ci } 138c5f01b2fSopenharmony_ci#if JSON_HAS_THREE_WAY_COMPARISON 139c5f01b2fSopenharmony_ci // JSON_HAS_CPP_20 (do not remove; see note at top of file) 140c5f01b2fSopenharmony_ci SECTION("comparison: 3-way") 141c5f01b2fSopenharmony_ci { 142c5f01b2fSopenharmony_ci std::vector<std::vector<std::partial_ordering>> expected = 143c5f01b2fSopenharmony_ci { 144c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 145c5f01b2fSopenharmony_ci {eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0 146c5f01b2fSopenharmony_ci {gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1 147c5f01b2fSopenharmony_ci {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 2 148c5f01b2fSopenharmony_ci {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3 149c5f01b2fSopenharmony_ci {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4 150c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, eq, lt, lt, lt, un}, // 5 151c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6 152c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, eq, lt, un}, // 7 153c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8 154c5f01b2fSopenharmony_ci {un, un, un, un, un, un, un, un, un, un}, // 9 155c5f01b2fSopenharmony_ci }; 156c5f01b2fSopenharmony_ci 157c5f01b2fSopenharmony_ci // check expected partial_ordering against expected boolean 158c5f01b2fSopenharmony_ci REQUIRE(expected.size() == expected_lt.size()); 159c5f01b2fSopenharmony_ci for (size_t i = 0; i < expected.size(); ++i) 160c5f01b2fSopenharmony_ci { 161c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == expected_lt[i].size()); 162c5f01b2fSopenharmony_ci for (size_t j = 0; j < expected[i].size(); ++j) 163c5f01b2fSopenharmony_ci { 164c5f01b2fSopenharmony_ci CAPTURE(i) 165c5f01b2fSopenharmony_ci CAPTURE(j) 166c5f01b2fSopenharmony_ci CHECK(std::is_lt(expected[i][j]) == expected_lt[i][j]); 167c5f01b2fSopenharmony_ci } 168c5f01b2fSopenharmony_ci } 169c5f01b2fSopenharmony_ci 170c5f01b2fSopenharmony_ci // check 3-way comparison against expected partial_ordering 171c5f01b2fSopenharmony_ci REQUIRE(expected.size() == j_types.size()); 172c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_types.size(); ++i) 173c5f01b2fSopenharmony_ci { 174c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == j_types.size()); 175c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_types.size(); ++j) 176c5f01b2fSopenharmony_ci { 177c5f01b2fSopenharmony_ci CAPTURE(i) 178c5f01b2fSopenharmony_ci CAPTURE(j) 179c5f01b2fSopenharmony_ci CHECK((j_types[i] <=> j_types[j]) == expected[i][j]); // *NOPAD* 180c5f01b2fSopenharmony_ci } 181c5f01b2fSopenharmony_ci } 182c5f01b2fSopenharmony_ci } 183c5f01b2fSopenharmony_ci#endif 184c5f01b2fSopenharmony_ci } 185c5f01b2fSopenharmony_ci 186c5f01b2fSopenharmony_ci SECTION("values") 187c5f01b2fSopenharmony_ci { 188c5f01b2fSopenharmony_ci json j_values = 189c5f01b2fSopenharmony_ci { 190c5f01b2fSopenharmony_ci nullptr, nullptr, // 0 1 191c5f01b2fSopenharmony_ci -17, 42, // 2 3 192c5f01b2fSopenharmony_ci 8u, 13u, // 4 5 193c5f01b2fSopenharmony_ci 3.14159, 23.42, // 6 7 194c5f01b2fSopenharmony_ci nan, nan, // 8 9 195c5f01b2fSopenharmony_ci "foo", "bar", // 10 11 196c5f01b2fSopenharmony_ci true, false, // 12 13 197c5f01b2fSopenharmony_ci {1, 2, 3}, {"one", "two", "three"}, // 14 15 198c5f01b2fSopenharmony_ci {{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}}, // 16 17 199c5f01b2fSopenharmony_ci json::binary({1, 2, 3}), json::binary({1, 2, 4}), // 18 19 200c5f01b2fSopenharmony_ci json(json::value_t::discarded), json(json::value_t::discarded) // 20 21 201c5f01b2fSopenharmony_ci }; 202c5f01b2fSopenharmony_ci 203c5f01b2fSopenharmony_ci std::vector<std::vector<bool>> expected_eq = 204c5f01b2fSopenharmony_ci { 205c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 206c5f01b2fSopenharmony_ci {_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0 207c5f01b2fSopenharmony_ci {_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1 208c5f01b2fSopenharmony_ci {f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2 209c5f01b2fSopenharmony_ci {f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3 210c5f01b2fSopenharmony_ci {f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4 211c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5 212c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6 213c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7 214c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 215c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 216c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10 217c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11 218c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12 219c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_}, // 13 220c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_}, // 14 221c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_}, // 15 222c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_}, // 16 223c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_}, // 17 224c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_}, // 18 225c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 19 226c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 227c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 228c5f01b2fSopenharmony_ci }; 229c5f01b2fSopenharmony_ci 230c5f01b2fSopenharmony_ci std::vector<std::vector<bool>> expected_lt = 231c5f01b2fSopenharmony_ci { 232c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 233c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 0 234c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 1 235c5f01b2fSopenharmony_ci {f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 2 236c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 3 237c5f01b2fSopenharmony_ci {f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 4 238c5f01b2fSopenharmony_ci {f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 5 239c5f01b2fSopenharmony_ci {f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 6 240c5f01b2fSopenharmony_ci {f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 7 241c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 8 242c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 9 243c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 10 244c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 11 245c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 12 246c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 13 247c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_}, // 14 248c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 15 249c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_}, // 16 250c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_}, // 17 251c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 18 252c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19 253c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 254c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 255c5f01b2fSopenharmony_ci }; 256c5f01b2fSopenharmony_ci 257c5f01b2fSopenharmony_ci SECTION("compares unordered") 258c5f01b2fSopenharmony_ci { 259c5f01b2fSopenharmony_ci std::vector<std::vector<bool>> expected = 260c5f01b2fSopenharmony_ci { 261c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 262c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 0 263c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 1 264c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 2 265c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 3 266c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 4 267c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 5 268c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 6 269c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 7 270c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 8 271c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 9 272c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 10 273c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 11 274c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 12 275c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 13 276c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 14 277c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 15 278c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 16 279c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 17 280c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 18 281c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19 282c5f01b2fSopenharmony_ci {_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 20 283c5f01b2fSopenharmony_ci {_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21 284c5f01b2fSopenharmony_ci }; 285c5f01b2fSopenharmony_ci 286c5f01b2fSopenharmony_ci // check if two values compare unordered as expected 287c5f01b2fSopenharmony_ci REQUIRE(expected.size() == j_values.size()); 288c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 289c5f01b2fSopenharmony_ci { 290c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == j_values.size()); 291c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 292c5f01b2fSopenharmony_ci { 293c5f01b2fSopenharmony_ci CAPTURE(i) 294c5f01b2fSopenharmony_ci CAPTURE(j) 295c5f01b2fSopenharmony_ci CHECK(json::compares_unordered(j_values[i], j_values[j]) == expected[i][j]); 296c5f01b2fSopenharmony_ci } 297c5f01b2fSopenharmony_ci } 298c5f01b2fSopenharmony_ci } 299c5f01b2fSopenharmony_ci 300c5f01b2fSopenharmony_ci#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 301c5f01b2fSopenharmony_ci SECTION("compares unordered (inverse)") 302c5f01b2fSopenharmony_ci { 303c5f01b2fSopenharmony_ci std::vector<std::vector<bool>> expected = 304c5f01b2fSopenharmony_ci { 305c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 306c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0 307c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1 308c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2 309c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3 310c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4 311c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5 312c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6 313c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7 314c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 315c5f01b2fSopenharmony_ci {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 316c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10 317c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11 318c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12 319c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 13 320c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 14 321c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 15 322c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 16 323c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 17 324c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 18 325c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19 326c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 327c5f01b2fSopenharmony_ci {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 328c5f01b2fSopenharmony_ci }; 329c5f01b2fSopenharmony_ci 330c5f01b2fSopenharmony_ci // check that two values compare unordered as expected (with legacy-mode enabled) 331c5f01b2fSopenharmony_ci REQUIRE(expected.size() == j_values.size()); 332c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 333c5f01b2fSopenharmony_ci { 334c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == j_values.size()); 335c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 336c5f01b2fSopenharmony_ci { 337c5f01b2fSopenharmony_ci CAPTURE(i) 338c5f01b2fSopenharmony_ci CAPTURE(j) 339c5f01b2fSopenharmony_ci CAPTURE(j_values[i]) 340c5f01b2fSopenharmony_ci CAPTURE(j_values[j]) 341c5f01b2fSopenharmony_ci CHECK(json::compares_unordered(j_values[i], j_values[j], true) == expected[i][j]); 342c5f01b2fSopenharmony_ci } 343c5f01b2fSopenharmony_ci } 344c5f01b2fSopenharmony_ci } 345c5f01b2fSopenharmony_ci#endif 346c5f01b2fSopenharmony_ci 347c5f01b2fSopenharmony_ci SECTION("comparison: equal") 348c5f01b2fSopenharmony_ci { 349c5f01b2fSopenharmony_ci // check that two values compare equal 350c5f01b2fSopenharmony_ci REQUIRE(expected_eq.size() == j_values.size()); 351c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 352c5f01b2fSopenharmony_ci { 353c5f01b2fSopenharmony_ci REQUIRE(expected_eq[i].size() == j_values.size()); 354c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 355c5f01b2fSopenharmony_ci { 356c5f01b2fSopenharmony_ci CAPTURE(i) 357c5f01b2fSopenharmony_ci CAPTURE(j) 358c5f01b2fSopenharmony_ci CHECK((j_values[i] == j_values[j]) == expected_eq[i][j]); 359c5f01b2fSopenharmony_ci } 360c5f01b2fSopenharmony_ci } 361c5f01b2fSopenharmony_ci 362c5f01b2fSopenharmony_ci // compare with null pointer 363c5f01b2fSopenharmony_ci json j_null; 364c5f01b2fSopenharmony_ci CHECK(j_null == nullptr); 365c5f01b2fSopenharmony_ci CHECK(nullptr == j_null); 366c5f01b2fSopenharmony_ci } 367c5f01b2fSopenharmony_ci 368c5f01b2fSopenharmony_ci SECTION("comparison: not equal") 369c5f01b2fSopenharmony_ci { 370c5f01b2fSopenharmony_ci // check that two values compare unequal as expected 371c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 372c5f01b2fSopenharmony_ci { 373c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 374c5f01b2fSopenharmony_ci { 375c5f01b2fSopenharmony_ci CAPTURE(i) 376c5f01b2fSopenharmony_ci CAPTURE(j) 377c5f01b2fSopenharmony_ci 378c5f01b2fSopenharmony_ci if (json::compares_unordered(j_values[i], j_values[j], true)) 379c5f01b2fSopenharmony_ci { 380c5f01b2fSopenharmony_ci // if two values compare unordered, 381c5f01b2fSopenharmony_ci // check that the boolean comparison result is always false 382c5f01b2fSopenharmony_ci CHECK_FALSE(j_values[i] != j_values[j]); 383c5f01b2fSopenharmony_ci } 384c5f01b2fSopenharmony_ci else 385c5f01b2fSopenharmony_ci { 386c5f01b2fSopenharmony_ci // otherwise, check that they compare according to their definition 387c5f01b2fSopenharmony_ci // as the inverse of equal 388c5f01b2fSopenharmony_ci CHECK((j_values[i] != j_values[j]) == !(j_values[i] == j_values[j])); 389c5f01b2fSopenharmony_ci } 390c5f01b2fSopenharmony_ci } 391c5f01b2fSopenharmony_ci } 392c5f01b2fSopenharmony_ci 393c5f01b2fSopenharmony_ci // compare with null pointer 394c5f01b2fSopenharmony_ci json j_null; 395c5f01b2fSopenharmony_ci CHECK((j_null != nullptr) == false); 396c5f01b2fSopenharmony_ci CHECK((nullptr != j_null) == false); 397c5f01b2fSopenharmony_ci CHECK((j_null != nullptr) == !(j_null == nullptr)); 398c5f01b2fSopenharmony_ci CHECK((nullptr != j_null) == !(nullptr == j_null)); 399c5f01b2fSopenharmony_ci } 400c5f01b2fSopenharmony_ci 401c5f01b2fSopenharmony_ci SECTION("comparison: less") 402c5f01b2fSopenharmony_ci { 403c5f01b2fSopenharmony_ci // check that two values compare less than as expected 404c5f01b2fSopenharmony_ci REQUIRE(expected_lt.size() == j_values.size()); 405c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 406c5f01b2fSopenharmony_ci { 407c5f01b2fSopenharmony_ci REQUIRE(expected_lt[i].size() == j_values.size()); 408c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 409c5f01b2fSopenharmony_ci { 410c5f01b2fSopenharmony_ci CAPTURE(i) 411c5f01b2fSopenharmony_ci CAPTURE(j) 412c5f01b2fSopenharmony_ci CHECK((j_values[i] < j_values[j]) == expected_lt[i][j]); 413c5f01b2fSopenharmony_ci } 414c5f01b2fSopenharmony_ci } 415c5f01b2fSopenharmony_ci } 416c5f01b2fSopenharmony_ci 417c5f01b2fSopenharmony_ci SECTION("comparison: less than or equal equal") 418c5f01b2fSopenharmony_ci { 419c5f01b2fSopenharmony_ci // check that two values compare less than or equal as expected 420c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 421c5f01b2fSopenharmony_ci { 422c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 423c5f01b2fSopenharmony_ci { 424c5f01b2fSopenharmony_ci CAPTURE(i) 425c5f01b2fSopenharmony_ci CAPTURE(j) 426c5f01b2fSopenharmony_ci if (json::compares_unordered(j_values[i], j_values[j], true)) 427c5f01b2fSopenharmony_ci { 428c5f01b2fSopenharmony_ci // if two values compare unordered, 429c5f01b2fSopenharmony_ci // check that the boolean comparison result is always false 430c5f01b2fSopenharmony_ci CHECK_FALSE(j_values[i] <= j_values[j]); 431c5f01b2fSopenharmony_ci } 432c5f01b2fSopenharmony_ci else 433c5f01b2fSopenharmony_ci { 434c5f01b2fSopenharmony_ci // otherwise, check that they compare according to their definition 435c5f01b2fSopenharmony_ci // as the inverse of less than with the operand order reversed 436c5f01b2fSopenharmony_ci CHECK((j_values[i] <= j_values[j]) == !(j_values[j] < j_values[i])); 437c5f01b2fSopenharmony_ci } 438c5f01b2fSopenharmony_ci } 439c5f01b2fSopenharmony_ci } 440c5f01b2fSopenharmony_ci } 441c5f01b2fSopenharmony_ci 442c5f01b2fSopenharmony_ci SECTION("comparison: greater than") 443c5f01b2fSopenharmony_ci { 444c5f01b2fSopenharmony_ci // check that two values compare greater than as expected 445c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 446c5f01b2fSopenharmony_ci { 447c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 448c5f01b2fSopenharmony_ci { 449c5f01b2fSopenharmony_ci CAPTURE(i) 450c5f01b2fSopenharmony_ci CAPTURE(j) 451c5f01b2fSopenharmony_ci if (json::compares_unordered(j_values[i], j_values[j])) 452c5f01b2fSopenharmony_ci { 453c5f01b2fSopenharmony_ci // if two values compare unordered, 454c5f01b2fSopenharmony_ci // check that the boolean comparison result is always false 455c5f01b2fSopenharmony_ci CHECK_FALSE(j_values[i] > j_values[j]); 456c5f01b2fSopenharmony_ci } 457c5f01b2fSopenharmony_ci else 458c5f01b2fSopenharmony_ci { 459c5f01b2fSopenharmony_ci // otherwise, check that they compare according to their definition 460c5f01b2fSopenharmony_ci // as the inverse of less than or equal which is defined as 461c5f01b2fSopenharmony_ci // the inverse of less than with the operand order reversed 462c5f01b2fSopenharmony_ci CHECK((j_values[i] > j_values[j]) == !(j_values[i] <= j_values[j])); 463c5f01b2fSopenharmony_ci CHECK((j_values[i] > j_values[j]) == !!(j_values[j] < j_values[i])); 464c5f01b2fSopenharmony_ci } 465c5f01b2fSopenharmony_ci } 466c5f01b2fSopenharmony_ci } 467c5f01b2fSopenharmony_ci } 468c5f01b2fSopenharmony_ci 469c5f01b2fSopenharmony_ci SECTION("comparison: greater than or equal") 470c5f01b2fSopenharmony_ci { 471c5f01b2fSopenharmony_ci // check that two values compare greater than or equal as expected 472c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 473c5f01b2fSopenharmony_ci { 474c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 475c5f01b2fSopenharmony_ci { 476c5f01b2fSopenharmony_ci CAPTURE(i) 477c5f01b2fSopenharmony_ci CAPTURE(j) 478c5f01b2fSopenharmony_ci if (json::compares_unordered(j_values[i], j_values[j], true)) 479c5f01b2fSopenharmony_ci { 480c5f01b2fSopenharmony_ci // if two values compare unordered, 481c5f01b2fSopenharmony_ci // check that the boolean result is always false 482c5f01b2fSopenharmony_ci CHECK_FALSE(j_values[i] >= j_values[j]); 483c5f01b2fSopenharmony_ci } 484c5f01b2fSopenharmony_ci else 485c5f01b2fSopenharmony_ci { 486c5f01b2fSopenharmony_ci // otherwise, check that they compare according to their definition 487c5f01b2fSopenharmony_ci // as the inverse of less than 488c5f01b2fSopenharmony_ci CHECK((j_values[i] >= j_values[j]) == !(j_values[i] < j_values[j])); 489c5f01b2fSopenharmony_ci } 490c5f01b2fSopenharmony_ci } 491c5f01b2fSopenharmony_ci } 492c5f01b2fSopenharmony_ci } 493c5f01b2fSopenharmony_ci 494c5f01b2fSopenharmony_ci#if JSON_HAS_THREE_WAY_COMPARISON 495c5f01b2fSopenharmony_ci // JSON_HAS_CPP_20 (do not remove; see note at top of file) 496c5f01b2fSopenharmony_ci SECTION("comparison: 3-way") 497c5f01b2fSopenharmony_ci { 498c5f01b2fSopenharmony_ci std::vector<std::vector<std::partial_ordering>> expected = 499c5f01b2fSopenharmony_ci { 500c5f01b2fSopenharmony_ci //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 501c5f01b2fSopenharmony_ci {eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 0 502c5f01b2fSopenharmony_ci {eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1 503c5f01b2fSopenharmony_ci {gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 2 504c5f01b2fSopenharmony_ci {gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 3 505c5f01b2fSopenharmony_ci {gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 4 506c5f01b2fSopenharmony_ci {gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 5 507c5f01b2fSopenharmony_ci {gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 6 508c5f01b2fSopenharmony_ci {gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 7 509c5f01b2fSopenharmony_ci {gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 8 510c5f01b2fSopenharmony_ci {gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 9 511c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 10 512c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 11 513c5f01b2fSopenharmony_ci {gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un}, // 12 514c5f01b2fSopenharmony_ci {gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un}, // 13 515c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un}, // 14 516c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un}, // 15 517c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un}, // 16 518c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un}, // 17 519c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un}, // 18 520c5f01b2fSopenharmony_ci {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un}, // 19 521c5f01b2fSopenharmony_ci {un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 20 522c5f01b2fSopenharmony_ci {un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21 523c5f01b2fSopenharmony_ci }; 524c5f01b2fSopenharmony_ci 525c5f01b2fSopenharmony_ci // check expected partial_ordering against expected booleans 526c5f01b2fSopenharmony_ci REQUIRE(expected.size() == expected_eq.size()); 527c5f01b2fSopenharmony_ci REQUIRE(expected.size() == expected_lt.size()); 528c5f01b2fSopenharmony_ci for (size_t i = 0; i < expected.size(); ++i) 529c5f01b2fSopenharmony_ci { 530c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == expected_eq[i].size()); 531c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == expected_lt[i].size()); 532c5f01b2fSopenharmony_ci for (size_t j = 0; j < expected[i].size(); ++j) 533c5f01b2fSopenharmony_ci { 534c5f01b2fSopenharmony_ci CAPTURE(i) 535c5f01b2fSopenharmony_ci CAPTURE(j) 536c5f01b2fSopenharmony_ci CHECK(std::is_eq(expected[i][j]) == expected_eq[i][j]); 537c5f01b2fSopenharmony_ci CHECK(std::is_lt(expected[i][j]) == expected_lt[i][j]); 538c5f01b2fSopenharmony_ci if (std::is_gt(expected[i][j])) 539c5f01b2fSopenharmony_ci { 540c5f01b2fSopenharmony_ci CHECK((!expected_eq[i][j] && !expected_lt[i][j])); 541c5f01b2fSopenharmony_ci } 542c5f01b2fSopenharmony_ci } 543c5f01b2fSopenharmony_ci } 544c5f01b2fSopenharmony_ci 545c5f01b2fSopenharmony_ci // check that two values compare according to their expected ordering 546c5f01b2fSopenharmony_ci REQUIRE(expected.size() == j_values.size()); 547c5f01b2fSopenharmony_ci for (size_t i = 0; i < j_values.size(); ++i) 548c5f01b2fSopenharmony_ci { 549c5f01b2fSopenharmony_ci REQUIRE(expected[i].size() == j_values.size()); 550c5f01b2fSopenharmony_ci for (size_t j = 0; j < j_values.size(); ++j) 551c5f01b2fSopenharmony_ci { 552c5f01b2fSopenharmony_ci CAPTURE(i) 553c5f01b2fSopenharmony_ci CAPTURE(j) 554c5f01b2fSopenharmony_ci CHECK((j_values[i] <=> j_values[j]) == expected[i][j]); // *NOPAD* 555c5f01b2fSopenharmony_ci } 556c5f01b2fSopenharmony_ci } 557c5f01b2fSopenharmony_ci } 558c5f01b2fSopenharmony_ci#endif 559c5f01b2fSopenharmony_ci } 560c5f01b2fSopenharmony_ci 561c5f01b2fSopenharmony_ci#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 562c5f01b2fSopenharmony_ci SECTION("parser callback regression") 563c5f01b2fSopenharmony_ci { 564c5f01b2fSopenharmony_ci SECTION("filter specific element") 565c5f01b2fSopenharmony_ci { 566c5f01b2fSopenharmony_ci const auto* s_object = R"( 567c5f01b2fSopenharmony_ci { 568c5f01b2fSopenharmony_ci "foo": 2, 569c5f01b2fSopenharmony_ci "bar": { 570c5f01b2fSopenharmony_ci "baz": 1 571c5f01b2fSopenharmony_ci } 572c5f01b2fSopenharmony_ci } 573c5f01b2fSopenharmony_ci )"; 574c5f01b2fSopenharmony_ci const auto* s_array = R"( 575c5f01b2fSopenharmony_ci [1,2,[3,4,5],4,5] 576c5f01b2fSopenharmony_ci )"; 577c5f01b2fSopenharmony_ci 578c5f01b2fSopenharmony_ci json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept 579c5f01b2fSopenharmony_ci { 580c5f01b2fSopenharmony_ci // filter all number(2) elements 581c5f01b2fSopenharmony_ci return j != json(2); 582c5f01b2fSopenharmony_ci }); 583c5f01b2fSopenharmony_ci 584c5f01b2fSopenharmony_ci CHECK (j_object == json({{"bar", {{"baz", 1}}}})); 585c5f01b2fSopenharmony_ci 586c5f01b2fSopenharmony_ci json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept 587c5f01b2fSopenharmony_ci { 588c5f01b2fSopenharmony_ci return j != json(2); 589c5f01b2fSopenharmony_ci }); 590c5f01b2fSopenharmony_ci 591c5f01b2fSopenharmony_ci CHECK (j_array == json({1, {3, 4, 5}, 4, 5})); 592c5f01b2fSopenharmony_ci } 593c5f01b2fSopenharmony_ci } 594c5f01b2fSopenharmony_ci#endif 595c5f01b2fSopenharmony_ci} 596