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 "tools/gn/parse_tree.h" |
| 6 |
5 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
6 | 9 |
7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/input_file.h" | 11 #include "tools/gn/input_file.h" |
9 #include "tools/gn/parse_tree.h" | |
10 #include "tools/gn/scope.h" | 12 #include "tools/gn/scope.h" |
11 #include "tools/gn/test_with_scope.h" | 13 #include "tools/gn/test_with_scope.h" |
12 | 14 |
13 TEST(ParseTree, Accessor) { | 15 TEST(ParseTree, Accessor) { |
14 TestWithScope setup; | 16 TestWithScope setup; |
15 | 17 |
16 // Make a pretend parse node with proper tracking that we can blame for the | 18 // Make a pretend parse node with proper tracking that we can blame for the |
17 // given value. | 19 // given value. |
18 InputFile input_file(SourceFile("//foo")); | 20 InputFile input_file(SourceFile("//foo")); |
19 Token base_token(Location(&input_file, 1, 1, 1), Token::IDENTIFIER, "a"); | 21 Token base_token(Location(&input_file, 1, 1, 1), Token::IDENTIFIER, "a"); |
20 Token member_token(Location(&input_file, 1, 1, 1), Token::IDENTIFIER, "b"); | 22 Token member_token(Location(&input_file, 1, 1, 1), Token::IDENTIFIER, "b"); |
21 | 23 |
22 AccessorNode accessor; | 24 AccessorNode accessor; |
23 accessor.set_base(base_token); | 25 accessor.set_base(base_token); |
24 | 26 |
25 scoped_ptr<IdentifierNode> member_identifier( | 27 scoped_ptr<IdentifierNode> member_identifier( |
26 new IdentifierNode(member_token)); | 28 new IdentifierNode(member_token)); |
27 accessor.set_member(member_identifier.Pass()); | 29 accessor.set_member(std::move(member_identifier)); |
28 | 30 |
29 // The access should fail because a is not defined. | 31 // The access should fail because a is not defined. |
30 Err err; | 32 Err err; |
31 Value result = accessor.Execute(setup.scope(), &err); | 33 Value result = accessor.Execute(setup.scope(), &err); |
32 EXPECT_TRUE(err.has_error()); | 34 EXPECT_TRUE(err.has_error()); |
33 EXPECT_EQ(Value::NONE, result.type()); | 35 EXPECT_EQ(Value::NONE, result.type()); |
34 | 36 |
35 // Define a as a Scope. It should still fail because b isn't defined. | 37 // Define a as a Scope. It should still fail because b isn't defined. |
36 err = Err(); | 38 err = Err(); |
37 setup.scope()->SetValue( | 39 setup.scope()->SetValue( |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 for (auto s : kBad) { | 245 for (auto s : kBad) { |
244 TestParseInput input(std::string("x = ") + s); | 246 TestParseInput input(std::string("x = ") + s); |
245 EXPECT_FALSE(input.has_error()); | 247 EXPECT_FALSE(input.has_error()); |
246 | 248 |
247 TestWithScope setup; | 249 TestWithScope setup; |
248 Err err; | 250 Err err; |
249 input.parsed()->Execute(setup.scope(), &err); | 251 input.parsed()->Execute(setup.scope(), &err); |
250 EXPECT_TRUE(err.has_error()); | 252 EXPECT_TRUE(err.has_error()); |
251 } | 253 } |
252 } | 254 } |
OLD | NEW |