diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index 15744b9e..63126654 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -1039,3 +1039,60 @@ TEST_CASE("deserialization") })); } } + +TEST_CASE_TEMPLATE("deserialization of different character types", T, + char, unsigned char, signed char, + wchar_t, + char16_t, char32_t, + std::uint8_t, std::int8_t, + std::int16_t, std::uint16_t, + std::int32_t, std::uint32_t) +{ + std::vector v = {'t', 'r', 'u', 'e'}; + CHECK(json::parse(v) == json(true)); + CHECK(json::accept(v)); + + SaxEventLogger l; + CHECK(json::sax_parse(v, &l)); + CHECK(l.events.size() == 1); + CHECK(l.events == std::vector({"boolean(true)"})); +} + +TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, + char, unsigned char, std::uint8_t) +{ + // a star emoji + std::vector v = {'"', static_cast(0xe2), static_cast(0xad), static_cast(0x90), static_cast(0xef), static_cast(0xb8), static_cast(0x8f), '"'}; + CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\""); + CHECK(json::accept(v)); + + SaxEventLogger l; + CHECK(json::sax_parse(v, &l)); + CHECK(l.events.size() == 1); +} + +TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, + char16_t, std::uint16_t) +{ + // a star emoji + std::vector v = {static_cast('"'), static_cast(0x2b50), static_cast(0xfe0f), static_cast('"')}; + CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\""); + CHECK(json::accept(v)); + + SaxEventLogger l; + CHECK(json::sax_parse(v, &l)); + CHECK(l.events.size() == 1); +} + +TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, + char32_t, std::uint32_t) +{ + // a star emoji + std::vector v = {static_cast('"'), static_cast(0x2b50), static_cast(0xfe0f), static_cast('"')}; + CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\""); + CHECK(json::accept(v)); + + SaxEventLogger l; + CHECK(json::sax_parse(v, &l)); + CHECK(l.events.size() == 1); +}