Replace limit macros with std::numeric_limits (#3723)

This commit is contained in:
Florian Albrechtskirchinger 2022-09-19 08:02:50 +02:00 committed by GitHub
parent 2d1f9b6a7d
commit 3d1252bbff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 17 deletions

View File

@ -12,6 +12,7 @@
using nlohmann::json; using nlohmann::json;
#include <fstream> #include <fstream>
#include <limits>
#include <sstream> #include <sstream>
#include "make_test_data_available.hpp" #include "make_test_data_available.hpp"
#include "test_utils.hpp" #include "test_utils.hpp"
@ -865,7 +866,7 @@ TEST_CASE("BSON numerical data")
{ {
std::vector<int64_t> const numbers std::vector<int64_t> const numbers
{ {
INT64_MIN, (std::numeric_limits<int64_t>::min)(),
-1000000000000000000LL, -1000000000000000000LL,
-100000000000000000LL, -100000000000000000LL,
-10000000000000000LL, -10000000000000000LL,
@ -875,7 +876,7 @@ TEST_CASE("BSON numerical data")
-1000000000000LL, -1000000000000LL,
-100000000000LL, -100000000000LL,
-10000000000LL, -10000000000LL,
static_cast<std::int64_t>(INT32_MIN) - 1, static_cast<std::int64_t>((std::numeric_limits<std::int32_t>::min)()) - 1,
}; };
for (const auto i : numbers) for (const auto i : numbers)
@ -923,7 +924,7 @@ TEST_CASE("BSON numerical data")
{ {
std::vector<int32_t> const numbers std::vector<int32_t> const numbers
{ {
INT32_MIN, (std::numeric_limits<int32_t>::min)(),
-2147483647L, -2147483647L,
-1000000000L, -1000000000L,
-100000000L, -100000000L,
@ -947,7 +948,7 @@ TEST_CASE("BSON numerical data")
100000000L, 100000000L,
1000000000L, 1000000000L,
2147483646L, 2147483646L,
INT32_MAX (std::numeric_limits<int32_t>::max)()
}; };
for (const auto i : numbers) for (const auto i : numbers)
@ -990,7 +991,7 @@ TEST_CASE("BSON numerical data")
{ {
std::vector<int64_t> const numbers std::vector<int64_t> const numbers
{ {
INT64_MAX, (std::numeric_limits<int64_t>::max)(),
1000000000000000000LL, 1000000000000000000LL,
100000000000000000LL, 100000000000000000LL,
10000000000000000LL, 10000000000000000LL,
@ -1000,7 +1001,7 @@ TEST_CASE("BSON numerical data")
1000000000000LL, 1000000000000LL,
100000000000LL, 100000000000LL,
10000000000LL, 10000000000LL,
static_cast<std::int64_t>(INT32_MAX) + 1, static_cast<std::int64_t>((std::numeric_limits<int32_t>::max)()) + 1,
}; };
for (const auto i : numbers) for (const auto i : numbers)
@ -1062,7 +1063,7 @@ TEST_CASE("BSON numerical data")
100000000ULL, 100000000ULL,
1000000000ULL, 1000000000ULL,
2147483646ULL, 2147483646ULL,
static_cast<std::uint64_t>(INT32_MAX) static_cast<std::uint64_t>((std::numeric_limits<int32_t>::max)())
}; };
for (const auto i : numbers) for (const auto i : numbers)
@ -1105,9 +1106,9 @@ TEST_CASE("BSON numerical data")
{ {
std::vector<std::uint64_t> const numbers std::vector<std::uint64_t> const numbers
{ {
static_cast<std::uint64_t>(INT32_MAX) + 1, static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()) + 1,
4000000000ULL, 4000000000ULL,
static_cast<std::uint64_t>(UINT32_MAX), static_cast<std::uint64_t>((std::numeric_limits<std::uint32_t>::max)()),
10000000000ULL, 10000000000ULL,
100000000000ULL, 100000000000ULL,
1000000000000ULL, 1000000000000ULL,
@ -1117,7 +1118,7 @@ TEST_CASE("BSON numerical data")
10000000000000000ULL, 10000000000000000ULL,
100000000000000000ULL, 100000000000000000ULL,
1000000000000000000ULL, 1000000000000000000ULL,
static_cast<std::uint64_t>(INT64_MAX), static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()),
}; };
for (const auto i : numbers) for (const auto i : numbers)
@ -1163,11 +1164,11 @@ TEST_CASE("BSON numerical data")
{ {
std::vector<std::uint64_t> const numbers std::vector<std::uint64_t> const numbers
{ {
static_cast<std::uint64_t>(INT64_MAX) + 1ULL, static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()) + 1ULL,
10000000000000000000ULL, 10000000000000000000ULL,
18000000000000000000ULL, 18000000000000000000ULL,
UINT64_MAX - 1ULL, (std::numeric_limits<std::uint64_t>::max)() - 1ULL,
UINT64_MAX, (std::numeric_limits<std::uint64_t>::max)(),
}; };
for (const auto i : numbers) for (const auto i : numbers)

View File

@ -15,6 +15,7 @@ using nlohmann::json;
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <limits>
#include <set> #include <set>
#include "make_test_data_available.hpp" #include "make_test_data_available.hpp"
#include "test_utils.hpp" #include "test_utils.hpp"
@ -174,7 +175,7 @@ TEST_CASE("CBOR")
{ {
const std::vector<int64_t> numbers const std::vector<int64_t> numbers
{ {
INT64_MIN, (std::numeric_limits<int64_t>::min)(),
-1000000000000000000, -1000000000000000000,
-100000000000000000, -100000000000000000,
-10000000000000000, -10000000000000000,

View File

@ -17,6 +17,7 @@ using nlohmann::json;
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <limits>
#include <set> #include <set>
#include "make_test_data_available.hpp" #include "make_test_data_available.hpp"
#include "test_utils.hpp" #include "test_utils.hpp"
@ -526,7 +527,7 @@ TEST_CASE("MessagePack")
{ {
std::vector<int64_t> const numbers std::vector<int64_t> const numbers
{ {
INT64_MIN, (std::numeric_limits<int64_t>::min)(),
-2147483649LL, -2147483649LL,
}; };
for (auto i : numbers) for (auto i : numbers)

View File

@ -21,6 +21,7 @@ using nlohmann::json;
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <list> #include <list>
#include <limits>
#include <cstdio> #include <cstdio>
#include "make_test_data_available.hpp" #include "make_test_data_available.hpp"
@ -877,12 +878,12 @@ TEST_CASE("regression tests 1")
// original test case // original test case
json const j1 = json::parse("-9223372036854775808"); json const j1 = json::parse("-9223372036854775808");
CHECK(j1.is_number_integer()); CHECK(j1.is_number_integer());
CHECK(j1.get<json::number_integer_t>() == INT64_MIN); CHECK(j1.get<json::number_integer_t>() == (std::numeric_limits<std::int64_t>::min)());
// edge case (+1; still an integer) // edge case (+1; still an integer)
json const j2 = json::parse("-9223372036854775807"); json const j2 = json::parse("-9223372036854775807");
CHECK(j2.is_number_integer()); CHECK(j2.is_number_integer());
CHECK(j2.get<json::number_integer_t>() == INT64_MIN + 1); CHECK(j2.get<json::number_integer_t>() == (std::numeric_limits<std::int64_t>::min)() + 1);
// edge case (-1; overflow -> floats) // edge case (-1; overflow -> floats)
json const j3 = json::parse("-9223372036854775809"); json const j3 = json::parse("-9223372036854775809");

View File

@ -7,6 +7,8 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "doctest_compatibility.h" #include "doctest_compatibility.h"
#undef WIN32_LEAN_AND_MEAN
#undef NOMINMAX
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>