2016-08-04 19:55:47 +00:00
|
|
|
/*
|
|
|
|
__ _____ _____ _____
|
|
|
|
__| | __| | | | JSON for Modern C++ (test suite)
|
2019-07-28 18:20:41 +00:00
|
|
|
| | |__ | | | | | | version 3.7.0
|
2016-08-04 19:55:47 +00:00
|
|
|
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
|
|
|
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
2018-05-03 15:41:45 +00:00
|
|
|
SPDX-License-Identifier: MIT
|
2019-03-19 23:19:07 +00:00
|
|
|
Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
|
2016-08-04 19:55:47 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-01-13 16:41:21 +00:00
|
|
|
#include "doctest_compatibility.h"
|
2016-08-04 19:55:47 +00:00
|
|
|
|
2018-01-29 10:21:11 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
2016-08-04 19:55:47 +00:00
|
|
|
using nlohmann::json;
|
|
|
|
|
2019-04-04 06:56:36 +00:00
|
|
|
namespace
|
|
|
|
{
|
2017-06-20 19:09:26 +00:00
|
|
|
// helper function to check std::less<json::value_t>
|
2018-06-24 20:29:33 +00:00
|
|
|
// see https://en.cppreference.com/w/cpp/utility/functional/less
|
2017-06-20 19:09:26 +00:00
|
|
|
template <typename A, typename B, typename U = std::less<json::value_t>>
|
|
|
|
bool f(A a, B b, U u = U())
|
|
|
|
{
|
|
|
|
return u(a, b);
|
|
|
|
}
|
2019-04-04 06:56:36 +00:00
|
|
|
}
|
2017-06-20 19:09:26 +00:00
|
|
|
|
2016-08-04 19:55:47 +00:00
|
|
|
TEST_CASE("lexicographical comparison operators")
|
|
|
|
{
|
|
|
|
SECTION("types")
|
|
|
|
{
|
|
|
|
std::vector<json::value_t> j_types =
|
|
|
|
{
|
|
|
|
json::value_t::null,
|
|
|
|
json::value_t::boolean,
|
|
|
|
json::value_t::number_integer,
|
|
|
|
json::value_t::number_unsigned,
|
|
|
|
json::value_t::number_float,
|
|
|
|
json::value_t::object,
|
|
|
|
json::value_t::array,
|
|
|
|
json::value_t::string
|
|
|
|
};
|
|
|
|
|
|
|
|
SECTION("comparison: less")
|
|
|
|
{
|
|
|
|
std::vector<std::vector<bool>> expected =
|
|
|
|
{
|
|
|
|
{false, true, true, true, true, true, true, true},
|
|
|
|
{false, false, true, true, true, true, true, true},
|
|
|
|
{false, false, false, false, false, true, true, true},
|
|
|
|
{false, false, false, false, false, true, true, true},
|
|
|
|
{false, false, false, false, false, true, true, true},
|
|
|
|
{false, false, false, false, false, false, true, true},
|
|
|
|
{false, false, false, false, false, false, false, true},
|
|
|
|
{false, false, false, false, false, false, false, false}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < j_types.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_types.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
2016-08-04 19:55:47 +00:00
|
|
|
// check precomputed values
|
|
|
|
CHECK(operator<(j_types[i], j_types[j]) == expected[i][j]);
|
2017-06-20 19:09:26 +00:00
|
|
|
CHECK(f(j_types[i], j_types[j]) == expected[i][j]);
|
2016-08-04 19:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("values")
|
|
|
|
{
|
|
|
|
json j_values =
|
|
|
|
{
|
|
|
|
nullptr, nullptr,
|
2017-10-22 06:53:27 +00:00
|
|
|
-17, 42,
|
2016-08-04 19:55:47 +00:00
|
|
|
8u, 13u,
|
|
|
|
3.14159, 23.42,
|
|
|
|
"foo", "bar",
|
|
|
|
true, false,
|
|
|
|
{1, 2, 3}, {"one", "two", "three"},
|
|
|
|
{{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}}
|
|
|
|
};
|
|
|
|
|
|
|
|
SECTION("comparison: equal")
|
|
|
|
{
|
|
|
|
std::vector<std::vector<bool>> expected =
|
|
|
|
{
|
|
|
|
{true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_values.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
|
|
|
CAPTURE(j_values[i])
|
|
|
|
CAPTURE(j_values[j])
|
2016-08-04 19:55:47 +00:00
|
|
|
// check precomputed values
|
|
|
|
CHECK( (j_values[i] == j_values[j]) == expected[i][j] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// comparison with discarded elements
|
|
|
|
json j_discarded(json::value_t::discarded);
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
CHECK( (j_values[i] == j_discarded) == false);
|
|
|
|
CHECK( (j_discarded == j_values[i]) == false);
|
|
|
|
CHECK( (j_discarded == j_discarded) == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare with null pointer
|
|
|
|
json j_null;
|
|
|
|
CHECK(j_null == nullptr);
|
|
|
|
CHECK(nullptr == j_null);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("comparison: not equal")
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_values.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
2016-08-04 19:55:47 +00:00
|
|
|
// check definition
|
|
|
|
CHECK( (j_values[i] != j_values[j]) == not(j_values[i] == j_values[j]) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare with null pointer
|
|
|
|
json j_null;
|
|
|
|
CHECK( (j_null != nullptr) == false);
|
|
|
|
CHECK( (nullptr != j_null) == false);
|
|
|
|
CHECK( (j_null != nullptr) == not(j_null == nullptr));
|
|
|
|
CHECK( (nullptr != j_null) == not(nullptr == j_null));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("comparison: less")
|
|
|
|
{
|
|
|
|
std::vector<std::vector<bool>> expected =
|
|
|
|
{
|
|
|
|
{false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true},
|
|
|
|
{false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true},
|
2017-10-22 06:53:27 +00:00
|
|
|
{false, false, false, true, true, true, true, true, true, true, false, false, true, true, true, true},
|
2016-08-04 19:55:47 +00:00
|
|
|
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true},
|
2017-10-22 06:53:27 +00:00
|
|
|
{false, false, false, true, false, true, false, true, true, true, false, false, true, true, true, true},
|
|
|
|
{false, false, false, true, false, false, false, true, true, true, false, false, true, true, true, true},
|
|
|
|
{false, false, false, true, true, true, false, true, true, true, false, false, true, true, true, true},
|
2016-08-04 19:55:47 +00:00
|
|
|
{false, false, false, true, false, false, false, false, true, true, false, false, true, true, true, true},
|
|
|
|
{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false},
|
|
|
|
{false, false, true, true, true, true, true, true, true, true, false, false, true, true, true, true},
|
|
|
|
{false, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true},
|
|
|
|
{false, false, false, false, false, false, false, false, true, true, false, false, false, true, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, false, false},
|
|
|
|
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, false}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_values.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
|
|
|
CAPTURE(j_values[i])
|
|
|
|
CAPTURE(j_values[j])
|
2016-08-04 19:55:47 +00:00
|
|
|
// check precomputed values
|
|
|
|
CHECK( (j_values[i] < j_values[j]) == expected[i][j] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// comparison with discarded elements
|
|
|
|
json j_discarded(json::value_t::discarded);
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
2016-08-04 19:55:47 +00:00
|
|
|
CHECK( (j_values[i] < j_discarded) == false);
|
|
|
|
CHECK( (j_discarded < j_values[i]) == false);
|
|
|
|
CHECK( (j_discarded < j_discarded) == false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("comparison: less than or equal equal")
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_values.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
2016-08-04 19:55:47 +00:00
|
|
|
// check definition
|
|
|
|
CHECK( (j_values[i] <= j_values[j]) == not(j_values[j] < j_values[i]) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("comparison: greater than")
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_values.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
2016-08-04 19:55:47 +00:00
|
|
|
// check definition
|
|
|
|
CHECK( (j_values[i] > j_values[j]) == (j_values[j] < j_values[i]) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("comparison: greater than or equal")
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < j_values.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < j_values.size(); ++j)
|
|
|
|
{
|
2018-12-23 12:56:18 +00:00
|
|
|
CAPTURE(i)
|
|
|
|
CAPTURE(j)
|
2016-08-04 19:55:47 +00:00
|
|
|
// check definition
|
|
|
|
CHECK( (j_values[i] >= j_values[j]) == not(j_values[i] < j_values[j]) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|