🏗️ adding anonymous namespace

This commit is contained in:
Niels Lohmann 2019-04-04 08:56:36 +02:00
parent 0da99027b7
commit f05614b240
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
16 changed files with 51 additions and 8 deletions

View file

@ -34,8 +34,9 @@ SOFTWARE.
using nlohmann::json;
#undef private
namespace
{
// special test case to check if memory is leaked if constructor throws
template<class T>
struct bad_allocator : std::allocator<T>
{
@ -45,6 +46,7 @@ struct bad_allocator : std::allocator<T>
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")
{

View file

@ -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")

View file

@ -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")
{

View file

@ -38,6 +38,8 @@ using nlohmann::json;
#include <iomanip>
#include <set>
namespace
{
class SaxCountdown
{
public:
@ -107,6 +109,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
TEST_CASE("CBOR")
{

View file

@ -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")
{

View file

@ -36,6 +36,8 @@ using nlohmann::json;
#include <valarray>
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")
{

View file

@ -32,6 +32,8 @@ SOFTWARE.
#include <nlohmann/json.hpp>
using nlohmann::json;
namespace
{
// helper function to check std::less<json::value_t>
// see https://en.cppreference.com/w/cpp/utility/functional/less
template <typename A, typename B, typename U = std::less<json::value_t>>
@ -39,6 +41,7 @@ bool f(A a, B b, U u = U())
{
return u(a, b);
}
}
TEST_CASE("lexicographical comparison operators")
{

View file

@ -36,6 +36,8 @@ using nlohmann::json;
#include <sstream>
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")
{

View file

@ -36,6 +36,8 @@ using nlohmann::json;
#include <sstream>
#include <valarray>
namespace
{
struct SaxEventLogger : public nlohmann::json_sax<json>
{
bool null() override
@ -167,6 +169,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
return false;
}
};
}
TEST_CASE("deserialization")
{

View file

@ -37,6 +37,8 @@ using nlohmann::json;
#include <iomanip>
#include <set>
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")

View file

@ -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<pod>()), "");
static_assert(not noexcept(j.get<pod_bis>()), "");
static_assert(noexcept(json(pod{})), "");
}
TEST_CASE("runtime checks")
{

View file

@ -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")
{

View file

@ -36,6 +36,8 @@ SOFTWARE.
#include <nlohmann/json.hpp>
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<double>(bits);
}
}
TEST_CASE("digit gen")
{

View file

@ -35,6 +35,8 @@ using nlohmann::json;
#include <fstream>
#include <set>
namespace
{
class SaxCountdown
{
public:
@ -104,6 +106,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
TEST_CASE("UBJSON")
{

View file

@ -42,6 +42,8 @@ using nlohmann::json;
#include <iostream>
#include <iomanip>
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")
{

View file

@ -32,6 +32,8 @@ SOFTWARE.
#include <nlohmann/json.hpp>
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")
{