Skip to content

Commit

Permalink
add some testcases: WriteTest, StreamWriterTest (open-source-parsers#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 authored and baylesj committed Sep 16, 2019
1 parent 21ab829 commit 3550a0a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,27 @@ JSONTEST_FIXTURE(WriterTest, dropNullPlaceholders) {
JSONTEST_ASSERT(writer.write(nullValue) == "\n");
}

JSONTEST_FIXTURE(WriterTest, enableYAMLCompatibility) {
Json::FastWriter writer;
Json::Value root;
root["hello"] = "world";

JSONTEST_ASSERT(writer.write(root) == "{\"hello\":\"world\"}\n");

writer.enableYAMLCompatibility();
JSONTEST_ASSERT(writer.write(root) == "{\"hello\": \"world\"}\n");
}

JSONTEST_FIXTURE(WriterTest, omitEndingLineFeed) {
Json::FastWriter writer;
Json::Value nullValue;

JSONTEST_ASSERT(writer.write(nullValue) == "null\n");

writer.omitEndingLineFeed();
JSONTEST_ASSERT(writer.write(nullValue) == "null");
}

struct StreamWriterTest : JsonTest::TestCase {};

JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) {
Expand All @@ -1875,6 +1896,33 @@ JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) {
JSONTEST_ASSERT(Json::writeString(b, nullValue).empty());
}

JSONTEST_FIXTURE(StreamWriterTest, enableYAMLCompatibility) {
Json::StreamWriterBuilder b;
Json::Value root;
root["hello"] = "world";

b.settings_["indentation"] = "";
JSONTEST_ASSERT(Json::writeString(b, root) == "{\"hello\":\"world\"}");

b.settings_["enableYAMLCompatibility"] = true;
JSONTEST_ASSERT(Json::writeString(b, root) == "{\"hello\": \"world\"}");

b.settings_["enableYAMLCompatibility"] = false;
JSONTEST_ASSERT(Json::writeString(b, root) == "{\"hello\":\"world\"}");
}

JSONTEST_FIXTURE(StreamWriterTest, indentation) {
Json::StreamWriterBuilder b;
Json::Value root;
root["hello"] = "world";

b.settings_["indentation"] = "";
JSONTEST_ASSERT(Json::writeString(b, root) == "{\"hello\":\"world\"}");

b.settings_["indentation"] = "\t";
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"hello\" : \"world\"\n}");
}

JSONTEST_FIXTURE(StreamWriterTest, writeZeroes) {
Json::String binary("hi", 3); // include trailing 0
JSONTEST_ASSERT_EQUAL(3, binary.length());
Expand Down Expand Up @@ -2622,7 +2670,11 @@ int main(int argc, const char* argv[]) {
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, precision);

JSONTEST_REGISTER_FIXTURE(runner, WriterTest, dropNullPlaceholders);
JSONTEST_REGISTER_FIXTURE(runner, WriterTest, enableYAMLCompatibility);
JSONTEST_REGISTER_FIXTURE(runner, WriterTest, omitEndingLineFeed);
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders);
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, enableYAMLCompatibility);
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, indentation);
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, writeZeroes);

JSONTEST_REGISTER_FIXTURE(runner, ReaderTest, parseWithNoErrors);
Expand Down

0 comments on commit 3550a0a

Please sign in to comment.