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 "tools/gn/operators.h" | 5 #include "tools/gn/operators.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 node.SetRightToValue(Value(nullptr, Value::LIST)); | 329 node.SetRightToValue(Value(nullptr, Value::LIST)); |
330 node.Execute(setup.scope(), &err); | 330 node.Execute(setup.scope(), &err); |
331 ASSERT_FALSE(err.has_error()); | 331 ASSERT_FALSE(err.has_error()); |
332 const Value* new_value = setup.scope()->GetValue(foo); | 332 const Value* new_value = setup.scope()->GetValue(foo); |
333 ASSERT_TRUE(new_value); | 333 ASSERT_TRUE(new_value); |
334 ASSERT_EQ(Value::LIST, new_value->type()); | 334 ASSERT_EQ(Value::LIST, new_value->type()); |
335 ASSERT_TRUE(new_value->list_value().empty()); | 335 ASSERT_TRUE(new_value->list_value().empty()); |
336 | 336 |
337 // Set up "foo" with a nonempty scope. | 337 // Set up "foo" with a nonempty scope. |
338 const char bar[] = "bar"; | 338 const char bar[] = "bar"; |
339 old_value = Value( | 339 old_value = |
340 nullptr, std::unique_ptr<Scope>(new Scope(setup.settings()))); | 340 Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.settings(), {}))); |
341 old_value.scope_value()->SetValue(bar, Value(nullptr, "bar"), nullptr); | 341 old_value.scope_value()->SetValue(bar, Value(nullptr, "bar"), nullptr); |
342 setup.scope()->SetValue(foo, old_value, nullptr); | 342 setup.scope()->SetValue(foo, old_value, nullptr); |
343 | 343 |
344 // Assigning a nonempty scope should fail (re-use old_value copy). | 344 // Assigning a nonempty scope should fail (re-use old_value copy). |
345 node.SetRightToValue(old_value); | 345 node.SetRightToValue(old_value); |
346 node.Execute(setup.scope(), &err); | 346 node.Execute(setup.scope(), &err); |
347 ASSERT_TRUE(err.has_error()); | 347 ASSERT_TRUE(err.has_error()); |
348 EXPECT_EQ("Replacing nonempty scope.", err.message()); | 348 EXPECT_EQ("Replacing nonempty scope.", err.message()); |
349 err = Err(); | 349 err = Err(); |
350 | 350 |
351 // Assigning an empty list should succeed. | 351 // Assigning an empty list should succeed. |
352 node.SetRightToValue( | 352 node.SetRightToValue( |
353 Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.settings())))); | 353 Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.settings(), {})))); |
354 node.Execute(setup.scope(), &err); | 354 node.Execute(setup.scope(), &err); |
355 ASSERT_FALSE(err.has_error()); | 355 ASSERT_FALSE(err.has_error()); |
356 new_value = setup.scope()->GetValue(foo); | 356 new_value = setup.scope()->GetValue(foo); |
357 ASSERT_TRUE(new_value); | 357 ASSERT_TRUE(new_value); |
358 ASSERT_EQ(Value::SCOPE, new_value->type()); | 358 ASSERT_EQ(Value::SCOPE, new_value->type()); |
359 ASSERT_FALSE(new_value->scope_value()->HasValues(Scope::SEARCH_CURRENT)); | 359 ASSERT_FALSE(new_value->scope_value()->HasValues(Scope::SEARCH_CURRENT)); |
360 } | 360 } |
361 | 361 |
362 // Tests this case: | 362 // Tests this case: |
363 // foo = 1 | 363 // foo = 1 |
(...skipping 18 matching lines...) Expand all Loading... |
382 TestBinaryOpNode node(Token::PLUS_EQUALS, "+="); | 382 TestBinaryOpNode node(Token::PLUS_EQUALS, "+="); |
383 node.SetLeftToIdentifier(foo); | 383 node.SetLeftToIdentifier(foo); |
384 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(1))); | 384 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(1))); |
385 node.Execute(&nested, &err); | 385 node.Execute(&nested, &err); |
386 ASSERT_FALSE(err.has_error()); | 386 ASSERT_FALSE(err.has_error()); |
387 | 387 |
388 // Outer foo should be used, inner foo should not be. | 388 // Outer foo should be used, inner foo should not be. |
389 EXPECT_FALSE(setup.scope()->IsSetButUnused(foo)); | 389 EXPECT_FALSE(setup.scope()->IsSetButUnused(foo)); |
390 EXPECT_TRUE(nested.IsSetButUnused(foo)); | 390 EXPECT_TRUE(nested.IsSetButUnused(foo)); |
391 } | 391 } |
OLD | NEW |