Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: tools/gn/functions_unittest.cc

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "tools/gn/parse_tree.h" 10 #include "tools/gn/parse_tree.h"
11 #include "tools/gn/test_with_scope.h" 11 #include "tools/gn/test_with_scope.h"
12 #include "tools/gn/value.h" 12 #include "tools/gn/value.h"
13 13
14 TEST(Functions, Defined) { 14 TEST(Functions, Defined) {
15 TestWithScope setup; 15 TestWithScope setup;
16 16
17 FunctionCallNode function_call; 17 FunctionCallNode function_call;
18 Err err; 18 Err err;
19 19
20 // Test an undefined identifier. 20 // Test an undefined identifier.
21 Token undefined_token(Location(), Token::IDENTIFIER, "undef"); 21 Token undefined_token(Location(), Token::IDENTIFIER, "undef");
22 ListNode args_list_identifier_undefined; 22 ListNode args_list_identifier_undefined;
23 args_list_identifier_undefined.append_item( 23 args_list_identifier_undefined.append_item(
24 scoped_ptr<ParseNode>(new IdentifierNode(undefined_token))); 24 std::unique_ptr<ParseNode>(new IdentifierNode(undefined_token)));
25 Value result = functions::RunDefined(setup.scope(), &function_call, 25 Value result = functions::RunDefined(setup.scope(), &function_call,
26 &args_list_identifier_undefined, &err); 26 &args_list_identifier_undefined, &err);
27 ASSERT_EQ(Value::BOOLEAN, result.type()); 27 ASSERT_EQ(Value::BOOLEAN, result.type());
28 EXPECT_FALSE(result.boolean_value()); 28 EXPECT_FALSE(result.boolean_value());
29 29
30 // Define a value that's itself a scope value. 30 // Define a value that's itself a scope value.
31 const char kDef[] = "def"; // Defined variable name. 31 const char kDef[] = "def"; // Defined variable name.
32 setup.scope()->SetValue( 32 setup.scope()->SetValue(
33 kDef, Value(nullptr, scoped_ptr<Scope>(new Scope(setup.scope()))), 33 kDef, Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.scope()))),
34 nullptr); 34 nullptr);
35 35
36 // Test the defined identifier. 36 // Test the defined identifier.
37 Token defined_token(Location(), Token::IDENTIFIER, kDef); 37 Token defined_token(Location(), Token::IDENTIFIER, kDef);
38 ListNode args_list_identifier_defined; 38 ListNode args_list_identifier_defined;
39 args_list_identifier_defined.append_item( 39 args_list_identifier_defined.append_item(
40 scoped_ptr<ParseNode>(new IdentifierNode(defined_token))); 40 std::unique_ptr<ParseNode>(new IdentifierNode(defined_token)));
41 result = functions::RunDefined(setup.scope(), &function_call, 41 result = functions::RunDefined(setup.scope(), &function_call,
42 &args_list_identifier_defined, &err); 42 &args_list_identifier_defined, &err);
43 ASSERT_EQ(Value::BOOLEAN, result.type()); 43 ASSERT_EQ(Value::BOOLEAN, result.type());
44 EXPECT_TRUE(result.boolean_value()); 44 EXPECT_TRUE(result.boolean_value());
45 45
46 // Should also work by passing an accessor node so you can do 46 // Should also work by passing an accessor node so you can do
47 // "defined(def.foo)" to see if foo is defined on the def scope. 47 // "defined(def.foo)" to see if foo is defined on the def scope.
48 scoped_ptr<AccessorNode> undef_accessor(new AccessorNode); 48 std::unique_ptr<AccessorNode> undef_accessor(new AccessorNode);
49 undef_accessor->set_base(defined_token); 49 undef_accessor->set_base(defined_token);
50 undef_accessor->set_member(scoped_ptr<IdentifierNode>( 50 undef_accessor->set_member(
51 new IdentifierNode(undefined_token))); 51 std::unique_ptr<IdentifierNode>(new IdentifierNode(undefined_token)));
vmpstr 2016/04/06 21:12:29 This can be WrapUnique, but this is fine as well.
dcheng 2016/04/06 21:26:32 Done.
52 ListNode args_list_accessor_defined; 52 ListNode args_list_accessor_defined;
53 args_list_accessor_defined.append_item(std::move(undef_accessor)); 53 args_list_accessor_defined.append_item(std::move(undef_accessor));
54 result = functions::RunDefined(setup.scope(), &function_call, 54 result = functions::RunDefined(setup.scope(), &function_call,
55 &args_list_accessor_defined, &err); 55 &args_list_accessor_defined, &err);
56 ASSERT_EQ(Value::BOOLEAN, result.type()); 56 ASSERT_EQ(Value::BOOLEAN, result.type());
57 EXPECT_FALSE(result.boolean_value()); 57 EXPECT_FALSE(result.boolean_value());
58 } 58 }
59 59
60 // 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
61 // doesn't take one. 61 // doesn't take one.
(...skipping 20 matching lines...) Expand all
82 EXPECT_FALSE(defined_no_scope.has_error()); 82 EXPECT_FALSE(defined_no_scope.has_error());
83 result = defined_no_scope.parsed()->Execute(setup.scope(), &err); 83 result = defined_no_scope.parsed()->Execute(setup.scope(), &err);
84 EXPECT_FALSE(err.has_error()); 84 EXPECT_FALSE(err.has_error());
85 85
86 // A block to defined should fail. 86 // A block to defined should fail.
87 TestParseInput defined_with_scope("defined(foo) {}"); 87 TestParseInput defined_with_scope("defined(foo) {}");
88 EXPECT_FALSE(defined_with_scope.has_error()); 88 EXPECT_FALSE(defined_with_scope.has_error());
89 result = defined_with_scope.parsed()->Execute(setup.scope(), &err); 89 result = defined_with_scope.parsed()->Execute(setup.scope(), &err);
90 EXPECT_TRUE(err.has_error()); 90 EXPECT_TRUE(err.has_error());
91 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698