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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 TestParseInput input_unused( | 69 TestParseInput input_unused( |
70 "{\n" | 70 "{\n" |
71 " a = 12\n" | 71 " a = 12\n" |
72 " b = 13\n" | 72 " b = 13\n" |
73 " print(\"$a\")\n" | 73 " print(\"$a\")\n" |
74 "}"); | 74 "}"); |
75 EXPECT_FALSE(input_unused.has_error()); | 75 EXPECT_FALSE(input_unused.has_error()); |
76 | 76 |
77 input_unused.parsed()->Execute(setup.scope(), &err); | 77 input_unused.parsed()->Execute(setup.scope(), &err); |
78 EXPECT_TRUE(err.has_error()); | 78 EXPECT_TRUE(err.has_error()); |
| 79 |
| 80 // Also verify that the unused variable has the correct origin set. The |
| 81 // origin will point to the value assigned to the variable (in this case, the |
| 82 // "13" assigned to "b". |
| 83 EXPECT_EQ(3, err.location().line_number()); |
| 84 EXPECT_EQ(7, err.location().char_offset()); |
| 85 |
79 } | 86 } |
| 87 |
| 88 TEST(ParseTree, OriginForDereference) { |
| 89 TestWithScope setup; |
| 90 TestParseInput input( |
| 91 "a = 6\n" |
| 92 "get_target_outputs(a)"); |
| 93 EXPECT_FALSE(input.has_error()); |
| 94 |
| 95 Err err; |
| 96 input.parsed()->Execute(setup.scope(), &err); |
| 97 EXPECT_TRUE(err.has_error()); |
| 98 |
| 99 // The origin for the "not a string" error message should be where the value |
| 100 // was dereferenced (the "a" on the second line). |
| 101 EXPECT_EQ(2, err.location().line_number()); |
| 102 EXPECT_EQ(20, err.location().char_offset()); |
| 103 } |
OLD | NEW |