From: Mikko Rasa Date: Sun, 4 Nov 2012 19:15:02 +0000 (+0200) Subject: Add a test case for comments X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7b6b79e9fcbadd043c9e34f4bb16540d1411b115;p=libs%2Fdatafile.git Add a test case for comments --- 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[] =