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

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

Issue 420443003: GN foreach should mark the list identifier as used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/function_foreach.cc ('k') | tools/gn/functions_target.cc » ('j') | 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/test_with_scope.h" 6 #include "tools/gn/test_with_scope.h"
7 7
8 TEST(FunctionForeach, CollisionOnLoopVar) { 8 TEST(FunctionForeach, CollisionOnLoopVar) {
9 TestWithScope setup; 9 TestWithScope setup;
10 TestParseInput input( 10 TestParseInput input(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 TestParseInput input_bad( 44 TestParseInput input_bad(
45 "foreach(i, [1, 2, 3]) {\n" 45 "foreach(i, [1, 2, 3]) {\n"
46 " print(i)\n" 46 " print(i)\n"
47 "}\n" 47 "}\n"
48 "print(i)"); 48 "print(i)");
49 ASSERT_FALSE(input_bad.has_error()); // Should parse OK. 49 ASSERT_FALSE(input_bad.has_error()); // Should parse OK.
50 50
51 input_bad.parsed()->Execute(setup.scope(), &err); 51 input_bad.parsed()->Execute(setup.scope(), &err);
52 ASSERT_TRUE(err.has_error()); // Shouldn't actually run. 52 ASSERT_TRUE(err.has_error()); // Shouldn't actually run.
53 } 53 }
54
55 // Checks that the identifier used as the list is marked as "used".
56 TEST(FunctionForeach, MarksIdentAsUsed) {
57 TestWithScope setup;
58 TestParseInput input_good(
59 "a = [1, 2]\n"
60 "foreach(i, a) {\n"
61 " print(i)\n"
62 "}\n");
63 ASSERT_FALSE(input_good.has_error());
64
65 Err err;
66 input_good.parsed()->Execute(setup.scope(), &err);
67 ASSERT_FALSE(err.has_error()) << err.message();
68
69 EXPECT_EQ("1\n2\n", setup.print_output());
70 setup.print_output().clear();
71
72 // Check for unused vars.
73 EXPECT_TRUE(setup.scope()->CheckForUnusedVars(&err));
74 EXPECT_FALSE(err.has_error());
75 }
OLDNEW
« no previous file with comments | « tools/gn/function_foreach.cc ('k') | tools/gn/functions_target.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698