| 7 | |
| 8 | Y_UNIT_TEST_SUITE(TJsonWriterTest) { |
| 9 | Y_UNIT_TEST(SimpleWriteTest) { |
| 10 | TString expected1 = "{\"key1\":1,\"key2\":2,\"key3\":3"; |
| 11 | TString expected2 = expected1 + ",\"array\":[\"stroka\",false]"; |
| 12 | TString expected3 = expected2 + "}"; |
| 13 | |
| 14 | TStringStream out; |
| 15 | |
| 16 | TJsonWriter json(&out, false); |
| 17 | json.OpenMap(); |
| 18 | json.Write("key1", (ui16)1); |
| 19 | json.WriteKey("key2"); |
| 20 | json.Write((i32)2); |
| 21 | json.Write("key3", (ui64)3); |
| 22 | |
| 23 | UNIT_ASSERT(out.Empty()); |
| 24 | json.Flush(); |
| 25 | UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected1); |
| 26 | |
| 27 | json.Write("array"); |
| 28 | json.OpenArray(); |
| 29 | json.Write("stroka"); |
| 30 | json.Write(false); |
| 31 | json.CloseArray(); |
| 32 | |
| 33 | UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected1); |
| 34 | json.Flush(); |
| 35 | UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected2); |
| 36 | |
| 37 | json.CloseMap(); |
| 38 | |
| 39 | UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected2); |
| 40 | json.Flush(); |
| 41 | UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected3); |
| 42 | } |
| 43 | |
| 44 | Y_UNIT_TEST(SimpleWriteValueTest) { |
| 45 | TString expected = "{\"key1\":null,\"key2\":{\"subkey1\":[1,{\"subsubkey\":\"test2\"},null,true],\"subkey2\":\"test\"}}"; |
nothing calls this directly
no test coverage detected