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

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

Issue 223783005: Add support for reading .gypi files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/functions.h" 6 #include "tools/gn/functions.h"
7 #include "tools/gn/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/test_with_scope.h" 8 #include "tools/gn/test_with_scope.h"
9 #include "tools/gn/value.h" 9 #include "tools/gn/value.h"
10 10
11 TEST(Functions, Defined) { 11 TEST(Functions, Defined) {
12 TestWithScope setup; 12 TestWithScope setup;
13 13
14 //InputFile input_file(SourceFile("//foo"));
15 FunctionCallNode function_call; 14 FunctionCallNode function_call;
16 Err err; 15 Err err;
17 16
18 // Test an undefined identifier. 17 // Test an undefined identifier.
19 Token undefined_token(Location(), Token::IDENTIFIER, "undef"); 18 Token undefined_token(Location(), Token::IDENTIFIER, "undef");
20 ListNode args_list_identifier_undefined; 19 ListNode args_list_identifier_undefined;
21 args_list_identifier_undefined.append_item( 20 args_list_identifier_undefined.append_item(
22 scoped_ptr<ParseNode>(new IdentifierNode(undefined_token))); 21 scoped_ptr<ParseNode>(new IdentifierNode(undefined_token)));
23 Value result = functions::RunDefined(setup.scope(), &function_call, 22 Value result = functions::RunDefined(setup.scope(), &function_call,
24 &args_list_identifier_undefined, &err); 23 &args_list_identifier_undefined, &err);
(...skipping 20 matching lines...) Expand all
45 scoped_ptr<AccessorNode> undef_accessor(new AccessorNode); 44 scoped_ptr<AccessorNode> undef_accessor(new AccessorNode);
46 undef_accessor->set_base(defined_token); 45 undef_accessor->set_base(defined_token);
47 undef_accessor->set_member(scoped_ptr<IdentifierNode>( 46 undef_accessor->set_member(scoped_ptr<IdentifierNode>(
48 new IdentifierNode(undefined_token))); 47 new IdentifierNode(undefined_token)));
49 ListNode args_list_accessor_defined; 48 ListNode args_list_accessor_defined;
50 args_list_accessor_defined.append_item(undef_accessor.PassAs<ParseNode>()); 49 args_list_accessor_defined.append_item(undef_accessor.PassAs<ParseNode>());
51 result = functions::RunDefined(setup.scope(), &function_call, 50 result = functions::RunDefined(setup.scope(), &function_call,
52 &args_list_accessor_defined, &err); 51 &args_list_accessor_defined, &err);
53 ASSERT_EQ(Value::BOOLEAN, result.type()); 52 ASSERT_EQ(Value::BOOLEAN, result.type());
54 EXPECT_FALSE(result.boolean_value()); 53 EXPECT_FALSE(result.boolean_value());
54
55 // Defined for a dictionary is a different codepath than a scope.
56 Value dict_value(NULL, Value::DICT);
57 dict_value.dict_value()["def"] = Value(NULL, "foo");
58
59 setup.scope()->SetValue("def", dict_value, NULL);
60 result = functions::RunDefined(setup.scope(), &function_call,
61 &args_list_identifier_defined, &err);
62 ASSERT_EQ(Value::BOOLEAN, result.type());
63 EXPECT_TRUE(result.boolean_value());
64 result = functions::RunDefined(setup.scope(), &function_call,
65 &args_list_accessor_defined, &err);
66 ASSERT_EQ(Value::BOOLEAN, result.type());
67 EXPECT_FALSE(result.boolean_value());
55 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698