OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iostream> | 5 #include <iostream> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "tools/gn/input_file.h" | 9 #include "tools/gn/input_file.h" |
10 #include "tools/gn/parser.h" | 10 #include "tools/gn/parser.h" |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 "BLOCK\n" | 626 "BLOCK\n" |
627 " BINARY(=)\n" | 627 " BINARY(=)\n" |
628 " IDENTIFIER(defines)\n" | 628 " IDENTIFIER(defines)\n" |
629 " LIST\n" | 629 " LIST\n" |
630 " LITERAL(\"WEE\")\n" | 630 " LITERAL(\"WEE\")\n" |
631 " +BEFORE_COMMENT(\"# Connected comment.\")\n" | 631 " +BEFORE_COMMENT(\"# Connected comment.\")\n" |
632 " LITERAL(\"BLORPY\")\n"; | 632 " LITERAL(\"BLORPY\")\n"; |
633 DoParserPrintTest(input, expected); | 633 DoParserPrintTest(input, expected); |
634 } | 634 } |
635 | 635 |
| 636 TEST(Parser, CommentsAtEndOfBlock) { |
| 637 const char* input = |
| 638 "if (is_win) {\n" |
| 639 " sources = [\"a.cc\"]\n" |
| 640 " # Some comment at end.\n" |
| 641 "}\n"; |
| 642 const char* expected = |
| 643 "BLOCK\n" |
| 644 " CONDITION\n" |
| 645 " IDENTIFIER(is_win)\n" |
| 646 " BLOCK\n" |
| 647 " BINARY(=)\n" |
| 648 " IDENTIFIER(sources)\n" |
| 649 " LIST\n" |
| 650 " LITERAL(\"a.cc\")\n" |
| 651 " END(})\n" |
| 652 " +BEFORE_COMMENT(\"# Some comment at end.\")\n"; |
| 653 DoParserPrintTest(input, expected); |
| 654 } |
| 655 |
| 656 // TODO(scottmg): I could be convinced this is incorrect. It's not clear to me |
| 657 // which thing this comment is intended to be attached to. |
| 658 TEST(Parser, CommentsEndOfBlockSingleLine) { |
| 659 const char* input = |
| 660 "defines = [ # EOL defines.\n" |
| 661 "]\n"; |
| 662 const char* expected = |
| 663 "BLOCK\n" |
| 664 " BINARY(=)\n" |
| 665 " IDENTIFIER(defines)\n" |
| 666 " +SUFFIX_COMMENT(\"# EOL defines.\")\n" |
| 667 " LIST\n"; |
| 668 DoParserPrintTest(input, expected); |
| 669 } |
| 670 |
636 TEST(Parser, HangingIf) { | 671 TEST(Parser, HangingIf) { |
637 DoParserErrorTest("if", 1, 1); | 672 DoParserErrorTest("if", 1, 1); |
638 } | 673 } |
639 | 674 |
640 TEST(Parser, NegatingList) { | 675 TEST(Parser, NegatingList) { |
641 DoParserErrorTest("executable(\"wee\") { sources =- [ \"foo.cc\" ] }", 1, 30); | 676 DoParserErrorTest("executable(\"wee\") { sources =- [ \"foo.cc\" ] }", 1, 30); |
642 } | 677 } |
OLD | NEW |