🔨 improved code coverage

This commit is contained in:
Niels Lohmann 2017-04-01 08:34:58 +02:00
parent c32d2e5b3c
commit 3a5cf9bd0a
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
2 changed files with 13 additions and 6 deletions

View File

@ -10965,6 +10965,9 @@ class basic_json
codepoint = codepoint1;
}
// result of the above calculation yields a proper codepoint
assert(0x00 <= codepoint and codepoint <= 0x10FFFF);
// translate code point to bytes
if (codepoint < 0x80)
{
@ -10984,7 +10987,7 @@ class basic_json
add(0x80 | ((codepoint >> 6) & 0x3F));
add(0x80 | (codepoint & 0x3F));
}
else if (codepoint <= 0x10ffff)
else
{
// 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
add(0xF0 | (codepoint >> 18));
@ -10992,11 +10995,6 @@ class basic_json
add(0x80 | ((codepoint >> 6) & 0x3F));
add(0x80 | (codepoint & 0x3F));
}
else
{
error_message = "invalid string: code points above U+10FFFF are invalid";
return token_type::parse_error;
}
break;
}

View File

@ -158,6 +158,15 @@ TEST_CASE("lexer class")
}
}
SECTION("very large string")
{
// strings larger than 1024 bytes yield a resize of the lexer's yytext buffer
std::string s("\"");
s += std::string(2048, 'x');
s += "\"";
CHECK((json::lexer(s.c_str(), 2050).scan() == json::lexer::token_type::value_string));
}
/* NOTE: to_unicode function has been removed
SECTION("to_unicode")
{