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

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

Issue 207233003: Add "." accessors to GN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 9 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
« no previous file with comments | « tools/gn/scope.cc ('k') | tools/gn/token.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/input_file.h" 6 #include "tools/gn/input_file.h"
7 #include "tools/gn/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 #include "tools/gn/test_with_scope.h" 9 #include "tools/gn/test_with_scope.h"
10 10
(...skipping 28 matching lines...) Expand all
39 Scope new_scope(setup.settings()); 39 Scope new_scope(setup.settings());
40 Value new_value(&assignment, "hello"); 40 Value new_value(&assignment, "hello");
41 new_scope.SetValue("v", new_value, &assignment); 41 new_scope.SetValue("v", new_value, &assignment);
42 42
43 Err err; 43 Err err;
44 EXPECT_TRUE(new_scope.NonRecursiveMergeTo( 44 EXPECT_TRUE(new_scope.NonRecursiveMergeTo(
45 setup.scope(), &assignment, "error", &err)); 45 setup.scope(), &assignment, "error", &err));
46 EXPECT_FALSE(err.has_error()); 46 EXPECT_FALSE(err.has_error());
47 } 47 }
48 } 48 }
49
50 TEST(Scope, GetMutableValue) {
51 TestWithScope setup;
52
53 // Make a pretend parse node with proper tracking that we can blame for the
54 // given value.
55 InputFile input_file(SourceFile("//foo"));
56 Token assignment_token(Location(&input_file, 1, 1), Token::STRING,
57 "\"hello\"");
58 LiteralNode assignment;
59 assignment.set_value(assignment_token);
60
61 const char kOnConst[] = "on_const";
62 const char kOnMutable1[] = "on_mutable1";
63 const char kOnMutable2[] = "on_mutable2";
64
65 Value value(&assignment, "hello");
66
67 // Create a root scope with one value.
68 Scope root_scope(setup.settings());
69 root_scope.SetValue(kOnConst, value, &assignment);
70
71 // Create a first nested scope with a different value.
72 const Scope* const_root_scope = &root_scope;
73 Scope mutable_scope1(const_root_scope);
74 mutable_scope1.SetValue(kOnMutable1, value, &assignment);
75
76 // Create a second nested scope with a different value.
77 Scope mutable_scope2(&mutable_scope1);
78 mutable_scope2.SetValue(kOnMutable2, value, &assignment);
79
80 // Check getting root scope values.
81 EXPECT_TRUE(mutable_scope2.GetValue(kOnConst, true));
82 EXPECT_FALSE(mutable_scope2.GetMutableValue(kOnConst, true));
83
84 // Test reading a value from scope 1.
85 Value* mutable1_result = mutable_scope2.GetMutableValue(kOnMutable1, false);
86 ASSERT_TRUE(mutable1_result);
87 EXPECT_TRUE(*mutable1_result == value);
88
89 // Make sure CheckForUnusedVars works on scope1 (we didn't mark the value as
90 // used in the previous step).
91 Err err;
92 EXPECT_FALSE(mutable_scope1.CheckForUnusedVars(&err));
93 mutable1_result = mutable_scope2.GetMutableValue(kOnMutable1, true);
94 EXPECT_TRUE(mutable1_result);
95 err = Err();
96 EXPECT_TRUE(mutable_scope1.CheckForUnusedVars(&err));
97
98 // Test reading a value from scope 2.
99 Value* mutable2_result = mutable_scope2.GetMutableValue(kOnMutable2, true);
100 ASSERT_TRUE(mutable2_result);
101 EXPECT_TRUE(*mutable2_result == value);
102 }
OLDNEW
« no previous file with comments | « tools/gn/scope.cc ('k') | tools/gn/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698