From f05614b240a6ed2ebafd256101a22acf2224e393 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 4 Apr 2019 08:56:36 +0200 Subject: [PATCH] :building_construction: adding anonymous namespace --- test/src/unit-allocator.cpp | 7 ++++++- test/src/unit-alt-string.cpp | 4 ---- test/src/unit-bson.cpp | 3 +++ test/src/unit-cbor.cpp | 3 +++ test/src/unit-class_lexer.cpp | 3 +++ test/src/unit-class_parser.cpp | 3 +++ test/src/unit-comparison.cpp | 3 +++ test/src/unit-convenience.cpp | 3 +++ test/src/unit-deserialization.cpp | 3 +++ test/src/unit-msgpack.cpp | 5 +++-- test/src/unit-noexcept.cpp | 3 +++ test/src/unit-testsuites.cpp | 4 +++- test/src/unit-to_chars.cpp | 3 +++ test/src/unit-ubjson.cpp | 3 +++ test/src/unit-unicode.cpp | 6 ++++++ test/src/unit-wstring.cpp | 3 +++ 16 files changed, 51 insertions(+), 8 deletions(-) diff --git a/test/src/unit-allocator.cpp b/test/src/unit-allocator.cpp index 079b8cae..6374640f 100644 --- a/test/src/unit-allocator.cpp +++ b/test/src/unit-allocator.cpp @@ -34,8 +34,9 @@ SOFTWARE. using nlohmann::json; #undef private +namespace +{ // special test case to check if memory is leaked if constructor throws - template struct bad_allocator : std::allocator { @@ -45,6 +46,7 @@ struct bad_allocator : std::allocator throw std::bad_alloc(); } }; +} TEST_CASE("bad_alloc") { @@ -65,6 +67,8 @@ TEST_CASE("bad_alloc") } } +namespace +{ static bool next_construct_fails = false; static bool next_destroy_fails = false; static bool next_deallocate_fails = false; @@ -130,6 +134,7 @@ void my_allocator_clean_up(T* p) alloc.destroy(p); alloc.deallocate(p, 1); } +} TEST_CASE("controlled bad_alloc") { diff --git a/test/src/unit-alt-string.cpp b/test/src/unit-alt-string.cpp index 941a59e7..39206b65 100644 --- a/test/src/unit-alt-string.cpp +++ b/test/src/unit-alt-string.cpp @@ -39,7 +39,6 @@ SOFTWARE. class alt_string; bool operator<(const char* op1, const alt_string& op2); - /* * This is virtually a string class. * It covers std::string under the hood. @@ -155,7 +154,6 @@ class alt_string friend bool ::operator<(const char*, const alt_string&); }; - using alt_json = nlohmann::basic_json < std::map, std::vector, @@ -173,8 +171,6 @@ bool operator<(const char* op1, const alt_string& op2) return op1 < op2.str_impl; } - - TEST_CASE("alternative string type") { SECTION("dump") diff --git a/test/src/unit-bson.cpp b/test/src/unit-bson.cpp index 64de0aa0..2689dcec 100644 --- a/test/src/unit-bson.cpp +++ b/test/src/unit-bson.cpp @@ -608,6 +608,8 @@ TEST_CASE("BSON input/output_adapters") } } +namespace +{ class SaxCountdown { public: @@ -677,6 +679,7 @@ class SaxCountdown private: int events_left = 0; }; +} TEST_CASE("Incomplete BSON Input") { diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 43073bd0..69368b41 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -38,6 +38,8 @@ using nlohmann::json; #include #include +namespace +{ class SaxCountdown { public: @@ -107,6 +109,7 @@ class SaxCountdown private: int events_left = 0; }; +} TEST_CASE("CBOR") { diff --git a/test/src/unit-class_lexer.cpp b/test/src/unit-class_lexer.cpp index 70c11252..64737b57 100644 --- a/test/src/unit-class_lexer.cpp +++ b/test/src/unit-class_lexer.cpp @@ -34,12 +34,15 @@ SOFTWARE. using nlohmann::json; #undef private +namespace +{ // shortcut to scan a string literal json::lexer::token_type scan_string(const char* s); json::lexer::token_type scan_string(const char* s) { return json::lexer(nlohmann::detail::input_adapter(s)).scan(); } +} TEST_CASE("lexer class") { diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index 95df17d6..edbef499 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -36,6 +36,8 @@ using nlohmann::json; #include +namespace +{ class SaxEventLogger { public: @@ -256,6 +258,7 @@ bool accept_helper(const std::string& s) // 7. return result return ok_accept; } +} TEST_CASE("parser class") { diff --git a/test/src/unit-comparison.cpp b/test/src/unit-comparison.cpp index dadb0986..6d02f581 100644 --- a/test/src/unit-comparison.cpp +++ b/test/src/unit-comparison.cpp @@ -32,6 +32,8 @@ SOFTWARE. #include using nlohmann::json; +namespace +{ // helper function to check std::less // see https://en.cppreference.com/w/cpp/utility/functional/less template > @@ -39,6 +41,7 @@ bool f(A a, B b, U u = U()) { return u(a, b); } +} TEST_CASE("lexicographical comparison operators") { diff --git a/test/src/unit-convenience.cpp b/test/src/unit-convenience.cpp index d8fc861f..030b04f6 100644 --- a/test/src/unit-convenience.cpp +++ b/test/src/unit-convenience.cpp @@ -36,6 +36,8 @@ using nlohmann::json; #include +namespace +{ void check_escaped(const char* original, const char* escaped = "", const bool ensure_ascii = false); void check_escaped(const char* original, const char* escaped, const bool ensure_ascii) { @@ -44,6 +46,7 @@ void check_escaped(const char* original, const char* escaped, const bool ensure_ s.dump_escaped(original, ensure_ascii); CHECK(ss.str() == escaped); } +} TEST_CASE("convenience functions") { diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index 90af61fd..10bece66 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -36,6 +36,8 @@ using nlohmann::json; #include #include +namespace +{ struct SaxEventLogger : public nlohmann::json_sax { bool null() override @@ -167,6 +169,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger return false; } }; +} TEST_CASE("deserialization") { diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index c71bafdd..cc1b8ae3 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -37,6 +37,8 @@ using nlohmann::json; #include #include +namespace +{ class SaxCountdown { public: @@ -106,6 +108,7 @@ class SaxCountdown private: int events_left = 0; }; +} TEST_CASE("MessagePack") { @@ -1300,7 +1303,6 @@ TEST_CASE("MessagePack") } } - // use this testcase outside [hide] to run it with Valgrind TEST_CASE("single MessagePack roundtrip") { @@ -1347,7 +1349,6 @@ TEST_CASE("single MessagePack roundtrip") } } - TEST_CASE("MessagePack roundtrips" * doctest::skip()) { SECTION("input from msgpack-python") diff --git a/test/src/unit-noexcept.cpp b/test/src/unit-noexcept.cpp index 78d72f2c..89049bfe 100644 --- a/test/src/unit-noexcept.cpp +++ b/test/src/unit-noexcept.cpp @@ -33,6 +33,8 @@ SOFTWARE. using nlohmann::json; +namespace +{ enum test { }; @@ -59,6 +61,7 @@ static_assert(noexcept(json(pod{})), ""); static_assert(noexcept(j.get()), ""); static_assert(not noexcept(j.get()), ""); static_assert(noexcept(json(pod{})), ""); +} TEST_CASE("runtime checks") { diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index c38b24ef..6496be10 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -418,7 +418,6 @@ TEST_CASE("json.org examples") json j; CHECK_NOTHROW(j.parse(f.get())); } - } TEST_CASE("RFC 7159 examples") @@ -1352,6 +1351,8 @@ TEST_CASE("nst's JSONTestSuite (2)") } } +namespace +{ std::string trim(const std::string& str); // from http://stackoverflow.com/a/25829178/266378 @@ -1365,6 +1366,7 @@ std::string trim(const std::string& str) size_t last = str.find_last_not_of(' '); return str.substr(first, (last - first + 1)); } +} TEST_CASE("Big List of Naughty Strings") { diff --git a/test/src/unit-to_chars.cpp b/test/src/unit-to_chars.cpp index 3399513b..dbd5e175 100644 --- a/test/src/unit-to_chars.cpp +++ b/test/src/unit-to_chars.cpp @@ -36,6 +36,8 @@ SOFTWARE. #include using nlohmann::detail::dtoa_impl::reinterpret_bits; +namespace +{ static float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand) { assert(sign_bit == 0 || sign_bit == 1); @@ -139,6 +141,7 @@ static double make_double(uint64_t f, int e) uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); return reinterpret_bits(bits); } +} TEST_CASE("digit gen") { diff --git a/test/src/unit-ubjson.cpp b/test/src/unit-ubjson.cpp index 86f35b02..ca6b70fd 100644 --- a/test/src/unit-ubjson.cpp +++ b/test/src/unit-ubjson.cpp @@ -35,6 +35,8 @@ using nlohmann::json; #include #include +namespace +{ class SaxCountdown { public: @@ -104,6 +106,7 @@ class SaxCountdown private: int events_left = 0; }; +} TEST_CASE("UBJSON") { diff --git a/test/src/unit-unicode.cpp b/test/src/unit-unicode.cpp index aa854280..e69639f4 100644 --- a/test/src/unit-unicode.cpp +++ b/test/src/unit-unicode.cpp @@ -42,6 +42,8 @@ using nlohmann::json; #include #include +namespace +{ extern size_t calls; size_t calls = 0; @@ -165,6 +167,7 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte CHECK_THROWS_AS(json::parse(json_string), json::parse_error&); } } +} TEST_CASE("Unicode" * doctest::skip()) { @@ -1205,6 +1208,8 @@ TEST_CASE("Unicode" * doctest::skip()) } } +namespace +{ void roundtrip(bool success_expected, const std::string& s); void roundtrip(bool success_expected, const std::string& s) @@ -1244,6 +1249,7 @@ void roundtrip(bool success_expected, const std::string& s) CHECK_THROWS_AS(json::parse(ps), json::parse_error&); } } +} TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test") { diff --git a/test/src/unit-wstring.cpp b/test/src/unit-wstring.cpp index 66bb5938..85aa04db 100644 --- a/test/src/unit-wstring.cpp +++ b/test/src/unit-wstring.cpp @@ -32,6 +32,8 @@ SOFTWARE. #include using nlohmann::json; +namespace +{ bool wstring_is_utf16(); bool wstring_is_utf16() { @@ -49,6 +51,7 @@ bool u32string_is_utf32() { return (std::u32string(U"💩") == std::u32string(U"\U0001F4A9")); } +} TEST_CASE("wide strings") {