From 7b6b79e9fcbadd043c9e34f4bb16540d1411b115 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 4 Nov 2012 21:15:02 +0200 Subject: [PATCH] Add a test case for comments --- tests/parser.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/parser.cpp b/tests/parser.cpp index 32fc6a4..61e7bff 100644 --- a/tests/parser.cpp +++ b/tests/parser.cpp @@ -18,6 +18,7 @@ private: void arguments(); void substatements(); void empty(); + void comments(); void unterminated_comment(); void missing_semicolon(); void bad_string(); @@ -30,6 +31,7 @@ ParserTests::ParserTests() add(&ParserTests::arguments, "Arguments"); add(&ParserTests::substatements, "Substatements"); add(&ParserTests::empty, "Empty input"); + add(&ParserTests::comments, "Comments"); add(&ParserTests::unterminated_comment, "Unterminated comment").expect_throw(); add(&ParserTests::missing_semicolon, "Missing semicolon").expect_throw(); add(&ParserTests::bad_string, "Bad string").expect_throw(); @@ -100,6 +102,32 @@ void ParserTests::empty() EXPECT(!st.valid); } +void ParserTests::comments() +{ + static const char input[] = + "// line comment\n" + "a;\n" + "/* block\n" + "comment */\n" + "b;\n" + "/* block comment with embedded // double\n" + "slash */\n" + "c;\n" + "// line comment with embedded /* slash star\n" + "d;\n"; + + IO::Memory mem(input, sizeof(input)-1); + DataFile::Parser parser(mem, "-"); + DataFile::Statement st = parser.parse(); + EXPECT_EQUAL(st.keyword, "a"); + st = parser.parse(); + EXPECT_EQUAL(st.keyword, "b"); + st = parser.parse(); + EXPECT_EQUAL(st.keyword, "c"); + st = parser.parse(); + EXPECT_EQUAL(st.keyword, "d"); +} + void ParserTests::unterminated_comment() { static const char input[] = -- 2.45.2