Index: tools/gn/scope_unittest.cc |
diff --git a/tools/gn/scope_unittest.cc b/tools/gn/scope_unittest.cc |
index 5585e50bd018226369d7d46ae6183965ca1197fa..53d4689af0b9723c9a34ec7f1929e8cce2d34e73 100644 |
--- a/tools/gn/scope_unittest.cc |
+++ b/tools/gn/scope_unittest.cc |
@@ -36,6 +36,8 @@ TEST(Scope, NonRecursiveMergeTo) { |
Value old_value(&assignment, "hello"); |
setup.scope()->SetValue("v", old_value, &assignment); |
+ base::StringPiece private_var_name("_private"); |
+ setup.scope()->SetValue(private_var_name, old_value, &assignment); |
// Detect collisions of values' values. |
{ |
@@ -45,7 +47,8 @@ TEST(Scope, NonRecursiveMergeTo) { |
Err err; |
EXPECT_FALSE(setup.scope()->NonRecursiveMergeTo( |
- &new_scope, false, &assignment, "error", &err)); |
+ &new_scope, Scope::MergeOptions(), |
+ &assignment, "error", &err)); |
EXPECT_TRUE(err.has_error()); |
} |
@@ -56,8 +59,10 @@ TEST(Scope, NonRecursiveMergeTo) { |
new_scope.SetValue("v", new_value, &assignment); |
Err err; |
+ Scope::MergeOptions options; |
+ options.clobber_existing = true; |
EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo( |
- &new_scope, true, &assignment, "error", &err)); |
+ &new_scope, options, &assignment, "error", &err)); |
EXPECT_FALSE(err.has_error()); |
const Value* found_value = new_scope.GetValue("v"); |
@@ -72,8 +77,61 @@ TEST(Scope, NonRecursiveMergeTo) { |
new_scope.SetValue("v", new_value, &assignment); |
Err err; |
+ Scope::MergeOptions options; |
+ options.clobber_existing = true; |
EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo( |
- &new_scope, false, &assignment, "error", &err)); |
+ &new_scope, options, &assignment, "error", &err)); |
+ EXPECT_FALSE(err.has_error()); |
+ } |
+ |
+ // Copy private values. |
+ { |
+ Scope new_scope(setup.settings()); |
+ |
+ Err err; |
+ EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo( |
+ &new_scope, Scope::MergeOptions(), &assignment, "error", &err)); |
+ EXPECT_FALSE(err.has_error()); |
+ EXPECT_TRUE(new_scope.GetValue(private_var_name)); |
+ } |
+ |
+ // Skip private values. |
+ { |
+ Scope new_scope(setup.settings()); |
+ |
+ Err err; |
+ Scope::MergeOptions options; |
+ options.skip_private_vars = true; |
+ EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo( |
+ &new_scope, options, &assignment, "error", &err)); |
+ EXPECT_FALSE(err.has_error()); |
+ EXPECT_FALSE(new_scope.GetValue(private_var_name)); |
+ } |
+ |
+ // Don't mark used. |
+ { |
+ Scope new_scope(setup.settings()); |
+ |
+ Err err; |
+ Scope::MergeOptions options; |
+ EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo( |
+ &new_scope, options, &assignment, "error", &err)); |
+ EXPECT_FALSE(err.has_error()); |
+ EXPECT_FALSE(new_scope.CheckForUnusedVars(&err)); |
+ EXPECT_TRUE(err.has_error()); |
+ } |
+ |
+ // Mark used. |
+ { |
+ Scope new_scope(setup.settings()); |
+ |
+ Err err; |
+ Scope::MergeOptions options; |
+ options.mark_used = true; |
+ EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo( |
+ &new_scope, options, &assignment, "error", &err)); |
+ EXPECT_FALSE(err.has_error()); |
+ EXPECT_TRUE(new_scope.CheckForUnusedVars(&err)); |
EXPECT_FALSE(err.has_error()); |
} |
} |
@@ -167,3 +225,13 @@ TEST(Scope, GetMutableValue) { |
ASSERT_TRUE(mutable2_result); |
EXPECT_TRUE(*mutable2_result == value); |
} |
+ |
+TEST(Scope, RemovePrivateIdentifiers) { |
+ TestWithScope setup; |
+ setup.scope()->SetValue("a", Value(NULL, true), NULL); |
+ setup.scope()->SetValue("_b", Value(NULL, true), NULL); |
+ |
+ setup.scope()->RemovePrivateIdentifiers(); |
+ EXPECT_TRUE(setup.scope()->GetValue("a")); |
+ EXPECT_FALSE(setup.scope()->GetValue("_b")); |
+} |