more test cases

This commit is contained in:
Niels 2015-02-10 20:28:16 +01:00
parent 8c6bb04d10
commit 3589837071
3 changed files with 68 additions and 10 deletions

View file

@ -1463,11 +1463,6 @@ class basic_json
switch (m_type)
{
case (value_t::null):
{
return "null";
}
case (value_t::object):
{
if (m_value.object->empty())
@ -1558,6 +1553,11 @@ class basic_json
{
return std::to_string(m_value.number_float);
}
default:
{
return "null";
}
}
}

View file

@ -1463,11 +1463,6 @@ class basic_json
switch (m_type)
{
case (value_t::null):
{
return "null";
}
case (value_t::object):
{
if (m_value.object->empty())
@ -1558,6 +1553,11 @@ class basic_json
{
return std::to_string(m_value.number_float);
}
default:
{
return "null";
}
}
}

View file

@ -3915,3 +3915,61 @@ TEST_CASE("deserialization")
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
}
}
TEST_CASE("convenience functions")
{
SECTION("type name as string")
{
CHECK(json(json::value_t::null).type_name() == "null");
CHECK(json(json::value_t::object).type_name() == "object");
CHECK(json(json::value_t::array).type_name() == "array");
CHECK(json(json::value_t::number_integer).type_name() == "number");
CHECK(json(json::value_t::number_float).type_name() == "number");
CHECK(json(json::value_t::boolean).type_name() == "boolean");
CHECK(json(json::value_t::string).type_name() == "string");
}
SECTION("string escape")
{
CHECK(json::escape_string("\"") == "\\\"");
CHECK(json::escape_string("\\") == "\\\\");
CHECK(json::escape_string("\b") == "\\b");
CHECK(json::escape_string("\f") == "\\f");
CHECK(json::escape_string("\n") == "\\n");
CHECK(json::escape_string("\r") == "\\r");
CHECK(json::escape_string("\t") == "\\t");
CHECK(json::escape_string( "\x01" ) == "\\u0001");
CHECK(json::escape_string( "\x02" ) == "\\u0002");
CHECK(json::escape_string( "\x03" ) == "\\u0003");
CHECK(json::escape_string( "\x04" ) == "\\u0004");
CHECK(json::escape_string( "\x05" ) == "\\u0005");
CHECK(json::escape_string( "\x06" ) == "\\u0006");
CHECK(json::escape_string( "\x07" ) == "\\u0007");
CHECK(json::escape_string( "\x08" ) == "\\b");
CHECK(json::escape_string( "\x09" ) == "\\t");
CHECK(json::escape_string( "\x0a" ) == "\\n");
CHECK(json::escape_string( "\x0b" ) == "\\u000b");
CHECK(json::escape_string( "\x0c" ) == "\\f");
CHECK(json::escape_string( "\x0d" ) == "\\r");
CHECK(json::escape_string( "\x0e" ) == "\\u000e");
CHECK(json::escape_string( "\x0f" ) == "\\u000f");
CHECK(json::escape_string( "\x10" ) == "\\u0010");
CHECK(json::escape_string( "\x11" ) == "\\u0011");
CHECK(json::escape_string( "\x12" ) == "\\u0012");
CHECK(json::escape_string( "\x13" ) == "\\u0013");
CHECK(json::escape_string( "\x14" ) == "\\u0014");
CHECK(json::escape_string( "\x15" ) == "\\u0015");
CHECK(json::escape_string( "\x16" ) == "\\u0016");
CHECK(json::escape_string( "\x17" ) == "\\u0017");
CHECK(json::escape_string( "\x18" ) == "\\u0018");
CHECK(json::escape_string( "\x19" ) == "\\u0019");
CHECK(json::escape_string( "\x1a" ) == "\\u001a");
CHECK(json::escape_string( "\x1b" ) == "\\u001b");
CHECK(json::escape_string( "\x1c" ) == "\\u001c");
CHECK(json::escape_string( "\x1d" ) == "\\u001d");
CHECK(json::escape_string( "\x1e" ) == "\\u001e");
CHECK(json::escape_string( "\x1f" ) == "\\u001f");
}
}