mirror of
https://github.com/nlohmann/json.git
synced 2025-07-21 04:22:05 +03:00
Added class hierarchy for user-defined exceptions (#244). Integrated parse exceptions 101-103. Parse exceptions include the byte count of the last read character to locate the position of the error (#301).
This commit is contained in:
@ -38,6 +38,9 @@ TEST_CASE("Unicode", "[hide]")
|
||||
{
|
||||
SECTION("full enumeration of Unicode code points")
|
||||
{
|
||||
// lexer to call to_unicode on
|
||||
json::lexer dummy_lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(""), 0);
|
||||
|
||||
// create an escaped string from a code point
|
||||
const auto codepoint_to_unicode = [](std::size_t cp)
|
||||
{
|
||||
@ -85,7 +88,7 @@ TEST_CASE("Unicode", "[hide]")
|
||||
// they are checked with codepoint_to_unicode.
|
||||
if (cp > 0x1f and cp != 0x22 and cp != 0x5c)
|
||||
{
|
||||
unescaped_string = json::lexer::to_unicode(cp);
|
||||
unescaped_string = dummy_lexer.to_unicode(cp);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -97,7 +100,7 @@ TEST_CASE("Unicode", "[hide]")
|
||||
const auto codepoint2 = 0xdc00u + ((cp - 0x10000u) & 0x3ffu);
|
||||
escaped_string = codepoint_to_unicode(codepoint1);
|
||||
escaped_string += codepoint_to_unicode(codepoint2);
|
||||
unescaped_string += json::lexer::to_unicode(codepoint1, codepoint2);
|
||||
unescaped_string += dummy_lexer.to_unicode(codepoint1, codepoint2);
|
||||
}
|
||||
|
||||
// all other code points are valid and must not yield parse errors
|
||||
@ -170,7 +173,7 @@ TEST_CASE("Unicode", "[hide]")
|
||||
|
||||
SECTION("error for incomplete/wrong BOM")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse("\xef\xbb"), std::invalid_argument);
|
||||
CHECK_THROWS_AS(json::parse("\xef\xbb\xbb"), std::invalid_argument);
|
||||
CHECK_THROWS_AS(json::parse("\xef\xbb"), json::parse_error);
|
||||
CHECK_THROWS_AS(json::parse("\xef\xbb\xbb"), json::parse_error);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user