♻️ rename internal_binary_t with binary_t

This commit is contained in:
Niels Lohmann 2020-05-17 22:50:27 +02:00
parent dead99eb0e
commit 904642f261
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
59 changed files with 536 additions and 457 deletions

View file

@ -77,7 +77,7 @@ class SaxEventLogger
return true;
}
bool binary(json::internal_binary_t& val)
bool binary(json::binary_t& val)
{
std::string binary_contents = "binary(";
std::string comma_space = "";
@ -183,7 +183,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return events_left-- > 0;
}
bool binary(json::internal_binary_t&) override
bool binary(json::binary_t&) override
{
return events_left-- > 0;
}

View file

@ -485,14 +485,14 @@ TEST_CASE("constructors")
{
SECTION("empty binary")
{
json::internal_binary_t b{};
json::binary_t b{};
json j(b);
CHECK(j.type() == json::value_t::binary);
}
SECTION("filled binary")
{
json::internal_binary_t b({1, 2, 3});
json::binary_t b({1, 2, 3});
json j(b);
CHECK(j.type() == json::value_t::binary);
}

View file

@ -76,7 +76,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
return true;
}
bool binary(json::internal_binary_t& val) override
bool binary(json::binary_t& val) override
{
std::string binary_contents = "binary(";
std::string comma_space = "";

View file

@ -968,21 +968,35 @@ TEST_CASE("modifiers")
SECTION("binary_t type")
{
json j = json::binary_array({1, 2, 3, 4});
json::binary_t s = {1, 2, 3, 4};
json::binary_t s = {{5, 6, 7, 8}};
j.swap(s);
CHECK(j == json::binary_array({1, 2, 3, 4}));
CHECK(j == json::binary_array({5, 6, 7, 8}));
j.swap(s);
CHECK(j == json::binary_array({1, 2, 3, 4}));
}
SECTION("non-string_t type")
SECTION("binary_t::container_type type")
{
json j = json::binary_array({1, 2, 3, 4});
std::vector<std::uint8_t> s = {{5, 6, 7, 8}};
j.swap(s);
CHECK(j == json::binary_array({5, 6, 7, 8}));
j.swap(s);
CHECK(j == json::binary_array({1, 2, 3, 4}));
}
SECTION("non-binary_t type")
{
json j = 17;
json::binary_t s = {1, 2, 3, 4};
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");

View file

@ -1134,7 +1134,7 @@ TEST_CASE("MessagePack")
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
std::uint8_t subtype = 42;
j.set_subtype(subtype);
j.get_binary().set_subtype(subtype);
// create expected byte vector
std::vector<uint8_t> expected;
@ -1209,7 +1209,7 @@ TEST_CASE("MessagePack")
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
std::uint8_t subtype = 42;
j.set_subtype(subtype);
j.get_binary().set_subtype(subtype);
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');
@ -1245,7 +1245,7 @@ TEST_CASE("MessagePack")
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
std::uint8_t subtype = 42;
j.set_subtype(subtype);
j.get_binary().set_subtype(subtype);
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');

View file

@ -60,7 +60,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const object_t")
@ -89,7 +89,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to array_t")
@ -118,7 +118,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const array_t")
@ -147,7 +147,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to string_t")
@ -176,7 +176,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const string_t")
@ -205,7 +205,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to boolean_t")
@ -234,7 +234,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const boolean_t")
@ -263,7 +263,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to number_integer_t")
@ -292,7 +292,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const number_integer_t")
@ -321,7 +321,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to number_unsigned_t")
@ -350,7 +350,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() != nullptr);
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const number_unsigned_t")
@ -379,7 +379,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() != nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to number_float_t")
@ -408,7 +408,7 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<json::number_float_t*>() != nullptr);
CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
}
SECTION("pointer access to const number_float_t")
@ -437,12 +437,12 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() != nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
}
SECTION("pointer access to const internal_binary_t")
SECTION("pointer access to const binary_t")
{
using test_type = const json::internal_binary_t;
using test_type = const json::binary_t;
const json value = json::binary_array({1, 2, 3});
// check if pointers are returned correctly
@ -466,12 +466,12 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() != nullptr);
CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
}
SECTION("pointer access to const internal_binary_t")
SECTION("pointer access to const binary_t")
{
using test_type = const json::internal_binary_t;
using test_type = const json::binary_t;
const json value = json::binary_array({});
// check if pointers are returned correctly
@ -495,6 +495,6 @@ TEST_CASE("pointer access")
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
CHECK(value.get_ptr<const json::internal_binary_t*>() != nullptr);
CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
}
}