|
@@ -29,7 +29,8 @@ typedef MasterLexer::Token Token; // shortcut
|
|
|
class MasterLexerStateTest : public ::testing::Test {
|
|
|
protected:
|
|
|
MasterLexerStateTest() : s_start(State::getInstance(State::Start)),
|
|
|
- s_crlf(State::getInstance(State::CRLF))
|
|
|
+ s_crlf(State::getInstance(State::CRLF)),
|
|
|
+ options(MasterLexer::NONE)
|
|
|
{
|
|
|
lexer.open(ss);
|
|
|
}
|
|
@@ -37,6 +38,7 @@ protected:
|
|
|
const State& s_crlf;
|
|
|
MasterLexer lexer;
|
|
|
std::stringstream ss;
|
|
|
+ MasterLexer::Options options;
|
|
|
};
|
|
|
|
|
|
// Common check for the end-of-file condition.
|
|
@@ -52,21 +54,45 @@ eofCheck(const State& state, MasterLexer& lexer) {
|
|
|
TEST_F(MasterLexerStateTest, startAndEnd) {
|
|
|
// A simple case: the input is empty, so we begin with start and
|
|
|
// are immediately done.
|
|
|
- const State* s_next = s_start.handle(lexer);
|
|
|
+ const State* s_next = s_start.handle(lexer, options);
|
|
|
EXPECT_EQ(static_cast<const State*>(NULL), s_next);
|
|
|
eofCheck(s_start, lexer);
|
|
|
}
|
|
|
|
|
|
TEST_F(MasterLexerStateTest, startToEOL) {
|
|
|
ss << "\n";
|
|
|
- const State* s_next = s_start.handle(lexer);
|
|
|
+ const State* s_next = s_start.handle(lexer, options);
|
|
|
EXPECT_EQ(static_cast<const State*>(NULL), s_next);
|
|
|
EXPECT_TRUE(s_start.wasLastEOL(lexer));
|
|
|
EXPECT_EQ(Token::END_OF_LINE, s_start.getToken(lexer).getType());
|
|
|
|
|
|
// The next lexer session will reach EOF. Same eof check should pass.
|
|
|
- s_start.handle(lexer);
|
|
|
+ s_start.handle(lexer, options);
|
|
|
eofCheck(s_start, lexer);
|
|
|
}
|
|
|
|
|
|
+TEST_F(MasterLexerStateTest, space) {
|
|
|
+ // by default space characters and tabs will be ignored. We check this
|
|
|
+ // twice; at the second iteration, it's a white space at the beginning
|
|
|
+ // of line, but since we don't specify INITIAL_WS option, it's treated as
|
|
|
+ // normal space and ignored.
|
|
|
+ const State* s_next;
|
|
|
+ for (size_t i = 0; i < 2; ++i) {
|
|
|
+ ss << " \t\n";
|
|
|
+ s_next = s_start.handle(lexer, options);
|
|
|
+ EXPECT_EQ(static_cast<const State*>(NULL), s_next);
|
|
|
+ EXPECT_TRUE(s_start.wasLastEOL(lexer));
|
|
|
+ EXPECT_EQ(Token::END_OF_LINE, s_start.getToken(lexer).getType());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Now we specify the INITIAL_WS option. It will be recognized and the
|
|
|
+ // corresponding token will be returned.
|
|
|
+ ss << " ";
|
|
|
+ options = MasterLexer::INITIAL_WS;
|
|
|
+ s_next = s_start.handle(lexer, options);
|
|
|
+ EXPECT_EQ(static_cast<const State*>(NULL), s_next);
|
|
|
+ EXPECT_FALSE(s_start.wasLastEOL(lexer));
|
|
|
+ EXPECT_EQ(Token::INITIAL_WS, s_start.getToken(lexer).getType());
|
|
|
+}
|
|
|
+
|
|
|
}
|