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

Side by Side Diff: tools/gn/parser_unittest.cc

Issue 1007963003: Fixes to {} handling in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « tools/gn/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « tools/gn/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698