add tests for binary type

parent 48aa4416
This diff is collapsed.
...@@ -58,6 +58,7 @@ TEST_CASE("convenience functions") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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") ...@@ -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");
}
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment