Merge pull request #1722 from t-b/fix-int64-min-issue

Fix int64 min issue
This commit is contained in:
Niels Lohmann 2019-09-10 07:58:02 +02:00 committed by GitHub
commit 06ccd43a2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 2 deletions

View file

@ -1802,6 +1802,13 @@ TEST_CASE("regression tests")
json j = json::parse("[-9223372036854775808]");
CHECK(j.dump() == "[-9223372036854775808]");
}
SECTION("issue #1708 - minimum value of int64_t can be outputted")
{
constexpr auto smallest = (std::numeric_limits<int64_t>::min)();
json j = smallest;
CHECK(j.dump() == std::to_string(smallest));
}
}
#if not defined(JSON_NOEXCEPTION)

View file

@ -189,3 +189,20 @@ TEST_CASE("serialization")
test("[3,\"false\",false]", "[3,\\\"false\\\",false]");
}
}
TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint32_t, int64_t, uint64_t)
{
SECTION("minimum")
{
constexpr auto minimum = (std::numeric_limits<T>::min)();
json j = minimum;
CHECK(j.dump() == std::to_string(minimum));
}
SECTION("maximum")
{
constexpr auto maximum = (std::numeric_limits<T>::max)();
json j = maximum;
CHECK(j.dump() == std::to_string(maximum));
}
}