| 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 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 TEST(Scope, NonRecursiveMergeTo) { | 27 TEST(Scope, NonRecursiveMergeTo) { |
| 28 TestWithScope setup; | 28 TestWithScope setup; |
| 29 | 29 |
| 30 // Make a pretend parse node with proper tracking that we can blame for the | 30 // Make a pretend parse node with proper tracking that we can blame for the |
| 31 // given value. | 31 // given value. |
| 32 InputFile input_file(SourceFile("//foo")); | 32 InputFile input_file(SourceFile("//foo")); |
| 33 Token assignment_token(Location(&input_file, 1, 1), Token::STRING, | 33 Token assignment_token(Location(&input_file, 1, 1, 1), Token::STRING, |
| 34 "\"hello\""); | 34 "\"hello\""); |
| 35 LiteralNode assignment; | 35 LiteralNode assignment; |
| 36 assignment.set_value(assignment_token); | 36 assignment.set_value(assignment_token); |
| 37 | 37 |
| 38 // Add some values to the scope. | 38 // Add some values to the scope. |
| 39 Value old_value(&assignment, "hello"); | 39 Value old_value(&assignment, "hello"); |
| 40 setup.scope()->SetValue("v", old_value, &assignment); | 40 setup.scope()->SetValue("v", old_value, &assignment); |
| 41 base::StringPiece private_var_name("_private"); | 41 base::StringPiece private_var_name("_private"); |
| 42 setup.scope()->SetValue(private_var_name, old_value, &assignment); | 42 setup.scope()->SetValue(private_var_name, old_value, &assignment); |
| 43 | 43 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST(Scope, MakeClosure) { | 197 TEST(Scope, MakeClosure) { |
| 198 // Create 3 nested scopes [const root from setup] <- nested1 <- nested2. | 198 // Create 3 nested scopes [const root from setup] <- nested1 <- nested2. |
| 199 TestWithScope setup; | 199 TestWithScope setup; |
| 200 | 200 |
| 201 // Make a pretend parse node with proper tracking that we can blame for the | 201 // Make a pretend parse node with proper tracking that we can blame for the |
| 202 // given value. | 202 // given value. |
| 203 InputFile input_file(SourceFile("//foo")); | 203 InputFile input_file(SourceFile("//foo")); |
| 204 Token assignment_token(Location(&input_file, 1, 1), Token::STRING, | 204 Token assignment_token(Location(&input_file, 1, 1, 1), Token::STRING, |
| 205 "\"hello\""); | 205 "\"hello\""); |
| 206 LiteralNode assignment; | 206 LiteralNode assignment; |
| 207 assignment.set_value(assignment_token); | 207 assignment.set_value(assignment_token); |
| 208 setup.scope()->SetValue("on_root", Value(&assignment, "on_root"), | 208 setup.scope()->SetValue("on_root", Value(&assignment, "on_root"), |
| 209 &assignment); | 209 &assignment); |
| 210 | 210 |
| 211 // Root scope should be const from the nested caller's perspective. | 211 // Root scope should be const from the nested caller's perspective. |
| 212 Scope nested1(static_cast<const Scope*>(setup.scope())); | 212 Scope nested1(static_cast<const Scope*>(setup.scope())); |
| 213 nested1.SetValue("on_one", Value(&assignment, "on_one"), &assignment); | 213 nested1.SetValue("on_one", Value(&assignment, "on_one"), &assignment); |
| 214 | 214 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 229 EXPECT_TRUE(HasStringValueEqualTo(result.get(), "on_one", "on_two")); | 229 EXPECT_TRUE(HasStringValueEqualTo(result.get(), "on_one", "on_two")); |
| 230 EXPECT_TRUE(HasStringValueEqualTo(result.get(), "on_two", "on_two2")); | 230 EXPECT_TRUE(HasStringValueEqualTo(result.get(), "on_two", "on_two2")); |
| 231 } | 231 } |
| 232 | 232 |
| 233 TEST(Scope, GetMutableValue) { | 233 TEST(Scope, GetMutableValue) { |
| 234 TestWithScope setup; | 234 TestWithScope setup; |
| 235 | 235 |
| 236 // Make a pretend parse node with proper tracking that we can blame for the | 236 // Make a pretend parse node with proper tracking that we can blame for the |
| 237 // given value. | 237 // given value. |
| 238 InputFile input_file(SourceFile("//foo")); | 238 InputFile input_file(SourceFile("//foo")); |
| 239 Token assignment_token(Location(&input_file, 1, 1), Token::STRING, | 239 Token assignment_token(Location(&input_file, 1, 1, 1), Token::STRING, |
| 240 "\"hello\""); | 240 "\"hello\""); |
| 241 LiteralNode assignment; | 241 LiteralNode assignment; |
| 242 assignment.set_value(assignment_token); | 242 assignment.set_value(assignment_token); |
| 243 | 243 |
| 244 const char kOnConst[] = "on_const"; | 244 const char kOnConst[] = "on_const"; |
| 245 const char kOnMutable1[] = "on_mutable1"; | 245 const char kOnMutable1[] = "on_mutable1"; |
| 246 const char kOnMutable2[] = "on_mutable2"; | 246 const char kOnMutable2[] = "on_mutable2"; |
| 247 | 247 |
| 248 Value value(&assignment, "hello"); | 248 Value value(&assignment, "hello"); |
| 249 | 249 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 TEST(Scope, RemovePrivateIdentifiers) { | 287 TEST(Scope, RemovePrivateIdentifiers) { |
| 288 TestWithScope setup; | 288 TestWithScope setup; |
| 289 setup.scope()->SetValue("a", Value(NULL, true), NULL); | 289 setup.scope()->SetValue("a", Value(NULL, true), NULL); |
| 290 setup.scope()->SetValue("_b", Value(NULL, true), NULL); | 290 setup.scope()->SetValue("_b", Value(NULL, true), NULL); |
| 291 | 291 |
| 292 setup.scope()->RemovePrivateIdentifiers(); | 292 setup.scope()->RemovePrivateIdentifiers(); |
| 293 EXPECT_TRUE(setup.scope()->GetValue("a")); | 293 EXPECT_TRUE(setup.scope()->GetValue("a")); |
| 294 EXPECT_FALSE(setup.scope()->GetValue("_b")); | 294 EXPECT_FALSE(setup.scope()->GetValue("_b")); |
| 295 } | 295 } |
| OLD | NEW |