From fd969a679b4a008526d4853a7c98254268b4fc0c Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 12 Feb 2023 19:03:59 +0900 Subject: [PATCH] test: check if a large bin ints are parsed --- tests/test_parse_integer.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_parse_integer.cpp b/tests/test_parse_integer.cpp index 423961f..4a86226 100644 --- a/tests/test_parse_integer.cpp +++ b/tests/test_parse_integer.cpp @@ -84,6 +84,22 @@ BOOST_AUTO_TEST_CASE(test_bin_value) TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "0b010000", value(16)); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "0b01_00_00", value(16)); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "0b111111", value(63)); + + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "0b1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000", + // 1 0 0 0 + // 0 C 8 4 + value(0x0888888888888888)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "0b01111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111", + // 1 0 0 0 + // 0 C 8 4 + value(0x7FFFFFFFFFFFFFFF)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "0b00000000_01111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111", + // 1 0 0 0 + // 0 C 8 4 + value(0x7FFFFFFFFFFFFFFF)); } BOOST_AUTO_TEST_CASE(test_integer_overflow) @@ -91,7 +107,8 @@ BOOST_AUTO_TEST_CASE(test_integer_overflow) std::istringstream dec_overflow(std::string("dec-overflow = 9223372036854775808")); std::istringstream hex_overflow(std::string("hex-overflow = 0x1_00000000_00000000")); std::istringstream oct_overflow(std::string("oct-overflow = 0o1_000_000_000_000_000_000_000")); - std::istringstream bin_overflow(std::string("bin-overflow = 0b1_00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000")); + // 64 56 48 40 32 24 16 8 + std::istringstream bin_overflow(std::string("bin-overflow = 0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000")); BOOST_CHECK_THROW(toml::parse(dec_overflow), toml::syntax_error); BOOST_CHECK_THROW(toml::parse(hex_overflow), toml::syntax_error); BOOST_CHECK_THROW(toml::parse(oct_overflow), toml::syntax_error);