diff options
author | Milo Yip <miloyip@gmail.com> | 2014-07-28 14:45:06 +0400 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2014-07-28 14:45:06 +0400 |
commit | e6f344637b3163e74f0f1bd5f94d5595ed36d9d1 (patch) | |
tree | ae5e21fe32ef88a63461cb53dafd486604082139 /test | |
parent | c5458953687d5390cd4084eb2051eb373187565f (diff) | |
parent | 3d106085c102739a23cfd73a6e2797bebacfd791 (diff) |
Merge pull request #83 from miloyip/issue75stopwhendone
Issue75stopwhendone
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest/readertest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index d6dd4c4c..61bc38c8 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -545,6 +545,39 @@ TEST(Reader, Parse_EmptyObject) { EXPECT_EQ(2u, h.step_);
}
+struct ParseMultipleRootHandler : BaseReaderHandler<> {
+ ParseMultipleRootHandler() : step_(0) {}
+
+ bool Default() { ADD_FAILURE(); return false; }
+ bool StartObject() { EXPECT_EQ(0u, step_); step_++; return true; }
+ bool EndObject(SizeType) { EXPECT_EQ(1u, step_); step_++; return true; }
+ bool StartArray() { EXPECT_EQ(2u, step_); step_++; return true; }
+ bool EndArray(SizeType) { EXPECT_EQ(3u, step_); step_++; return true; }
+
+ unsigned step_;
+};
+
+template <unsigned parseFlags>
+void TestMultipleRoot() {
+ StringStream s("{}[] a");
+ ParseMultipleRootHandler h;
+ Reader reader;
+ EXPECT_TRUE(reader.Parse<parseFlags>(s, h));
+ EXPECT_EQ(2u, h.step_);
+ EXPECT_TRUE(reader.Parse<parseFlags>(s, h));
+ EXPECT_EQ(4u, h.step_);
+ EXPECT_EQ(' ', s.Take());
+ EXPECT_EQ('a', s.Take());
+}
+
+TEST(Reader, Parse_MultipleRoot) {
+ TestMultipleRoot<kParseStopWhenDoneFlag>();
+}
+
+TEST(Reader, ParseIterative_MultipleRoot) {
+ TestMultipleRoot<kParseIterativeFlag | kParseStopWhenDoneFlag>();
+}
+
#define TEST_ERROR(errorCode, str) \
{ \
char buffer[1001]; \
|