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" | 5 #include "tools/gn/parse_tree.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "tools/gn/input_file.h" | 11 #include "tools/gn/input_file.h" |
12 #include "tools/gn/scope.h" | 12 #include "tools/gn/scope.h" |
13 #include "tools/gn/test_with_scope.h" | 13 #include "tools/gn/test_with_scope.h" |
14 | 14 |
15 TEST(ParseTree, Accessor) { | 15 TEST(ParseTree, Accessor) { |
16 TestWithScope setup; | 16 TestWithScope setup; |
17 | 17 |
18 // 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 |
19 // given value. | 19 // given value. |
20 InputFile input_file(SourceFile("//foo")); | 20 InputFile input_file(SourceFile("//foo")); |
21 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"); |
22 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"); |
23 | 23 |
24 AccessorNode accessor; | 24 AccessorNode accessor; |
25 accessor.set_base(base_token); | 25 accessor.set_base(base_token); |
26 | 26 |
27 scoped_ptr<IdentifierNode> member_identifier( | 27 std::unique_ptr<IdentifierNode> member_identifier( |
28 new IdentifierNode(member_token)); | 28 new IdentifierNode(member_token)); |
29 accessor.set_member(std::move(member_identifier)); | 29 accessor.set_member(std::move(member_identifier)); |
30 | 30 |
31 // The access should fail because a is not defined. | 31 // The access should fail because a is not defined. |
32 Err err; | 32 Err err; |
33 Value result = accessor.Execute(setup.scope(), &err); | 33 Value result = accessor.Execute(setup.scope(), &err); |
34 EXPECT_TRUE(err.has_error()); | 34 EXPECT_TRUE(err.has_error()); |
35 EXPECT_EQ(Value::NONE, result.type()); | 35 EXPECT_EQ(Value::NONE, result.type()); |
36 | 36 |
37 // 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. |
38 err = Err(); | 38 err = Err(); |
39 setup.scope()->SetValue( | 39 setup.scope()->SetValue( |
40 "a", Value(nullptr, scoped_ptr<Scope>(new Scope(setup.scope()))), | 40 "a", Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.scope()))), |
41 nullptr); | 41 nullptr); |
42 result = accessor.Execute(setup.scope(), &err); | 42 result = accessor.Execute(setup.scope(), &err); |
43 EXPECT_TRUE(err.has_error()); | 43 EXPECT_TRUE(err.has_error()); |
44 EXPECT_EQ(Value::NONE, result.type()); | 44 EXPECT_EQ(Value::NONE, result.type()); |
45 | 45 |
46 // Define b, accessor should succeed now. | 46 // Define b, accessor should succeed now. |
47 const int64_t kBValue = 42; | 47 const int64_t kBValue = 42; |
48 err = Err(); | 48 err = Err(); |
49 setup.scope() | 49 setup.scope() |
50 ->GetMutableValue("a", false) | 50 ->GetMutableValue("a", false) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 for (auto s : kBad) { | 245 for (auto s : kBad) { |
246 TestParseInput input(std::string("x = ") + s); | 246 TestParseInput input(std::string("x = ") + s); |
247 EXPECT_FALSE(input.has_error()); | 247 EXPECT_FALSE(input.has_error()); |
248 | 248 |
249 TestWithScope setup; | 249 TestWithScope setup; |
250 Err err; | 250 Err err; |
251 input.parsed()->Execute(setup.scope(), &err); | 251 input.parsed()->Execute(setup.scope(), &err); |
252 EXPECT_TRUE(err.has_error()); | 252 EXPECT_TRUE(err.has_error()); |
253 } | 253 } |
254 } | 254 } |
OLD | NEW |