Commit 3038a785 authored by thebusytypist's avatar thebusytypist

Revise unittests: reset the handler before the transition which we are going to test.

parent 36434b66
...@@ -38,7 +38,7 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro ...@@ -38,7 +38,7 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
default: default:
return RAPIDJSON_ERROR_STRING("Unknown error."); return RAPIDJSON_ERROR_STRING("Unknown error.");
......
...@@ -82,7 +82,7 @@ enum ParseErrorCode { ...@@ -82,7 +82,7 @@ enum ParseErrorCode {
kParseErrorNumberMissFraction, //!< Miss fraction part in number. kParseErrorNumberMissFraction, //!< Miss fraction part in number.
kParseErrorNumberMissExponent, //!< Miss exponent in number. kParseErrorNumberMissExponent, //!< Miss exponent in number.
kParseErrorUnspecificSyntaxError //!< General syntax error. kParseErrorUnspecificSyntaxError //!< Unspecific syntax error.
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -735,20 +735,24 @@ template<typename Encoding = UTF8<> > ...@@ -735,20 +735,24 @@ template<typename Encoding = UTF8<> >
struct IterativeParsingReaderHandler { struct IterativeParsingReaderHandler {
typedef typename Encoding::Ch Ch; typedef typename Encoding::Ch Ch;
IterativeParsingReaderHandler() : IterativeParsingReaderHandler() {
IsNullTriggered(false), Reset();
IsBoolTriggered(false), }
IsIntTriggered(false),
IsUintTriggered(false), void Reset() {
IsInt64Triggered(false), IsNullTriggered = false;
IsUint64Triggered(false), IsBoolTriggered = false;
IsDoubleTriggered(false), IsIntTriggered = false;
IsStringTriggered(false), IsUintTriggered = false;
IsStartObjectTriggered(false), IsInt64Triggered = false;
IsEndObjectTriggered(false), IsUint64Triggered = false;
MemberCount(0), IsDoubleTriggered = false;
IsStartArrayTriggered(false), IsStringTriggered = false;
ElementCount(0) { IsStartObjectTriggered = false;
IsEndObjectTriggered = false;
MemberCount = 0;
IsStartArrayTriggered = false;
ElementCount = 0;
} }
bool IsNullTriggered; bool IsNullTriggered;
...@@ -838,6 +842,7 @@ TEST(Reader, IterativeParsing_StateTransition_ObjectInitial) { ...@@ -838,6 +842,7 @@ TEST(Reader, IterativeParsing_StateTransition_ObjectInitial) {
// ObjectInitial -> ObjectFinish -> Finish // ObjectInitial -> ObjectFinish -> Finish
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{}", 1); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{}", 1);
handler.Reset();
EXPECT_EQ(Reader::IterativeParsingObjectInitialState, state); EXPECT_EQ(Reader::IterativeParsingObjectInitialState, state);
Reader::IterativeParsingState d = reader.Transit<kParseIterativeFlag>( Reader::IterativeParsingState d = reader.Transit<kParseIterativeFlag>(
...@@ -855,6 +860,7 @@ TEST(Reader, IterativeParsing_StateTransition_ObjectInitial) { ...@@ -855,6 +860,7 @@ TEST(Reader, IterativeParsing_StateTransition_ObjectInitial) {
// ObjectInitial -> MemberKey // ObjectInitial -> MemberKey
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"key\": 1}", 1); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"key\": 1}", 1);
handler.Reset();
EXPECT_EQ(Reader::IterativeParsingObjectInitialState, state); EXPECT_EQ(Reader::IterativeParsingObjectInitialState, state);
Reader::IterativeParsingState d = reader.Transit<kParseIterativeFlag>( Reader::IterativeParsingState d = reader.Transit<kParseIterativeFlag>(
...@@ -962,6 +968,7 @@ TEST(Reader, IterativeParsing_StateTransition_MemberValue) { ...@@ -962,6 +968,7 @@ TEST(Reader, IterativeParsing_StateTransition_MemberValue) {
// MemberValue -> ObjectFinish // MemberValue -> ObjectFinish
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"k\": 123}", 9); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"k\": 123}", 9);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingMemberValueState, state); EXPECT_EQ(Reader::IterativeParsingMemberValueState, state);
...@@ -981,6 +988,7 @@ TEST(Reader, IterativeParsing_StateTransition_MemberValue) { ...@@ -981,6 +988,7 @@ TEST(Reader, IterativeParsing_StateTransition_MemberValue) {
// MemberValue -> MemberDelimiter // MemberValue -> MemberDelimiter
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"k\": 1, \"e\": 2}", 7); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"k\": 1, \"e\": 2}", 7);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingMemberValueState, state); EXPECT_EQ(Reader::IterativeParsingMemberValueState, state);
...@@ -999,6 +1007,7 @@ TEST(Reader, IterativeParsing_StateTransition_MemberValue) { ...@@ -999,6 +1007,7 @@ TEST(Reader, IterativeParsing_StateTransition_MemberValue) {
TEST(Reader, IterativeParsing_StateTransition_MemberDelimiter) { TEST(Reader, IterativeParsing_StateTransition_MemberDelimiter) {
// MemberDelimiter -> MemberKey // MemberDelimiter -> MemberKey
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"k\": 1, \"e\": 2}", 9); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("{\"k\": 1, \"e\": 2}", 9);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingMemberDelimiterState, state); EXPECT_EQ(Reader::IterativeParsingMemberDelimiterState, state);
...@@ -1027,6 +1036,7 @@ TEST(Reader, IterativeParsing_StateTransition_ArrayInitial) { ...@@ -1027,6 +1036,7 @@ TEST(Reader, IterativeParsing_StateTransition_ArrayInitial) {
// ArrayInitial -> ArrayFinish -> Finish // ArrayInitial -> ArrayFinish -> Finish
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[]", 1); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[]", 1);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingArrayInitialState, state); EXPECT_EQ(Reader::IterativeParsingArrayInitialState, state);
...@@ -1056,6 +1066,7 @@ TEST(Reader, IterativeParsing_StateTransition_ArrayInitial) { ...@@ -1056,6 +1066,7 @@ TEST(Reader, IterativeParsing_StateTransition_ArrayInitial) {
// ArrayInitial -> Element // ArrayInitial -> Element
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1]", 1); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1]", 1);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingArrayInitialState, state); EXPECT_EQ(Reader::IterativeParsingArrayInitialState, state);
...@@ -1075,6 +1086,7 @@ TEST(Reader, IterativeParsing_StateTransition_Element) { ...@@ -1075,6 +1086,7 @@ TEST(Reader, IterativeParsing_StateTransition_Element) {
// Element -> ArrayFinish -> Finish // Element -> ArrayFinish -> Finish
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1]", 2); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1]", 2);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingElementState, state); EXPECT_EQ(Reader::IterativeParsingElementState, state);
...@@ -1094,6 +1106,7 @@ TEST(Reader, IterativeParsing_StateTransition_Element) { ...@@ -1094,6 +1106,7 @@ TEST(Reader, IterativeParsing_StateTransition_Element) {
// Element -> ElementDelimiter // Element -> ElementDelimiter
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, 2]", 2); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, 2]", 2);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingElementState, state); EXPECT_EQ(Reader::IterativeParsingElementState, state);
...@@ -1113,6 +1126,7 @@ TEST(Reader, IterativeParsing_StateTransition_ElementDelimiter) { ...@@ -1113,6 +1126,7 @@ TEST(Reader, IterativeParsing_StateTransition_ElementDelimiter) {
// ElementDelimiter -> ArrayInitial // ElementDelimiter -> ArrayInitial
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, [1]]", 4); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, [1]]", 4);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingElementDelimiterState, state); EXPECT_EQ(Reader::IterativeParsingElementDelimiterState, state);
...@@ -1135,6 +1149,7 @@ TEST(Reader, IterativeParsing_StateTransition_ElementDelimiter) { ...@@ -1135,6 +1149,7 @@ TEST(Reader, IterativeParsing_StateTransition_ElementDelimiter) {
// ElementDelimiter -> ObjectInitial // ElementDelimiter -> ObjectInitial
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, [1]]", 4); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, [1]]", 4);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingElementDelimiterState, state); EXPECT_EQ(Reader::IterativeParsingElementDelimiterState, state);
...@@ -1157,6 +1172,7 @@ TEST(Reader, IterativeParsing_StateTransition_ElementDelimiter) { ...@@ -1157,6 +1172,7 @@ TEST(Reader, IterativeParsing_StateTransition_ElementDelimiter) {
// ElementDelimiter -> Element // ElementDelimiter -> Element
{ {
ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, 2]", 4); ITERATIVE_PARSING_PREPARE_STATE_UNTIL("[1, 2]", 4);
handler.Reset();
EXPECT_FALSE(reader.HasParseError()); EXPECT_FALSE(reader.HasParseError());
EXPECT_EQ(Reader::IterativeParsingElementDelimiterState, state); EXPECT_EQ(Reader::IterativeParsingElementDelimiterState, state);
......
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