✅ add tests for binary type
This commit is contained in:
parent
48aa441661
commit
2a34f4cd63
4 changed files with 135 additions and 42 deletions
|
@ -56,21 +56,23 @@ TEST_CASE("lexicographical comparison operators")
|
||||||
json::value_t::number_float,
|
json::value_t::number_float,
|
||||||
json::value_t::object,
|
json::value_t::object,
|
||||||
json::value_t::array,
|
json::value_t::array,
|
||||||
json::value_t::string
|
json::value_t::string,
|
||||||
|
json::value_t::binary
|
||||||
};
|
};
|
||||||
|
|
||||||
SECTION("comparison: less")
|
SECTION("comparison: less")
|
||||||
{
|
{
|
||||||
std::vector<std::vector<bool>> expected =
|
std::vector<std::vector<bool>> expected =
|
||||||
{
|
{
|
||||||
{false, true, true, true, true, true, true, true},
|
{false, true, true, true, true, true, true, true, true},
|
||||||
{false, false, true, true, true, true, true, true},
|
{false, false, true, true, true, true, true, true, true},
|
||||||
{false, false, false, false, false, true, true, true},
|
{false, false, false, false, false, true, true, true, true},
|
||||||
{false, false, false, false, false, true, true, true},
|
{false, false, false, false, false, true, true, true, true},
|
||||||
{false, false, false, false, false, true, true, true},
|
{false, false, false, false, false, true, true, true, true},
|
||||||
{false, false, false, false, false, false, true, true},
|
{false, false, false, false, false, false, true, true, true},
|
||||||
{false, false, false, false, false, false, false, true},
|
{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}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < j_types.size(); ++i)
|
for (size_t i = 0; i < j_types.size(); ++i)
|
||||||
|
@ -98,29 +100,32 @@ TEST_CASE("lexicographical comparison operators")
|
||||||
"foo", "bar",
|
"foo", "bar",
|
||||||
true, false,
|
true, false,
|
||||||
{1, 2, 3}, {"one", "two", "three"},
|
{1, 2, 3}, {"one", "two", "three"},
|
||||||
{{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}}
|
{{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}},
|
||||||
|
json::binary_array({1, 2, 3}), json::binary_array({1, 2, 4})
|
||||||
};
|
};
|
||||||
|
|
||||||
SECTION("comparison: equal")
|
SECTION("comparison: equal")
|
||||||
{
|
{
|
||||||
std::vector<std::vector<bool>> expected =
|
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, 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},
|
||||||
{false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true, 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, false, false, true}
|
{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, false, false, true, false},
|
||||||
|
{false, 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 i = 0; i < j_values.size(); ++i)
|
||||||
|
@ -176,22 +181,24 @@ TEST_CASE("lexicographical comparison operators")
|
||||||
{
|
{
|
||||||
std::vector<std::vector<bool>> expected =
|
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, true, true},
|
||||||
{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, true, true},
|
||||||
{false, false, false, true, true, true, true, true, true, true, false, false, true, true, true, true},
|
{false, false, false, true, true, true, true, true, true, true, false, false, true, true, true, true, true, true},
|
||||||
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true},
|
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true, true, true},
|
||||||
{false, false, false, true, false, true, false, true, true, true, false, false, true, true, true, true},
|
{false, false, false, true, false, true, false, true, true, true, false, false, true, true, true, true, true, true},
|
||||||
{false, false, false, true, false, false, 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, true, true},
|
||||||
{false, false, false, true, true, true, 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, true, true},
|
||||||
{false, false, false, true, false, false, false, false, true, true, false, false, true, true, true, true},
|
{false, false, false, true, false, false, false, false, true, true, false, false, true, true, 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, false, false, false, false, false, false, false, false, true, true},
|
||||||
{false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false},
|
{false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, true},
|
||||||
{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, false, false, true, true, true, true, true, true},
|
||||||
{false, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true},
|
{false, false, true, true, true, true, true, true, true, true, true, false, true, true, 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, true, false, false, true, true},
|
||||||
{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, false, false, false, false, true, true},
|
||||||
{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, false, false, true, true},
|
||||||
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, false}
|
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, false, 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, false, false, false, false, false, false, false, false, false, false, true, false}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < j_values.size(); ++i)
|
for (size_t i = 0; i < j_values.size(); ++i)
|
||||||
|
|
|
@ -58,6 +58,7 @@ TEST_CASE("convenience functions")
|
||||||
CHECK(std::string(json(json::value_t::number_integer).type_name()) == "number");
|
CHECK(std::string(json(json::value_t::number_integer).type_name()) == "number");
|
||||||
CHECK(std::string(json(json::value_t::number_unsigned).type_name()) == "number");
|
CHECK(std::string(json(json::value_t::number_unsigned).type_name()) == "number");
|
||||||
CHECK(std::string(json(json::value_t::number_float).type_name()) == "number");
|
CHECK(std::string(json(json::value_t::number_float).type_name()) == "number");
|
||||||
|
CHECK(std::string(json(json::value_t::binary).type_name()) == "binary");
|
||||||
CHECK(std::string(json(json::value_t::boolean).type_name()) == "boolean");
|
CHECK(std::string(json(json::value_t::boolean).type_name()) == "boolean");
|
||||||
CHECK(std::string(json(json::value_t::string).type_name()) == "string");
|
CHECK(std::string(json(json::value_t::string).type_name()) == "string");
|
||||||
CHECK(std::string(json(json::value_t::discarded).type_name()) == "discarded");
|
CHECK(std::string(json(json::value_t::discarded).type_name()) == "discarded");
|
||||||
|
|
|
@ -49,6 +49,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(j.is_object());
|
CHECK(j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -66,6 +67,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(j.is_array());
|
CHECK(j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -83,6 +85,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -100,6 +103,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -117,6 +121,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(j.is_string());
|
CHECK(j.is_string());
|
||||||
|
@ -134,6 +139,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -151,6 +157,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -168,6 +175,25 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(j.is_number_float());
|
CHECK(j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
|
CHECK(not j.is_object());
|
||||||
|
CHECK(not j.is_array());
|
||||||
|
CHECK(not j.is_string());
|
||||||
|
CHECK(not j.is_discarded());
|
||||||
|
CHECK(j.is_primitive());
|
||||||
|
CHECK(not j.is_structured());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("binary")
|
||||||
|
{
|
||||||
|
json j(json::value_t::binary);
|
||||||
|
CHECK(not j.is_null());
|
||||||
|
CHECK(not j.is_boolean());
|
||||||
|
CHECK(not j.is_number());
|
||||||
|
CHECK(not j.is_number_integer());
|
||||||
|
CHECK(not j.is_number_unsigned());
|
||||||
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -185,6 +211,7 @@ TEST_CASE("object inspection")
|
||||||
CHECK(not j.is_number_integer());
|
CHECK(not j.is_number_integer());
|
||||||
CHECK(not j.is_number_unsigned());
|
CHECK(not j.is_number_unsigned());
|
||||||
CHECK(not j.is_number_float());
|
CHECK(not j.is_number_float());
|
||||||
|
CHECK(not j.is_binary());
|
||||||
CHECK(not j.is_object());
|
CHECK(not j.is_object());
|
||||||
CHECK(not j.is_array());
|
CHECK(not j.is_array());
|
||||||
CHECK(not j.is_string());
|
CHECK(not j.is_string());
|
||||||
|
@ -439,5 +466,12 @@ TEST_CASE("object inspection")
|
||||||
json::value_t t = j;
|
json::value_t t = j;
|
||||||
CHECK(t == j.type());
|
CHECK(t == j.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("binary")
|
||||||
|
{
|
||||||
|
json j = json::binary_array({});
|
||||||
|
json::value_t t = j;
|
||||||
|
CHECK(t == j.type());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,31 @@ TEST_CASE("modifiers")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("binary")
|
||||||
|
{
|
||||||
|
SECTION("empty binary")
|
||||||
|
{
|
||||||
|
json j = json::binary_array({});
|
||||||
|
json k = j;
|
||||||
|
|
||||||
|
j.clear();
|
||||||
|
CHECK(not j.empty());
|
||||||
|
CHECK(j == json(json::value_t::binary));
|
||||||
|
CHECK(j == json(k.type()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("filled binary")
|
||||||
|
{
|
||||||
|
json j = json::binary_array({1, 2, 3, 4, 5});
|
||||||
|
json k = j;
|
||||||
|
|
||||||
|
j.clear();
|
||||||
|
CHECK(not j.empty());
|
||||||
|
CHECK(j == json(json::value_t::binary));
|
||||||
|
CHECK(j == json(k.type()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("number (integer)")
|
SECTION("number (integer)")
|
||||||
{
|
{
|
||||||
json j = 23;
|
json j = 23;
|
||||||
|
@ -937,5 +962,31 @@ TEST_CASE("modifiers")
|
||||||
CHECK_THROWS_WITH(j.swap(s), "[json.exception.type_error.310] cannot use swap() with number");
|
CHECK_THROWS_WITH(j.swap(s), "[json.exception.type_error.310] cannot use swap() with number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("binary_t")
|
||||||
|
{
|
||||||
|
SECTION("binary_t type")
|
||||||
|
{
|
||||||
|
json j = json::binary_array({1, 2, 3, 4});
|
||||||
|
json::binary_t s = {1, 2, 3, 4};
|
||||||
|
|
||||||
|
j.swap(s);
|
||||||
|
|
||||||
|
CHECK(j == json::binary_array({1, 2, 3, 4}));
|
||||||
|
|
||||||
|
j.swap(s);
|
||||||
|
|
||||||
|
CHECK(j == json::binary_array({1, 2, 3, 4}));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("non-string_t type")
|
||||||
|
{
|
||||||
|
json j = 17;
|
||||||
|
json::binary_t s = {1, 2, 3, 4};
|
||||||
|
|
||||||
|
CHECK_THROWS_AS(j.swap(s), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(j.swap(s), "[json.exception.type_error.310] cannot use swap() with number");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue