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