]> git.tdb.fi Git - libs/datafile.git/commitdiff
Add a test case for comments
authorMikko Rasa <tdb@tdb.fi>
Sun, 4 Nov 2012 19:15:02 +0000 (21:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 Nov 2012 19:15:02 +0000 (21:15 +0200)
tests/parser.cpp

index 32fc6a4ef0a234a69e282ecda3e569e96f428c3b..61e7bff424ef6bc5f01cedb40f396bb031fd7327 100644 (file)
@@ -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<DataFile::data_error>();
        add(&ParserTests::missing_semicolon, "Missing semicolon").expect_throw<DataFile::data_error>();
        add(&ParserTests::bad_string, "Bad string").expect_throw<DataFile::data_error>();
@@ -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[] =