Commit 8d536894 authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

(Pretty)Writer: drop restriction to object/array roots

parent 86245ce9
......@@ -174,7 +174,6 @@ protected:
level->valueCount++;
}
else {
RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root.
Base::hasRoot_ = true;
}
......
......@@ -321,7 +321,6 @@ protected:
level->valueCount++;
}
else {
RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root.
hasRoot_ = true;
}
......
......@@ -155,12 +155,12 @@ TEST(Writer, OStreamWrapper) {
EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", actual.c_str());
}
TEST(Writer, AssertRootMustBeArrayOrObject) {
TEST(Writer, AssertRootMayBeAnyValue) {
#define T(x)\
{\
StringBuffer buffer;\
Writer<StringBuffer> writer(buffer);\
ASSERT_THROW(x, AssertException);\
EXPECT_TRUE(x);\
}
T(writer.Bool(false));
T(writer.Bool(true));
......@@ -228,9 +228,23 @@ TEST(Writer, AssertObjectKeyNotString) {
TEST(Writer, AssertMultipleRoot) {
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
writer.StartObject();
writer.EndObject();
ASSERT_THROW(writer.StartObject(), AssertException);
writer.Reset(buffer);
writer.Null();
ASSERT_THROW(writer.Int(0), AssertException);
writer.Reset(buffer);
writer.String("foo");
ASSERT_THROW(writer.StartArray(), AssertException);
writer.Reset(buffer);
writer.StartArray();
writer.EndArray();
ASSERT_THROW(writer.Double(3.14), AssertException);
}
TEST(Writer, RootObjectIsComplete) {
......@@ -260,3 +274,24 @@ TEST(Writer, RootArrayIsComplete) {
writer.EndArray();
EXPECT_TRUE(writer.IsComplete());
}
TEST(Writer, RootValueIsComplete) {
#define T(x)\
{\
StringBuffer buffer;\
Writer<StringBuffer> writer(buffer);\
EXPECT_FALSE(writer.IsComplete()); \
x; \
EXPECT_TRUE(writer.IsComplete()); \
}
T(writer.Null());
T(writer.Bool(true));
T(writer.Bool(false));
T(writer.Int(0));
T(writer.Uint(0));
T(writer.Int64(0));
T(writer.Uint64(0));
T(writer.Double(0));
T(writer.String(""));
#undef T
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment