mirror of
https://github.com/nlohmann/json.git
synced 2026-07-28 13:24:57 +00:00
lexer: add test checks for numeric literal edge cases
When an integer JSON token exceeds the range of the underlying 64-bit unsigned/integer types, the lexer instead identifies the token type as `value_float`. When the value exceeds the range of the underlying floating-point type, the token type remains as `value_float`. This was previously not tested explicitly for the edge case values and subtly breaking this behavior right around the edge case was not caught by any other test. Signed-off-by: Jonas Greitemann <jgreitemann@gmail.com>
This commit is contained in:
@@ -65,13 +65,20 @@ TEST_CASE("lexer class")
|
||||
CHECK((scan_string("7") == json::lexer::token_type::value_unsigned));
|
||||
CHECK((scan_string("8") == json::lexer::token_type::value_unsigned));
|
||||
CHECK((scan_string("9") == json::lexer::token_type::value_unsigned));
|
||||
CHECK((scan_string("18446744073709551615") == json::lexer::token_type::value_unsigned));
|
||||
|
||||
CHECK((scan_string("-0") == json::lexer::token_type::value_integer));
|
||||
CHECK((scan_string("-1") == json::lexer::token_type::value_integer));
|
||||
CHECK((scan_string("-9223372036854775808") == json::lexer::token_type::value_integer));
|
||||
|
||||
CHECK((scan_string("1.1") == json::lexer::token_type::value_float));
|
||||
CHECK((scan_string("-1.1") == json::lexer::token_type::value_float));
|
||||
CHECK((scan_string("1E10") == json::lexer::token_type::value_float));
|
||||
|
||||
// out-of-range integers/floats are treated as value_float tokens
|
||||
CHECK((scan_string("18446744073709551616") == json::lexer::token_type::value_float));
|
||||
CHECK((scan_string("-9223372036854775809") == json::lexer::token_type::value_float));
|
||||
CHECK((scan_string("1E400") == json::lexer::token_type::value_float));
|
||||
}
|
||||
|
||||
SECTION("whitespace")
|
||||
|
||||
Reference in New Issue
Block a user