| OLD | NEW |
| 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/template.h" | 9 #include "tools/gn/template.h" |
| 10 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 const Scope* const_root_scope = &root_scope; | 255 const Scope* const_root_scope = &root_scope; |
| 256 Scope mutable_scope1(const_root_scope); | 256 Scope mutable_scope1(const_root_scope); |
| 257 mutable_scope1.SetValue(kOnMutable1, value, &assignment); | 257 mutable_scope1.SetValue(kOnMutable1, value, &assignment); |
| 258 | 258 |
| 259 // Create a second nested scope with a different value. | 259 // Create a second nested scope with a different value. |
| 260 Scope mutable_scope2(&mutable_scope1); | 260 Scope mutable_scope2(&mutable_scope1); |
| 261 mutable_scope2.SetValue(kOnMutable2, value, &assignment); | 261 mutable_scope2.SetValue(kOnMutable2, value, &assignment); |
| 262 | 262 |
| 263 // Check getting root scope values. | 263 // Check getting root scope values. |
| 264 EXPECT_TRUE(mutable_scope2.GetValue(kOnConst, true)); | 264 EXPECT_TRUE(mutable_scope2.GetValue(kOnConst, true)); |
| 265 EXPECT_FALSE(mutable_scope2.GetMutableValue(kOnConst, true)); | 265 EXPECT_FALSE(mutable_scope2.GetMutableValue( |
| 266 kOnConst, Scope::SEARCH_NESTED, true)); |
| 266 | 267 |
| 267 // Test reading a value from scope 1. | 268 // Test reading a value from scope 1. |
| 268 Value* mutable1_result = mutable_scope2.GetMutableValue(kOnMutable1, false); | 269 Value* mutable1_result = mutable_scope2.GetMutableValue( |
| 270 kOnMutable1, Scope::SEARCH_NESTED, false); |
| 269 ASSERT_TRUE(mutable1_result); | 271 ASSERT_TRUE(mutable1_result); |
| 270 EXPECT_TRUE(*mutable1_result == value); | 272 EXPECT_TRUE(*mutable1_result == value); |
| 271 | 273 |
| 272 // Make sure CheckForUnusedVars works on scope1 (we didn't mark the value as | 274 // Make sure CheckForUnusedVars works on scope1 (we didn't mark the value as |
| 273 // used in the previous step). | 275 // used in the previous step). |
| 274 Err err; | 276 Err err; |
| 275 EXPECT_FALSE(mutable_scope1.CheckForUnusedVars(&err)); | 277 EXPECT_FALSE(mutable_scope1.CheckForUnusedVars(&err)); |
| 276 mutable1_result = mutable_scope2.GetMutableValue(kOnMutable1, true); | 278 mutable1_result = mutable_scope2.GetMutableValue( |
| 279 kOnMutable1, Scope::SEARCH_NESTED, true); |
| 277 EXPECT_TRUE(mutable1_result); | 280 EXPECT_TRUE(mutable1_result); |
| 278 err = Err(); | 281 err = Err(); |
| 279 EXPECT_TRUE(mutable_scope1.CheckForUnusedVars(&err)); | 282 EXPECT_TRUE(mutable_scope1.CheckForUnusedVars(&err)); |
| 280 | 283 |
| 281 // Test reading a value from scope 2. | 284 // Test reading a value from scope 2. |
| 282 Value* mutable2_result = mutable_scope2.GetMutableValue(kOnMutable2, true); | 285 Value* mutable2_result = mutable_scope2.GetMutableValue( |
| 286 kOnMutable2, Scope::SEARCH_NESTED, true); |
| 283 ASSERT_TRUE(mutable2_result); | 287 ASSERT_TRUE(mutable2_result); |
| 284 EXPECT_TRUE(*mutable2_result == value); | 288 EXPECT_TRUE(*mutable2_result == value); |
| 285 } | 289 } |
| 286 | 290 |
| 287 TEST(Scope, RemovePrivateIdentifiers) { | 291 TEST(Scope, RemovePrivateIdentifiers) { |
| 288 TestWithScope setup; | 292 TestWithScope setup; |
| 289 setup.scope()->SetValue("a", Value(nullptr, true), nullptr); | 293 setup.scope()->SetValue("a", Value(nullptr, true), nullptr); |
| 290 setup.scope()->SetValue("_b", Value(nullptr, true), nullptr); | 294 setup.scope()->SetValue("_b", Value(nullptr, true), nullptr); |
| 291 | 295 |
| 292 setup.scope()->RemovePrivateIdentifiers(); | 296 setup.scope()->RemovePrivateIdentifiers(); |
| 293 EXPECT_TRUE(setup.scope()->GetValue("a")); | 297 EXPECT_TRUE(setup.scope()->GetValue("a")); |
| 294 EXPECT_FALSE(setup.scope()->GetValue("_b")); | 298 EXPECT_FALSE(setup.scope()->GetValue("_b")); |
| 295 } | 299 } |
| OLD | NEW |