| Index: runtime/vm/json_test.cc
|
| diff --git a/runtime/vm/json_test.cc b/runtime/vm/json_test.cc
|
| index 90c9fdfb4363e9b543be6a5cd25d4ee5cd53ec78..030a51947f2eecc15ccfe1aadd1bea03755145dc 100644
|
| --- a/runtime/vm/json_test.cc
|
| +++ b/runtime/vm/json_test.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "platform/assert.h"
|
| #include "platform/json.h"
|
| +#include "vm/json_stream.h"
|
| #include "vm/unit_test.h"
|
|
|
| namespace dart {
|
| @@ -116,4 +117,65 @@ TEST_CASE(JSON_TextBuffer) {
|
| EXPECT(r.IsStringLiteral("stopIt"));
|
| }
|
|
|
| +
|
| +TEST_CASE(JSONStream_Primitives) {
|
| + TextBuffer tb(256);
|
| + JSONStream js(&tb);
|
| +
|
| + js.OpenObject();
|
| + js.CloseObject();
|
| +
|
| + EXPECT_STREQ("{}", tb.buf());
|
| +
|
| + js.Clear();
|
| + js.OpenArray();
|
| + js.CloseArray();
|
| + EXPECT_STREQ("[]", tb.buf());
|
| +
|
| + js.Clear();
|
| + js.PrintValueBool(true);
|
| + EXPECT_STREQ("true", tb.buf());
|
| +
|
| + js.Clear();
|
| + js.PrintValueBool(false);
|
| + EXPECT_STREQ("false", tb.buf());
|
| +
|
| + js.Clear();
|
| + js.PrintValue(4);
|
| + EXPECT_STREQ("4", tb.buf());
|
| +
|
| + js.Clear();
|
| + js.PrintValue(1.0);
|
| + EXPECT_STREQ("1.000000", tb.buf());
|
| +
|
| + js.Clear();
|
| + js.PrintValue("hello");
|
| + EXPECT_STREQ("\"hello\"", tb.buf());
|
| +}
|
| +
|
| +
|
| +TEST_CASE(JSONStream_Array) {
|
| + TextBuffer tb(256);
|
| + JSONStream js(&tb);
|
| + js.Clear();
|
| + js.OpenArray();
|
| + js.PrintValueBool(true);
|
| + js.PrintValueBool(false);
|
| + js.CloseArray();
|
| + EXPECT_STREQ("[true,false]", tb.buf());
|
| +}
|
| +
|
| +
|
| +TEST_CASE(JSONStream_Object) {
|
| + TextBuffer tb(256);
|
| + JSONStream js(&tb);
|
| + js.Clear();
|
| + js.OpenObject();
|
| + js.PrintProperty("key1", "a");
|
| + js.PrintProperty("key2", "b");
|
| + js.CloseObject();
|
| + EXPECT_STREQ("{\"key1\":\"a\",\"key2\":\"b\"}", tb.buf());
|
| +}
|
| +
|
| +
|
| } // namespace dart
|
|
|