From c9dd260a4c53c95c657eedfccb72851d443a12b7 Mon Sep 17 00:00:00 2001 From: Isaac Nickaein Date: Tue, 1 Jan 2019 12:49:51 -0800 Subject: [PATCH] Add unit tests for dump_integer Add some unit tests for formatting integers to keep code coverage as before. --- test/src/unit-to_chars.cpp | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/src/unit-to_chars.cpp b/test/src/unit-to_chars.cpp index fd2ee121..a8c7492c 100644 --- a/test/src/unit-to_chars.cpp +++ b/test/src/unit-to_chars.cpp @@ -471,4 +471,64 @@ TEST_CASE("formatting") check_double( 1.2345e+21, "1.2344999999999999e+21" ); // 1.2345e+21 1.2344999999999999e+21 1.2345e21 check_double( 1.2345e+22, "1.2345e+22" ); // 1.2345e+22 1.2345e+22 1.2345e22 } + + SECTION("integer") + { + auto check_integer = [](std::int64_t number, const std::string & expected) + { + nlohmann::json j = number; + CHECK(j.dump() == expected); + }; + + // edge cases + check_integer(INT64_MIN, "-9223372036854775808"); + check_integer(INT64_MAX, "9223372036854775807"); + + // few random big integers + check_integer(-3456789012345678901LL, "-3456789012345678901"); + check_integer(3456789012345678901LL, "3456789012345678901"); + check_integer(-5678901234567890123LL, "-5678901234567890123"); + check_integer(5678901234567890123LL, "5678901234567890123"); + + // integers with various digit counts + check_integer(-1000000000000000000LL, "-1000000000000000000"); + check_integer(-100000000000000000LL, "-100000000000000000"); + check_integer(-10000000000000000LL, "-10000000000000000"); + check_integer(-1000000000000000LL, "-1000000000000000"); + check_integer(-100000000000000LL, "-100000000000000"); + check_integer(-10000000000000LL, "-10000000000000"); + check_integer(-1000000000000LL, "-1000000000000"); + check_integer(-100000000000LL, "-100000000000"); + check_integer(-10000000000LL, "-10000000000"); + check_integer(-1000000000LL, "-1000000000"); + check_integer(-100000000LL, "-100000000"); + check_integer(-10000000LL, "-10000000"); + check_integer(-1000000LL, "-1000000"); + check_integer(-100000LL, "-100000"); + check_integer(-10000LL, "-10000"); + check_integer(-1000LL, "-1000"); + check_integer(-100LL, "-100"); + check_integer(-10LL, "-10"); + check_integer(-1LL, "-1"); + check_integer(0, "0"); + check_integer(1LL, "1"); + check_integer(10LL, "10"); + check_integer(100LL, "100"); + check_integer(1000LL, "1000"); + check_integer(10000LL, "10000"); + check_integer(100000LL, "100000"); + check_integer(1000000LL, "1000000"); + check_integer(10000000LL, "10000000"); + check_integer(100000000LL, "100000000"); + check_integer(1000000000LL, "1000000000"); + check_integer(10000000000LL, "10000000000"); + check_integer(100000000000LL, "100000000000"); + check_integer(1000000000000LL, "1000000000000"); + check_integer(10000000000000LL, "10000000000000"); + check_integer(100000000000000LL, "100000000000000"); + check_integer(1000000000000000LL, "1000000000000000"); + check_integer(10000000000000000LL, "10000000000000000"); + check_integer(100000000000000000LL, "100000000000000000"); + check_integer(1000000000000000000LL, "1000000000000000000"); + } }