add a switch to enable implicit conversions (defaults to true)

wrap implicit conversions tests around the JSON_USE_IMPLICIT_CONVERSIONS
macro
This commit is contained in:
Théo DELRIEU
2020-07-16 11:11:35 +02:00
parent 2cd10a7405
commit 74b446f5fd
15 changed files with 151 additions and 64 deletions

View File

@@ -240,12 +240,12 @@ TEST_CASE("regression tests")
{
json j1 = NAN;
CHECK(j1.is_number_float());
json::number_float_t f1 = j1;
json::number_float_t f1{j1};
CHECK(std::isnan(f1));
json j2 = json::number_float_t(NAN);
CHECK(j2.is_number_float());
json::number_float_t f2 = j2;
json::number_float_t f2{j2};
CHECK(std::isnan(f2));
}
@@ -253,12 +253,12 @@ TEST_CASE("regression tests")
{
json j1 = INFINITY;
CHECK(j1.is_number_float());
json::number_float_t f1 = j1;
json::number_float_t f1{j1};
CHECK(!std::isfinite(f1));
json j2 = json::number_float_t(INFINITY);
CHECK(j2.is_number_float());
json::number_float_t f2 = j2;
json::number_float_t f2{j2};
CHECK(!std::isfinite(f2));
}
}
@@ -332,11 +332,11 @@ TEST_CASE("regression tests")
json j;
ss >> j;
std::string test = j["Test"];
auto test = j["Test"].get<std::string>();
CHECK(test == "Test1");
int number = j["Number"];
int number{j["Number"]};
CHECK(number == 100);
float foo = j["Foo"];
float foo{j["Foo"]};
CHECK(static_cast<double>(foo) == Approx(42.42));
}
@@ -453,6 +453,7 @@ TEST_CASE("regression tests")
CHECK(j["string"] == "\u0007\u0007");
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #144 - implicit assignment to std::string fails")
{
json o = {{"name", "value"}};
@@ -470,6 +471,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS(s2 = o["int"], json::type_error);
CHECK_THROWS_WITH(s2 = o["int"], "[json.exception.type_error.302] type must be string, but is number");
}
#endif
SECTION("issue #146 - character following a surrogate pair is skipped")
{
@@ -689,7 +691,7 @@ TEST_CASE("regression tests")
{"object", {{"key1", 1}, {"key2", 2}}},
};
int at_integer = j.at("/object/key2"_json_pointer);
int at_integer{j.at("/object/key2"_json_pointer)};
int val_integer = j.value("/object/key2"_json_pointer, 0);
CHECK(at_integer == val_integer);
@@ -1233,6 +1235,7 @@ TEST_CASE("regression tests")
CHECK(j["double_value"].is_number_float());
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #464 - VS2017 implicit to std::string conversion fix")
{
json v = "test";
@@ -1240,6 +1243,7 @@ TEST_CASE("regression tests")
test = v;
CHECK(v == "test");
}
#endif
SECTION("issue #465 - roundtrip error while parsing 1000000000000000010E5")
{
@@ -1250,6 +1254,7 @@ TEST_CASE("regression tests")
CHECK(s1 == s2);
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #473 - inconsistent behavior in conversion to array type")
{
json j_array = {1, 2, 3, 4};
@@ -1298,6 +1303,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
}
}
#endif
SECTION("issue #486 - json::value_t can't be a map's key type in VC++ 2015")
{
@@ -1377,6 +1383,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #600 - how does one convert a map in Json back to std::map?")
{
SECTION("example 1")
@@ -1409,6 +1416,7 @@ TEST_CASE("regression tests")
CHECK(m1 == m2);
}
}
#endif
SECTION("issue #602 - BOM not skipped when using json:parse(iterator)")
{
@@ -1417,6 +1425,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(_ = json::parse(i.begin(), i.end()));
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #702 - conversion from valarray<double> to json fails to build")
{
SECTION("original example")
@@ -1445,6 +1454,7 @@ TEST_CASE("regression tests")
"[json.exception.type_error.302] type must be array, but is null");
}
}
#endif
SECTION("issue #367 - Behavior of operator>> should more closely resemble that of built-in overloads.")
{
@@ -1456,9 +1466,9 @@ TEST_CASE("regression tests")
i1_2_3 >> j2;
i1_2_3 >> j3;
std::map<std::string, std::string> m1 = j1;
std::map<std::string, std::string> m2 = j2;
int i3 = j3;
auto m1 = j1.get<std::map<std::string, std::string>>();
auto m2 = j2.get<std::map<std::string, std::string>>();
int i3{j3};
CHECK( m1 == ( std::map<std::string, std::string> {{ "first", "one" }} ));
CHECK( m2 == ( std::map<std::string, std::string> {{ "second", "two" }} ));
@@ -1513,6 +1523,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_WITH(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E");
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #843 - converting to array not working")
{
json j;
@@ -1520,6 +1531,7 @@ TEST_CASE("regression tests")
j = ar;
ar = j;
}
#endif
SECTION("issue #894 - invalid RFC6902 copy operation succeeds")
{
@@ -1632,7 +1644,7 @@ TEST_CASE("regression tests")
SECTION("issue #977 - Assigning between different json types")
{
foo_json lj = ns::foo{3};
ns::foo ff = lj;
ns::foo ff(lj);
CHECK(lj.is_object());
CHECK(lj.size() == 1);
CHECK(lj["x"] == 3);
@@ -1880,7 +1892,7 @@ TEST_CASE("regression tests")
{
{
json j;
NonDefaultFromJsonStruct x = j;
NonDefaultFromJsonStruct x(j);
NonDefaultFromJsonStruct y;
CHECK(x == y);
}