Move the custom BinaryType tests into their own translation unit

The two sections added to unit-regression2.cpp brought a third full
basic_json instantiation into a translation unit that was already large.
With Clang on MinGW that pushed the object over the reach of a 32-bit
relocation and test-regression2_cpp20.exe failed to link:

    relocation truncated to fit: IMAGE_REL_AMD64_REL32 against `.rdata'

unit-regression2.cpp is restored to exactly what it was before, and the
coverage moves to unit-custom-binary-type.cpp, next to the object and array
type tests it belongs with. The signed value type is now also covered in
C++11, where std::byte is not available.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-08-28 19:02:04 +00:00
parent 3b28316ee4
commit 8ce64b9c16
2 changed files with 79 additions and 33 deletions
-33
View File
@@ -1154,39 +1154,6 @@ TEST_CASE("regression tests 2")
CHECK(!default_json.is_binary());
}
SECTION("dumping a binary value with a custom BinaryType")
{
// the elements of a binary value are dumped as the numbers 0..255,
// whatever the value type of the configured BinaryType is
const std::vector<std::byte> bytes{std::byte{0}, std::byte{1}, std::byte{0xFF}};
CHECK(json_4804::binary(bytes).dump() == R"({"bytes":[0,1,255],"subtype":null})");
CHECK(json_4804::binary(bytes, 42).dump() == R"({"bytes":[0,1,255],"subtype":42})");
CHECK(json_4804::binary({}).dump() == R"({"bytes":[],"subtype":null})");
// a signed byte type must not dump negative numbers
using json_char_binary = nlohmann::basic_json <
std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t,
double, std::allocator, nlohmann::adl_serializer, std::vector<char>, void >;
const std::vector<char> chars{'\0', '\x01', '\xFF'};
CHECK(json_char_binary::binary(chars).dump() == R"({"bytes":[0,1,255],"subtype":null})");
// the default binary type is unchanged
CHECK(json::binary({0, 1, 255}, 42).dump() == R"({"bytes":[0,1,255],"subtype":42})");
}
SECTION("hashing and UBJSON with a custom BinaryType")
{
const std::vector<std::byte> bytes{std::byte{0}, std::byte{1}, std::byte{0xFF}};
const auto j = json_4804::binary(bytes);
CHECK(std::hash<json_4804> {}(j) == std::hash<json_4804> {}(j));
CHECK(json_4804::from_cbor(json_4804::to_cbor(j)) == j);
CHECK(json_4804::from_msgpack(json_4804::to_msgpack(j)) == j);
// UBJSON has no binary type, so binary values are written as arrays
CHECK(json_4804::from_ubjson(json_4804::to_ubjson(j)) == json_4804({0, 1, 255}));
}
SECTION("discussion #4209 - custom BinaryType extraction from parsed array")
{
// Test that extracting a custom BinaryType from a parsed JSON array still works