OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/input_file.h" | 6 #include "tools/gn/input_file.h" |
7 #include "tools/gn/parse_tree.h" | 7 #include "tools/gn/parse_tree.h" |
8 #include "tools/gn/scope.h" | 8 #include "tools/gn/scope.h" |
9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 "}"); | 83 "}"); |
84 EXPECT_FALSE(input_unused.has_error()); | 84 EXPECT_FALSE(input_unused.has_error()); |
85 | 85 |
86 input_unused.parsed()->Execute(setup.scope(), &err); | 86 input_unused.parsed()->Execute(setup.scope(), &err); |
87 EXPECT_TRUE(err.has_error()); | 87 EXPECT_TRUE(err.has_error()); |
88 | 88 |
89 // Also verify that the unused variable has the correct origin set. The | 89 // Also verify that the unused variable has the correct origin set. The |
90 // origin will point to the value assigned to the variable (in this case, the | 90 // origin will point to the value assigned to the variable (in this case, the |
91 // "13" assigned to "b". | 91 // "13" assigned to "b". |
92 EXPECT_EQ(3, err.location().line_number()); | 92 EXPECT_EQ(3, err.location().line_number()); |
93 EXPECT_EQ(7, err.location().char_offset()); | 93 EXPECT_EQ(7, err.location().column_number()); |
94 } | 94 } |
95 | 95 |
96 TEST(ParseTree, OriginForDereference) { | 96 TEST(ParseTree, OriginForDereference) { |
97 TestWithScope setup; | 97 TestWithScope setup; |
98 TestParseInput input( | 98 TestParseInput input( |
99 "a = 6\n" | 99 "a = 6\n" |
100 "get_target_outputs(a)"); | 100 "get_target_outputs(a)"); |
101 EXPECT_FALSE(input.has_error()); | 101 EXPECT_FALSE(input.has_error()); |
102 | 102 |
103 Err err; | 103 Err err; |
104 input.parsed()->Execute(setup.scope(), &err); | 104 input.parsed()->Execute(setup.scope(), &err); |
105 EXPECT_TRUE(err.has_error()); | 105 EXPECT_TRUE(err.has_error()); |
106 | 106 |
107 // The origin for the "not a string" error message should be where the value | 107 // The origin for the "not a string" error message should be where the value |
108 // was dereferenced (the "a" on the second line). | 108 // was dereferenced (the "a" on the second line). |
109 EXPECT_EQ(2, err.location().line_number()); | 109 EXPECT_EQ(2, err.location().line_number()); |
110 EXPECT_EQ(20, err.location().char_offset()); | 110 EXPECT_EQ(20, err.location().column_number()); |
111 } | 111 } |
112 | 112 |
113 TEST(ParseTree, SortRangeExtraction) { | 113 TEST(ParseTree, SortRangeExtraction) { |
114 TestWithScope setup; | 114 TestWithScope setup; |
115 | 115 |
116 // Ranges are [begin, end). | 116 // Ranges are [begin, end). |
117 | 117 |
118 { | 118 { |
119 TestParseInput input( | 119 TestParseInput input( |
120 "sources = [\n" | 120 "sources = [\n" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 for (auto s : kBad) { | 241 for (auto s : kBad) { |
242 TestParseInput input(std::string("x = ") + s); | 242 TestParseInput input(std::string("x = ") + s); |
243 EXPECT_FALSE(input.has_error()); | 243 EXPECT_FALSE(input.has_error()); |
244 | 244 |
245 TestWithScope setup; | 245 TestWithScope setup; |
246 Err err; | 246 Err err; |
247 input.parsed()->Execute(setup.scope(), &err); | 247 input.parsed()->Execute(setup.scope(), &err); |
248 EXPECT_TRUE(err.has_error()); | 248 EXPECT_TRUE(err.has_error()); |
249 } | 249 } |
250 } | 250 } |
OLD | NEW |