Commit d5218636 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2506] supported NUMBER in getNextToken() with expected type

parent f70d131f
......@@ -192,14 +192,26 @@ MasterLexer::getNextToken(Options options) {
return (impl_->token_);
}
const MasterToken&
MasterLexer::getNextToken(MasterToken::Type expect, bool eol_ok) {
Options options = NONE;
if (expect == MasterToken::QSTRING) {
options = options | QSTRING;
namespace {
inline MasterLexer::Options
optionsForTokenType(MasterToken::Type expect) {
switch (expect) {
case MasterToken::STRING:
return (MasterLexer::NONE);
case MasterToken::QSTRING:
return (MasterLexer::QSTRING);
case MasterToken::NUMBER:
return (MasterLexer::NUMBER);
default:
assert(false);
}
}
}
getNextToken(options); // the result should be set in impl_->token_
const MasterToken&
MasterLexer::getNextToken(MasterToken::Type expect, bool eol_ok) {
// the result should be set in impl_->token_
getNextToken(optionsForTokenType(expect));
const bool is_eol_like =
(impl_->token_.getType() == MasterToken::END_OF_LINE ||
......
......@@ -356,4 +356,25 @@ TEST_F(MasterLexerTest, getNextTokenQString) {
eofCheck(lexer, MasterToken::QSTRING);
}
TEST_F(MasterLexerTest, getNextTokenNumber) {
ss << "3600\n";
ss << "\n";
ss << "86400";
lexer.pushSource(ss);
// Expecting a number string and get one.
EXPECT_EQ(3600,
lexer.getNextToken(MasterToken::NUMBER).getNumber());
eolCheck(lexer, MasterToken::NUMBER);
// Skip the 2nd '\n'
EXPECT_EQ(MasterToken::END_OF_LINE, lexer.getNextToken().getType());
// Unless we specify NUMBER, decimal number string should be recognized
// as a string.
EXPECT_EQ("86400",
lexer.getNextToken(MasterToken::STRING).getString());
eofCheck(lexer, MasterToken::NUMBER);
}
}
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