From a4ffdc27ec77d2a30d713944aca5ae9e8d6d3257 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Mon, 9 Apr 2018 15:22:51 -0700 Subject: [PATCH] test methods at end of input --- rcl/test/rcl/test_lexer_lookahead.cpp | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rcl/test/rcl/test_lexer_lookahead.cpp b/rcl/test/rcl/test_lexer_lookahead.cpp index 694d7bd1e..51c509c96 100644 --- a/rcl/test/rcl/test_lexer_lookahead.cpp +++ b/rcl/test/rcl/test_lexer_lookahead.cpp @@ -108,6 +108,37 @@ TEST_F(CLASSNAME(TestLexerLookaheadFixture, RMW_IMPLEMENTATION), test_peek2) EXPECT_EQ(RCL_LEXEME_FORWARD_SLASH, lexeme2); } +TEST_F(CLASSNAME(TestLexerLookaheadFixture, RMW_IMPLEMENTATION), test_eof) +{ + rcl_ret_t ret; + rcl_lexer_lookahead2_t buffer; + SCOPE_LOOKAHEAD2(buffer, ""); + + { + rcl_lexeme_t lexeme = RCL_LEXEME_NONE; + ret = rcl_lexer_lookahead2_peek(&buffer, &lexeme); + EXPECT_EQ(RCL_RET_OK, ret); + EXPECT_EQ(RCL_LEXEME_EOF, lexeme); + } + { + rcl_lexeme_t lexeme1 = RCL_LEXEME_NONE; + rcl_lexeme_t lexeme2 = RCL_LEXEME_NONE; + ret = rcl_lexer_lookahead2_peek2(&buffer, &lexeme1, &lexeme2); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); + EXPECT_EQ(RCL_LEXEME_EOF, lexeme1); + EXPECT_EQ(RCL_LEXEME_EOF, lexeme2); + } + // Accepting keeps the lexer at EOF + { + EXPECT_EQ(RCL_RET_OK, rcl_lexer_lookahead2_accept(&buffer, NULL, NULL)); + rcl_lexeme_t lexeme = RCL_LEXEME_NONE; + ret = rcl_lexer_lookahead2_peek(&buffer, &lexeme); + EXPECT_EQ(RCL_RET_OK, ret); + EXPECT_EQ(RCL_LEXEME_EOF, lexeme); + } +} + + TEST_F(CLASSNAME(TestLexerLookaheadFixture, RMW_IMPLEMENTATION), test_accept) { rcl_ret_t ret;