From 6fb162a394f670a15b66befe255b06211e16d498 Mon Sep 17 00:00:00 2001 From: Jonas Greitemann Date: Sat, 27 Jun 2026 19:56:28 +0200 Subject: [PATCH] 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 --- tests/src/unit-class_lexer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index 64baf3da6..92eadfbc1 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp @@ -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")