Browse Source

[2372] covered a minor case of initial_ws after skipping a newline

JINMEI Tatuya 12 years ago
parent
commit
d4902d224c
2 changed files with 11 additions and 2 deletions
  1. 1 1
      src/lib/dns/master_lexer.cc
  2. 10 1
      src/lib/dns/tests/master_lexer_state_unittest.cc

+ 1 - 1
src/lib/dns/master_lexer.cc

@@ -218,8 +218,8 @@ Start::handle(MasterLexer& lexer, MasterLexer::Options& options) const {
             }
             continue;
         } else if (c == '\n') {
+            getLexerImpl(lexer)->last_was_eol_ = true;
             if ((options & MasterLexer::END_OF_LINE) != 0) {
-                getLexerImpl(lexer)->last_was_eol_ = true;
                 getLexerImpl(lexer)->token_ = Token(Token::END_OF_LINE);
                 return (NULL);
             }

+ 10 - 1
src/lib/dns/tests/master_lexer_state_unittest.cc

@@ -78,8 +78,17 @@ TEST_F(MasterLexerStateTest, startToEOL) {
     // The next lexer session will reach EOF.  Same eof check should pass.
     EXPECT_EQ(s_null, s_start.handle(lexer, options));
     eofCheck(s_start, lexer);
+}
 
-    // TBD: EOL after (
+TEST_F(MasterLexerStateTest, continuedInitialWS) {
+    // Unusual, probably impossible case in our expected usage.  We'll see
+    // an initial space after newline, but we didn't request recognizing
+    // the new line (so it'll be just skipped).
+    ss << "\n ";
+    options = MasterLexer::INITIAL_WS;
+    const State* state = State::getStartInstance(lexer, options);
+    EXPECT_EQ(s_null, state->handle(lexer, options));
+    EXPECT_EQ(Token::INITIAL_WS, s_start.getToken(lexer).getType());
 }
 
 TEST_F(MasterLexerStateTest, space) {