mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-10-28 19:52:02 +01:00
Add kParseStopWhenDoneFlag, its implementation and related unit tests
This commit is contained in:
@@ -545,6 +545,38 @@ 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('a', s.Peek());
|
||||
}
|
||||
|
||||
TEST(Reader, Parse_MultipleRoot) {
|
||||
TestMultipleRoot<kParseStopWhenDoneFlag>();
|
||||
}
|
||||
|
||||
TEST(Reader, ParseIterative_MultipleRoot) {
|
||||
TestMultipleRoot<kParseIterativeFlag | kParseStopWhenDoneFlag>();
|
||||
}
|
||||
|
||||
#define TEST_ERROR(errorCode, str) \
|
||||
{ \
|
||||
char buffer[1001]; \
|
||||
@@ -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__
|
||||
RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user