Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Unified Diff: tools/gn/parser_unittest.cc

Issue 588893006: gn: attach comments to parse tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x64 Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/parser.cc ('k') | tools/gn/scope_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/parser_unittest.cc
diff --git a/tools/gn/parser_unittest.cc b/tools/gn/parser_unittest.cc
index 1205038a8bccf7cf92b1c04c598ac5425cb48014..6f08c723eb1e88a6d97b83910dcd58fb87e39c3d 100644
--- a/tools/gn/parser_unittest.cc
+++ b/tools/gn/parser_unittest.cc
@@ -491,6 +491,104 @@ TEST(Parser, LongExpression) {
DoParserPrintTest(input, expected);
}
+TEST(Parser, CommentsStandalone) {
+ const char* input =
+ "# Toplevel comment.\n"
+ "\n"
+ "executable(\"wee\") {}\n";
+ 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);
}
« no previous file with comments | « tools/gn/parser.cc ('k') | tools/gn/scope_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698