| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 " LITERAL(\"asd.cc\")\n" | 356 " LITERAL(\"asd.cc\")\n" |
| 357 " LITERAL(\"foo.cc\")\n" | 357 " LITERAL(\"foo.cc\")\n" |
| 358 " BLOCK\n" | 358 " BLOCK\n" |
| 359 " BINARY(+=)\n" | 359 " BINARY(+=)\n" |
| 360 " IDENTIFIER(dependencies)\n" | 360 " IDENTIFIER(dependencies)\n" |
| 361 " LIST\n" | 361 " LIST\n" |
| 362 " LITERAL(\"bar.cc\")\n"; | 362 " LITERAL(\"bar.cc\")\n"; |
| 363 DoParserPrintTest(input, expected); | 363 DoParserPrintTest(input, expected); |
| 364 } | 364 } |
| 365 | 365 |
| 366 TEST(Parser, NestedBlocks) { | |
| 367 const char* input = "{cc_test(\"foo\") {{foo=1}\n{}}}"; | |
| 368 const char* expected = | |
| 369 "BLOCK\n" | |
| 370 " BLOCK\n" | |
| 371 " FUNCTION(cc_test)\n" | |
| 372 " LIST\n" | |
| 373 " LITERAL(\"foo\")\n" | |
| 374 " BLOCK\n" | |
| 375 " BLOCK\n" | |
| 376 " BINARY(=)\n" | |
| 377 " IDENTIFIER(foo)\n" | |
| 378 " LITERAL(1)\n" | |
| 379 " BLOCK\n"; | |
| 380 DoParserPrintTest(input, expected); | |
| 381 const char* input_with_newline = "{cc_test(\"foo\") {{foo=1}\n{}}}"; | |
| 382 DoParserPrintTest(input_with_newline, expected); | |
| 383 } | |
| 384 | |
| 385 TEST(Parser, UnterminatedBlock) { | 366 TEST(Parser, UnterminatedBlock) { |
| 386 DoParserErrorTest("stuff() {", 1, 9); | 367 DoParserErrorTest("stuff() {", 1, 9); |
| 387 } | 368 } |
| 388 | 369 |
| 389 TEST(Parser, BadlyTerminatedNumber) { | 370 TEST(Parser, BadlyTerminatedNumber) { |
| 390 DoParserErrorTest("1234z", 1, 5); | 371 DoParserErrorTest("1234z", 1, 5); |
| 391 } | 372 } |
| 392 | 373 |
| 393 TEST(Parser, NewlinesInUnusualPlaces) { | 374 TEST(Parser, NewlinesInUnusualPlaces) { |
| 394 DoParserPrintTest( | 375 DoParserPrintTest( |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 679 } |
| 699 | 680 |
| 700 TEST(Parser, ConditionNoBracesElseIf) { | 681 TEST(Parser, ConditionNoBracesElseIf) { |
| 701 DoParserErrorTest( | 682 DoParserErrorTest( |
| 702 "if (true) {\n" | 683 "if (true) {\n" |
| 703 " foreach(foo, []) {}\n" | 684 " foreach(foo, []) {}\n" |
| 704 "} else if (true)\n" | 685 "} else if (true)\n" |
| 705 " foreach(bar, []) {}\n", | 686 " foreach(bar, []) {}\n", |
| 706 4, 3); | 687 4, 3); |
| 707 } | 688 } |
| 689 |
| 690 // Disallow standalone {} for introducing new scopes. These are ambiguous with |
| 691 // target declarations (e.g. is: |
| 692 // foo("bar") {} |
| 693 // a function with an associated block, or a standalone function with a |
| 694 // freestanding block. |
| 695 TEST(Parser, StandaloneBlock) { |
| 696 DoParserErrorTest( |
| 697 "if (true) {\n" |
| 698 "}\n" |
| 699 "{\n" |
| 700 " assert(false)\n" |
| 701 "}\n", |
| 702 3, 1); |
| 703 } |
| OLD | NEW |