Commit c8138641 authored by Milo Yip's avatar Milo Yip

Add kParseStopWhenDoneFlag, its implementation and related unit tests

parent c4ce48cd
This diff is collapsed.
...@@ -545,6 +545,38 @@ TEST(Reader, Parse_EmptyObject) { ...@@ -545,6 +545,38 @@ TEST(Reader, Parse_EmptyObject) {
EXPECT_EQ(2u, h.step_); 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('a', s.Peek());
}
TEST(Reader, Parse_MultipleRoot) {
TestMultipleRoot<kParseStopWhenDoneFlag>();
}
TEST(Reader, ParseIterative_MultipleRoot) {
TestMultipleRoot<kParseIterativeFlag | kParseStopWhenDoneFlag>();
}
#define TEST_ERROR(errorCode, str) \ #define TEST_ERROR(errorCode, str) \
{ \ { \
char buffer[1001]; \ char buffer[1001]; \
...@@ -932,18 +964,6 @@ TEST(Reader, IterativeParsing_ShortCircuit) { ...@@ -932,18 +964,6 @@ TEST(Reader, IterativeParsing_ShortCircuit) {
} }
} }
TEST(Reader, IterativeParsing_LimitStackSize) {
BaseReaderHandler<> handler;
Reader reader(20);
StringStream is("[[[]]]");
ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
EXPECT_TRUE(reader.HasParseError());
EXPECT_EQ(kParseErrorStackSizeLimitExceeded, r.Code());
EXPECT_EQ(2u, r.Offset());
}
#ifdef __GNUC__ #ifdef __GNUC__
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif
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