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 |
11 TEST(ParseTree, Accessor) { | 11 TEST(ParseTree, Accessor) { |
12 TestWithScope setup; | 12 TestWithScope setup; |
13 | 13 |
14 // Make a pretend parse node with proper tracking that we can blame for the | 14 // Make a pretend parse node with proper tracking that we can blame for the |
15 // given value. | 15 // given value. |
16 InputFile input_file(SourceFile("//foo")); | 16 InputFile input_file(SourceFile("//foo")); |
17 Token base_token(Location(&input_file, 1, 1), Token::IDENTIFIER, "a"); | 17 Token base_token(Location(&input_file, 1, 1, 1), Token::IDENTIFIER, "a"); |
18 Token member_token(Location(&input_file, 1, 1), Token::IDENTIFIER, "b"); | 18 Token member_token(Location(&input_file, 1, 1, 1), Token::IDENTIFIER, "b"); |
19 | 19 |
20 AccessorNode accessor; | 20 AccessorNode accessor; |
21 accessor.set_base(base_token); | 21 accessor.set_base(base_token); |
22 | 22 |
23 scoped_ptr<IdentifierNode> member_identifier( | 23 scoped_ptr<IdentifierNode> member_identifier( |
24 new IdentifierNode(member_token)); | 24 new IdentifierNode(member_token)); |
25 accessor.set_member(member_identifier.Pass()); | 25 accessor.set_member(member_identifier.Pass()); |
26 | 26 |
27 // The access should fail because a is not defined. | 27 // The access should fail because a is not defined. |
28 Err err; | 28 Err err; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 Err err; | 95 Err err; |
96 input.parsed()->Execute(setup.scope(), &err); | 96 input.parsed()->Execute(setup.scope(), &err); |
97 EXPECT_TRUE(err.has_error()); | 97 EXPECT_TRUE(err.has_error()); |
98 | 98 |
99 // The origin for the "not a string" error message should be where the value | 99 // The origin for the "not a string" error message should be where the value |
100 // was dereferenced (the "a" on the second line). | 100 // was dereferenced (the "a" on the second line). |
101 EXPECT_EQ(2, err.location().line_number()); | 101 EXPECT_EQ(2, err.location().line_number()); |
102 EXPECT_EQ(20, err.location().char_offset()); | 102 EXPECT_EQ(20, err.location().char_offset()); |
103 } | 103 } |
OLD | NEW |