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 "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 Loading... |
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 } |
OLD | NEW |