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/functions.h" | 5 #include "tools/gn/functions.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 std::unique_ptr<ParseNode>(new IdentifierNode(defined_token))); | 41 std::unique_ptr<ParseNode>(new IdentifierNode(defined_token))); |
42 result = functions::RunDefined(setup.scope(), &function_call, | 42 result = functions::RunDefined(setup.scope(), &function_call, |
43 &args_list_identifier_defined, &err); | 43 &args_list_identifier_defined, &err); |
44 ASSERT_EQ(Value::BOOLEAN, result.type()); | 44 ASSERT_EQ(Value::BOOLEAN, result.type()); |
45 EXPECT_TRUE(result.boolean_value()); | 45 EXPECT_TRUE(result.boolean_value()); |
46 | 46 |
47 // Should also work by passing an accessor node so you can do | 47 // Should also work by passing an accessor node so you can do |
48 // "defined(def.foo)" to see if foo is defined on the def scope. | 48 // "defined(def.foo)" to see if foo is defined on the def scope. |
49 std::unique_ptr<AccessorNode> undef_accessor(new AccessorNode); | 49 std::unique_ptr<AccessorNode> undef_accessor(new AccessorNode); |
50 undef_accessor->set_base(defined_token); | 50 undef_accessor->set_base(defined_token); |
51 undef_accessor->set_member( | 51 undef_accessor->set_member(base::MakeUnique<IdentifierNode>(undefined_token)); |
52 base::WrapUnique(new IdentifierNode(undefined_token))); | |
53 ListNode args_list_accessor_defined; | 52 ListNode args_list_accessor_defined; |
54 args_list_accessor_defined.append_item(std::move(undef_accessor)); | 53 args_list_accessor_defined.append_item(std::move(undef_accessor)); |
55 result = functions::RunDefined(setup.scope(), &function_call, | 54 result = functions::RunDefined(setup.scope(), &function_call, |
56 &args_list_accessor_defined, &err); | 55 &args_list_accessor_defined, &err); |
57 ASSERT_EQ(Value::BOOLEAN, result.type()); | 56 ASSERT_EQ(Value::BOOLEAN, result.type()); |
58 EXPECT_FALSE(result.boolean_value()); | 57 EXPECT_FALSE(result.boolean_value()); |
59 } | 58 } |
60 | 59 |
61 // Tests that an error is thrown when a {} is supplied to a function that | 60 // Tests that an error is thrown when a {} is supplied to a function that |
62 // doesn't take one. | 61 // doesn't take one. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 input.parsed()->Execute(setup.scope(), &err); | 118 input.parsed()->Execute(setup.scope(), &err); |
120 ASSERT_FALSE(err.has_error()) << err.message(); | 119 ASSERT_FALSE(err.has_error()) << err.message(); |
121 | 120 |
122 EXPECT_EQ( | 121 EXPECT_EQ( |
123 "empty = [[]] [[], [], []]\n" | 122 "empty = [[]] [[], [], []]\n" |
124 "one = [[1]] [[1], []]\n" | 123 "one = [[1]] [[1], []]\n" |
125 "many = [[1, 2, 3, 4, 5], [6, 7, 8, 9]]\n" | 124 "many = [[1, 2, 3, 4, 5], [6, 7, 8, 9]]\n" |
126 "rounding = [[1, 2], [3, 4], [5], [6]]\n", | 125 "rounding = [[1, 2], [3, 4], [5], [6]]\n", |
127 setup.print_output()); | 126 setup.print_output()); |
128 } | 127 } |
OLD | NEW |