Chromium Code Reviews| Index: tools/gn/parser_unittest.cc |
| diff --git a/tools/gn/parser_unittest.cc b/tools/gn/parser_unittest.cc |
| index 1205038a8bccf7cf92b1c04c598ac5425cb48014..a984e8481c349fcd0fba13889498762aec822c3c 100644 |
| --- a/tools/gn/parser_unittest.cc |
| +++ b/tools/gn/parser_unittest.cc |
| @@ -491,6 +491,98 @@ TEST(Parser, LongExpression) { |
| DoParserPrintTest(input, expected); |
| } |
| +TEST(Parser, CommentsStandalone) { |
| + const char* input = "# Toplevel comment.\n\nexecutable(\"wee\") {}\n"; |
|
brettw
2014/09/23 21:33:15
Can you format your inputs on separate lines
"#
scottmg
2014/09/23 22:15:37
Done.
|
| + const char* expected = |
| + "BLOCK\n" |
| + " +BEFORE_COMMENT(\"# Toplevel comment.\")\n" |
| + " FUNCTION(executable)\n" |
| + " LIST\n" |
| + " LITERAL(\"wee\")\n" |
| + " BLOCK\n"; |
| + DoParserPrintTest(input, expected); |
| +} |
| + |
| +TEST(Parser, CommentsStandaloneEof) { |
| + const char* input = "executable(\"wee\") {}\n# EOF comment.\n"; |
| + const char* expected = |
| + "BLOCK\n" |
| + " +AFTER_COMMENT(\"# EOF comment.\")\n" |
| + " FUNCTION(executable)\n" |
| + " LIST\n" |
| + " LITERAL(\"wee\")\n" |
| + " BLOCK\n"; |
| + DoParserPrintTest(input, expected); |
| +} |
| + |
| +TEST(Parser, CommentsLineAttached) { |
| + const char* input = |
| + "executable(\"wee\") {\n" |
| + " # Some sources.\n" |
| + " sources = [\n" |
| + " \"stuff.cc\",\n" |
| + " \"things.cc\",\n" |
| + " # This file is special or something.\n" |
| + " \"another.cc\",\n" |
| + " ]\n" |
| + "}\n"; |
| + const char* expected = |
| + "BLOCK\n" |
| + " FUNCTION(executable)\n" |
| + " LIST\n" |
| + " LITERAL(\"wee\")\n" |
| + " BLOCK\n" |
| + " BINARY(=)\n" |
| + " +BEFORE_COMMENT(\"# Some sources.\")\n" |
| + " IDENTIFIER(sources)\n" |
| + " LIST\n" |
| + " LITERAL(\"stuff.cc\")\n" |
| + " LITERAL(\"things.cc\")\n" |
| + " LITERAL(\"another.cc\")\n" |
| + " +BEFORE_COMMENT(\"# This file is special or something.\")\n"; |
| + DoParserPrintTest(input, expected); |
| +} |
| + |
| +TEST(Parser, CommentsSuffix) { |
| + const char* input = "executable(\"wee\") { # This is some stuff.\n" |
| + "sources = [ \"a.cc\" # And another comment here.\n" |
| + "] }"; |
| + const char* expected = |
| + "BLOCK\n" |
| + " FUNCTION(executable)\n" |
| + " LIST\n" |
| + " LITERAL(\"wee\")\n" |
| + " +SUFFIX_COMMENT(\"# This is some stuff.\")\n" |
| + " BLOCK\n" |
| + " BINARY(=)\n" |
| + " IDENTIFIER(sources)\n" |
| + " LIST\n" |
| + " LITERAL(\"a.cc\")\n" |
| + " +SUFFIX_COMMENT(\"# And another comment here.\")\n"; |
| + DoParserPrintTest(input, expected); |
| +} |
| + |
| +TEST(Parser, CommentsSuffixDifferentLine) { |
| + const char* input = |
| + "executable(\"wee\") {\n" |
| + " sources = [ \"a\",\n" |
| + " \"b\" ] # Comment\n" |
| + "}\n"; |
| + const char* expected = |
| + "BLOCK\n" |
| + " FUNCTION(executable)\n" |
| + " LIST\n" |
| + " LITERAL(\"wee\")\n" |
| + " BLOCK\n" |
| + " BINARY(=)\n" |
| + " IDENTIFIER(sources)\n" |
| + " LIST\n" |
| + " LITERAL(\"a\")\n" |
| + " LITERAL(\"b\")\n" |
| + " +SUFFIX_COMMENT(\"# Comment\")\n"; |
| + DoParserPrintTest(input, expected); |
| +} |
| + |
| TEST(Parser, HangingIf) { |
| DoParserErrorTest("if", 1, 1); |
| } |