Commit dad4916f authored by Niels Lohmann's avatar Niels Lohmann Committed by GitHub

Merge pull request #654 from ryanjmulder/develop

add ensure_ascii parameter to dump. #330
parents 7dee868a 486f3a2d
This diff is collapsed.
......@@ -50,11 +50,12 @@ TEST_CASE("convenience functions")
SECTION("string escape")
{
const auto check_escaped = [](const char* original,
const char* escaped)
const char* escaped,
const bool ensure_ascii = false)
{
std::stringstream ss;
json::serializer s(nlohmann::detail::output_adapter_factory<char>::create(ss), ' ');
s.dump_escaped(original);
s.dump_escaped(original, ensure_ascii);
CHECK(ss.str() == escaped);
};
......@@ -97,5 +98,7 @@ TEST_CASE("convenience functions")
check_escaped("\x1d", "\\u001d");
check_escaped("\x1e", "\\u001e");
check_escaped("\x1f", "\\u001f");
check_escaped("\xA9", "\xA9");
check_escaped("\xA9", "\\u00a9", true);
}
}
......@@ -250,6 +250,13 @@ TEST_CASE("object inspection")
CHECK(json("❤️").dump() == "\"❤️\"");
}
SECTION("dump with ensure_ascii and non-ASCII characters")
{
CHECK(json("ä").dump(-1, ' ', true) == R"("\u00c3\u00a4")");
CHECK(json("Ö").dump(-1, ' ', true) == R"("\u00c3\u0096")");
CHECK(json("❤️").dump(-1, ' ', true) == R"("\u00e2\u009d\u00a4\u00ef\u00b8\u008f")");
}
SECTION("serialization of discarded element")
{
json j_discarded(json::value_t::discarded);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment