17 #include <gtest/gtest.h>
22 Lexer lexer(
"plain text $var $VaR ${x}\n");
27 EXPECT_EQ(
"[plain text ][$var][ ][$VaR][ ][$x]",
32 Lexer lexer(
"$ $$ab c$: $\ncde\n");
37 EXPECT_EQ(
"[ $ab c: cde]",
42 Lexer lexer(
"foo baR baz_123 foo-bar");
45 EXPECT_EQ(
"foo", ident);
47 EXPECT_EQ(
"baR", ident);
49 EXPECT_EQ(
"baz_123", ident);
51 EXPECT_EQ(
"foo-bar", ident);
57 Lexer lexer(
"foo.dots $bar.dots ${bar.dots}\n");
60 EXPECT_EQ(
"foo.dots", ident);
66 EXPECT_EQ(
"[$bar][.dots ][$bar.dots]",
71 Lexer lexer(
"foo$\nbad $");
75 EXPECT_EQ(
"input:2: bad $-escape (literal $ must be written as $$)\n"
91 Lexer lexer(
" \tfoobar");
TEST(Lexer, ReadVarValue)
Token ReadToken()
Read a Token from the Token enum.
string Serialize() const
Construct a human-readable representation of the parsed state, for use in tests.
string DescribeLastError()
If the last token read was an ERROR token, provide more info or the empty string. ...
bool ReadIdent(string *out)
Read a simple identifier (a rule or variable name).
bool ReadVarValue(EvalString *value, string *err)
Read the value side of a var = value line (complete with $escapes).
A tokenized string that contains variable references.
void Error(const char *msg,...)
Log an error message.