1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

added test of json writer

This commit is contained in:
Falk Werner 2020-07-15 23:01:08 +02:00
parent 9fa6241b6b
commit 860757ea4c

View File

@ -213,3 +213,57 @@ TEST(json_writer, reset)
ASSERT_EQ("42", writer.take()); ASSERT_EQ("42", writer.take());
} }
TEST(json_writer, write_object_null)
{
writer writer;
wf_impl_json_write_object_begin(writer);
wf_impl_json_write_object_null(writer, "error");
wf_impl_json_write_object_end(writer);
ASSERT_EQ("{\"error\":null}", writer.take());
}
TEST(json_writer, write_object_bool)
{
writer writer;
wf_impl_json_write_object_begin(writer);
wf_impl_json_write_object_bool(writer, "result", true);
wf_impl_json_write_object_end(writer);
ASSERT_EQ("{\"result\":true}", writer.take());
}
TEST(json_writer, write_object_string_nocheck)
{
writer writer;
wf_impl_json_write_object_begin(writer);
wf_impl_json_write_object_string(writer, "result", "Hello,\tWorld!");
wf_impl_json_write_object_end(writer);
ASSERT_EQ("{\"result\": \"Hello,\tWorld!\"}", writer.take());
}
TEST(json_writer, write_object_bytes)
{
writer writer;
wf_impl_json_write_object_begin(writer);
wf_impl_json_write_object_bytes(writer, "result", "\0\0", 2);
wf_impl_json_write_object_end(writer);
ASSERT_EQ("{\"result\": \"AAA\"}", writer.take());
}
TEST(json_writer, realloc_buffer)
{
writer writer(1);
wf_impl_json_write_string(writer, "very large contents");
ASSERT_EQ("very large contents", writer.take());
}
TEST(json_writer, unexpected_end)
{
writer writer;
wf_impl_json_write_array_end(writer);
}