From f1bd206994786cdf3a48516d6dcd2997b499a00c Mon Sep 17 00:00:00 2001 From: Niels Date: Wed, 11 Feb 2015 11:36:45 +0100 Subject: [PATCH] number test cases --- src/json.hpp | 1 - src/json.hpp.re2c | 1 - test/unit.cpp | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 0c524c89..c405ba0c 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3207,7 +3207,6 @@ json_parser_62: // check if strtod read beyond the end of the lexem if (endptr != m_cursor) { - std::cerr << get_string_value() << std::endl; return NAN; } else diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 3b697faa..1bfe3a2d 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2566,7 +2566,6 @@ class basic_json // check if strtod read beyond the end of the lexem if (endptr != m_cursor) { - std::cerr << get_string_value() << std::endl; return NAN; } else diff --git a/test/unit.cpp b/test/unit.cpp index c7f2a8b8..f475bdfe 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -3799,8 +3799,6 @@ TEST_CASE("lexicographical comparison operators") { for (size_t j = 0; j < j_values.size(); ++j) { - CAPTURE(i); - CAPTURE(j); // check precomputed values CHECK( (j_values[i] < j_values[j]) == expected[i][j] ); } @@ -4044,9 +4042,6 @@ TEST_CASE("lexer class") { auto s = std::string(1, c); - CAPTURE(c); - CAPTURE(s); - switch (c) { // characters that are prefixes of reasonable json @@ -4116,5 +4111,36 @@ TEST_CASE("parser class") { CHECK(json::parser("false").parse() == json(false)); } + + SECTION("number") + { + SECTION("integers") + { + SECTION("without exponent") + { + CHECK(json::parser("-128").parse() == json(-128)); + CHECK(json::parser("0").parse() == json(0)); + CHECK(json::parser("128").parse() == json(128)); + } + + SECTION("with exponent") + { + CHECK(json::parser("10000E-4").parse() == json(10000e-4)); + CHECK(json::parser("10000E-3").parse() == json(10000e-3)); + CHECK(json::parser("10000E-2").parse() == json(10000e-2)); + CHECK(json::parser("10000E-1").parse() == json(10000e-1)); + CHECK(json::parser("10000E0").parse() == json(10000e0)); + CHECK(json::parser("10000E1").parse() == json(10000e1)); + CHECK(json::parser("10000E2").parse() == json(10000e2)); + CHECK(json::parser("10000E3").parse() == json(10000e3)); + CHECK(json::parser("10000E4").parse() == json(10000e4)); + } + } + + SECTION("invalid numbers") + { + CHECK_THROWS_AS(json::parser("01").parse(), std::invalid_argument); + } + } } }