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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/scope.cc ('k') | tools/gn/token.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/scope_unittest.cc
diff --git a/tools/gn/scope_unittest.cc b/tools/gn/scope_unittest.cc
index a693957923ee543c04a4dc52b1efd28c52e5d421..494b90de1c4aedd7559fcece9c5c950fcb85c124 100644
--- a/tools/gn/scope_unittest.cc
+++ b/tools/gn/scope_unittest.cc
@@ -46,3 +46,57 @@ TEST(Scope, NonRecursiveMergeTo) {
EXPECT_FALSE(err.has_error());
}
}
+
+TEST(Scope, GetMutableValue) {
+ TestWithScope setup;
+
+ // Make a pretend parse node with proper tracking that we can blame for the
+ // given value.
+ InputFile input_file(SourceFile("//foo"));
+ Token assignment_token(Location(&input_file, 1, 1), Token::STRING,
+ "\"hello\"");
+ LiteralNode assignment;
+ assignment.set_value(assignment_token);
+
+ const char kOnConst[] = "on_const";
+ const char kOnMutable1[] = "on_mutable1";
+ const char kOnMutable2[] = "on_mutable2";
+
+ Value value(&assignment, "hello");
+
+ // Create a root scope with one value.
+ Scope root_scope(setup.settings());
+ root_scope.SetValue(kOnConst, value, &assignment);
+
+ // Create a first nested scope with a different value.
+ const Scope* const_root_scope = &root_scope;
+ Scope mutable_scope1(const_root_scope);
+ mutable_scope1.SetValue(kOnMutable1, value, &assignment);
+
+ // Create a second nested scope with a different value.
+ Scope mutable_scope2(&mutable_scope1);
+ mutable_scope2.SetValue(kOnMutable2, value, &assignment);
+
+ // Check getting root scope values.
+ EXPECT_TRUE(mutable_scope2.GetValue(kOnConst, true));
+ EXPECT_FALSE(mutable_scope2.GetMutableValue(kOnConst, true));
+
+ // Test reading a value from scope 1.
+ Value* mutable1_result = mutable_scope2.GetMutableValue(kOnMutable1, false);
+ ASSERT_TRUE(mutable1_result);
+ EXPECT_TRUE(*mutable1_result == value);
+
+ // Make sure CheckForUnusedVars works on scope1 (we didn't mark the value as
+ // used in the previous step).
+ Err err;
+ EXPECT_FALSE(mutable_scope1.CheckForUnusedVars(&err));
+ mutable1_result = mutable_scope2.GetMutableValue(kOnMutable1, true);
+ EXPECT_TRUE(mutable1_result);
+ err = Err();
+ EXPECT_TRUE(mutable_scope1.CheckForUnusedVars(&err));
+
+ // Test reading a value from scope 2.
+ Value* mutable2_result = mutable_scope2.GetMutableValue(kOnMutable2, true);
+ ASSERT_TRUE(mutable2_result);
+ EXPECT_TRUE(*mutable2_result == value);
+}
« 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