Skip to content

Commit

Permalink
Merge pull request #1991 from hzeller/20230801-test-for-stray-zero
Browse files Browse the repository at this point in the history
Add a test to verify that the lexer can deal with stray NUL-chars.
  • Loading branch information
hzeller authored Aug 2, 2023
2 parents 1ad5326 + b55edf4 commit 58c5006
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions verilog/parser/verilog_lexer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2355,5 +2355,25 @@ TEST(RecursiveLexTextTest, Basic) {
TokenInfo(';', text.substr(5, 1))));
}

TEST(VerilogLexerTest, StrayNulCharacterHandledCorrectly) {
{ // baseline
FilteredVerilogLexer lexer(absl::string_view("foo bar baz", 11));
for (absl::string_view expected : {"foo", "bar", "baz"}) {
auto token = lexer.DoNextToken();
EXPECT_EQ(token.text(), expected);
EXPECT_EQ(token.token_enum(), SymbolIdentifier);
}
EXPECT_TRUE(lexer.DoNextToken().isEOF());
}
{ // Stray nul character in text should just be skipped as space
FilteredVerilogLexer lexer(absl::string_view("foo bar\0baz", 11));
for (absl::string_view expected : {"foo", "bar", "baz"}) {
auto token = lexer.DoNextToken();
EXPECT_EQ(token.text(), expected);
EXPECT_EQ(token.token_enum(), SymbolIdentifier);
}
EXPECT_TRUE(lexer.DoNextToken().isEOF());
}
}
} // namespace
} // namespace verilog

0 comments on commit 58c5006

Please sign in to comment.