Skip to content

Commit

Permalink
tests: print string instead of int for Lexer::Token
Browse files Browse the repository at this point in the history
Add wrapper for Lexer::Token printing, to have string value reported
instead of numeric value, that gives "newline" instead of "8" in test
results.
Original line numbers are kept in error messages as they were before.
  • Loading branch information
pkitszel committed Mar 18, 2024
1 parent ab510c7 commit 6e6b482
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lexer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@

using namespace std;

string tok(Lexer::Token t) {
const char *str = Lexer::TokenName(t);
if (!str)
return "TokenOutOfRange: " + to_string(t);
return str;
}

#define EXPECT_EQ_TOK(t1, t2) \
EXPECT_EQ(tok(t1), tok(t2))

TEST(Lexer, ReadVarValue) {
Lexer lexer("plain text $var $VaR ${x}\n");
EvalString eval;
Expand Down Expand Up @@ -83,8 +93,7 @@ TEST(Lexer, CommentEOF) {
// Verify we don't run off the end of the string when the EOF is
// mid-comment.
Lexer lexer("# foo");
Lexer::Token token = lexer.ReadToken();
EXPECT_EQ(Lexer::ERROR, token);
EXPECT_EQ_TOK(Lexer::ERROR, lexer.ReadToken());
}

TEST(Lexer, Tabs) {
Expand Down

0 comments on commit 6e6b482

Please sign in to comment.