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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 " BINARY(||)\n" | 484 " BINARY(||)\n" |
485 " BINARY(&&)\n" | 485 " BINARY(&&)\n" |
486 " BINARY(+)\n" | 486 " BINARY(+)\n" |
487 " IDENTIFIER(b)\n" | 487 " IDENTIFIER(b)\n" |
488 " IDENTIFIER(c)\n" | 488 " IDENTIFIER(c)\n" |
489 " IDENTIFIER(d)\n" | 489 " IDENTIFIER(d)\n" |
490 " IDENTIFIER(e)\n"; | 490 " IDENTIFIER(e)\n"; |
491 DoParserPrintTest(input, expected); | 491 DoParserPrintTest(input, expected); |
492 } | 492 } |
493 | 493 |
| 494 TEST(Parser, CommentsStandalone) { |
| 495 const char* input = |
| 496 "# Toplevel comment.\n" |
| 497 "\n" |
| 498 "executable(\"wee\") {}\n"; |
| 499 const char* expected = |
| 500 "BLOCK\n" |
| 501 " +BEFORE_COMMENT(\"# Toplevel comment.\")\n" |
| 502 " FUNCTION(executable)\n" |
| 503 " LIST\n" |
| 504 " LITERAL(\"wee\")\n" |
| 505 " BLOCK\n"; |
| 506 DoParserPrintTest(input, expected); |
| 507 } |
| 508 |
| 509 TEST(Parser, CommentsStandaloneEof) { |
| 510 const char* input = |
| 511 "executable(\"wee\") {}\n" |
| 512 "# EOF comment.\n"; |
| 513 const char* expected = |
| 514 "BLOCK\n" |
| 515 " +AFTER_COMMENT(\"# EOF comment.\")\n" |
| 516 " FUNCTION(executable)\n" |
| 517 " LIST\n" |
| 518 " LITERAL(\"wee\")\n" |
| 519 " BLOCK\n"; |
| 520 DoParserPrintTest(input, expected); |
| 521 } |
| 522 |
| 523 TEST(Parser, CommentsLineAttached) { |
| 524 const char* input = |
| 525 "executable(\"wee\") {\n" |
| 526 " # Some sources.\n" |
| 527 " sources = [\n" |
| 528 " \"stuff.cc\",\n" |
| 529 " \"things.cc\",\n" |
| 530 " # This file is special or something.\n" |
| 531 " \"another.cc\",\n" |
| 532 " ]\n" |
| 533 "}\n"; |
| 534 const char* expected = |
| 535 "BLOCK\n" |
| 536 " FUNCTION(executable)\n" |
| 537 " LIST\n" |
| 538 " LITERAL(\"wee\")\n" |
| 539 " BLOCK\n" |
| 540 " BINARY(=)\n" |
| 541 " +BEFORE_COMMENT(\"# Some sources.\")\n" |
| 542 " IDENTIFIER(sources)\n" |
| 543 " LIST\n" |
| 544 " LITERAL(\"stuff.cc\")\n" |
| 545 " LITERAL(\"things.cc\")\n" |
| 546 " LITERAL(\"another.cc\")\n" |
| 547 " +BEFORE_COMMENT(\"# This file is special or something.\")\n"; |
| 548 DoParserPrintTest(input, expected); |
| 549 } |
| 550 |
| 551 TEST(Parser, CommentsSuffix) { |
| 552 const char* input = |
| 553 "executable(\"wee\") { # This is some stuff.\n" |
| 554 "sources = [ \"a.cc\" # And another comment here.\n" |
| 555 "] }"; |
| 556 const char* expected = |
| 557 "BLOCK\n" |
| 558 " FUNCTION(executable)\n" |
| 559 " LIST\n" |
| 560 " LITERAL(\"wee\")\n" |
| 561 " +SUFFIX_COMMENT(\"# This is some stuff.\")\n" |
| 562 " BLOCK\n" |
| 563 " BINARY(=)\n" |
| 564 " IDENTIFIER(sources)\n" |
| 565 " LIST\n" |
| 566 " LITERAL(\"a.cc\")\n" |
| 567 " +SUFFIX_COMMENT(\"# And another comment here.\")\n"; |
| 568 DoParserPrintTest(input, expected); |
| 569 } |
| 570 |
| 571 TEST(Parser, CommentsSuffixDifferentLine) { |
| 572 const char* input = |
| 573 "executable(\"wee\") {\n" |
| 574 " sources = [ \"a\",\n" |
| 575 " \"b\" ] # Comment\n" |
| 576 "}\n"; |
| 577 const char* expected = |
| 578 "BLOCK\n" |
| 579 " FUNCTION(executable)\n" |
| 580 " LIST\n" |
| 581 " LITERAL(\"wee\")\n" |
| 582 " BLOCK\n" |
| 583 " BINARY(=)\n" |
| 584 " IDENTIFIER(sources)\n" |
| 585 " LIST\n" |
| 586 " LITERAL(\"a\")\n" |
| 587 " LITERAL(\"b\")\n" |
| 588 " +SUFFIX_COMMENT(\"# Comment\")\n"; |
| 589 DoParserPrintTest(input, expected); |
| 590 } |
| 591 |
494 TEST(Parser, HangingIf) { | 592 TEST(Parser, HangingIf) { |
495 DoParserErrorTest("if", 1, 1); | 593 DoParserErrorTest("if", 1, 1); |
496 } | 594 } |
497 | 595 |
498 TEST(Parser, NegatingList) { | 596 TEST(Parser, NegatingList) { |
499 DoParserErrorTest("executable(\"wee\") { sources =- [ \"foo.cc\" ] }", 1, 30); | 597 DoParserErrorTest("executable(\"wee\") { sources =- [ \"foo.cc\" ] }", 1, 30); |
500 } | 598 } |
OLD | NEW |