mirror of
https://github.com/nlohmann/json.git
synced 2026-02-28 14:26:26 +00:00
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
@@ -192,6 +192,17 @@ struct adl_serializer<NonDefaultFromJsonStruct>
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1805
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct NotSerializableData
|
||||
{
|
||||
int mydata;
|
||||
float myfloat;
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE("regression tests")
|
||||
{
|
||||
SECTION("issue #60 - Double quotation mark is not parsed correctly")
|
||||
@@ -1771,31 +1782,37 @@ TEST_CASE("regression tests")
|
||||
{
|
||||
SECTION("a bunch of -1, ensure_ascii=true")
|
||||
{
|
||||
const auto length = 300;
|
||||
|
||||
json dump_test;
|
||||
std::vector<char> data(300, -1);
|
||||
std::vector<std::string> vec_string(300, "\\ufffd");
|
||||
std::string s{data.data(), data.size()};
|
||||
dump_test["1"] = s;
|
||||
std::ostringstream os;
|
||||
os << "{\"1\":\"";
|
||||
std::copy( vec_string.begin(), vec_string.end(), std::ostream_iterator<std::string>(os));
|
||||
os << "\"}";
|
||||
s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
|
||||
CHECK(s == os.str());
|
||||
dump_test["1"] = std::string(length, -1);
|
||||
|
||||
std::string expected = "{\"1\":\"";
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected += "\\ufffd";
|
||||
}
|
||||
expected += "\"}";
|
||||
|
||||
auto s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
|
||||
CHECK(s == expected);
|
||||
}
|
||||
SECTION("a bunch of -2, ensure_ascii=false")
|
||||
{
|
||||
const auto length = 500;
|
||||
|
||||
json dump_test;
|
||||
std::vector<char> data(500, -2);
|
||||
std::vector<std::string> vec_string(500, "\xEF\xBF\xBD");
|
||||
std::string s{data.data(), data.size()};
|
||||
dump_test["1"] = s;
|
||||
std::ostringstream os;
|
||||
os << "{\"1\":\"";
|
||||
std::copy( vec_string.begin(), vec_string.end(), std::ostream_iterator<std::string>(os));
|
||||
os << "\"}";
|
||||
s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
|
||||
CHECK(s == os.str());
|
||||
dump_test["1"] = std::string(length, -2);
|
||||
|
||||
std::string expected = "{\"1\":\"";
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected += "\xEF\xBF\xBD";
|
||||
}
|
||||
expected += "\"}";
|
||||
|
||||
auto s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
|
||||
CHECK(s == expected);
|
||||
}
|
||||
SECTION("test case in issue #1445")
|
||||
{
|
||||
@@ -1858,6 +1875,13 @@ TEST_CASE("regression tests")
|
||||
auto val = nlohmann::json("one").get<for_1647>();
|
||||
CHECK(val == for_1647::one);
|
||||
}
|
||||
|
||||
SECTION("issue #1805 - A pair<T1, T2> is json constructible only if T1 and T2 are json constructible")
|
||||
{
|
||||
static_assert(!std::is_constructible<json, std::pair<std::string, NotSerializableData>>::value, "");
|
||||
static_assert(!std::is_constructible<json, std::pair<NotSerializableData, std::string>>::value, "");
|
||||
static_assert(std::is_constructible<json, std::pair<int, std::string>>::value, "");
|
||||
}
|
||||
}
|
||||
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
|
||||
Reference in New Issue
Block a user