OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "tools/gn/input_file.h" |
| 7 #include "tools/gn/parse_tree.h" |
| 8 #include "tools/gn/scope.h" |
| 9 #include "tools/gn/test_with_scope.h" |
| 10 |
| 11 TEST(Scope, NonRecursiveMergeTo) { |
| 12 TestWithScope setup; |
| 13 |
| 14 // Make a pretend parse node with proper tracking that we can blame for the |
| 15 // given value. |
| 16 InputFile input_file(SourceFile("//foo")); |
| 17 Token assignment_token(Location(&input_file, 1, 1), Token::STRING, |
| 18 "\"hello\""); |
| 19 LiteralNode assignment; |
| 20 assignment.set_value(assignment_token); |
| 21 |
| 22 Value old_value(&assignment, "hello"); |
| 23 setup.scope()->SetValue("v", old_value, &assignment); |
| 24 |
| 25 // Detect collisions of values' values. |
| 26 { |
| 27 Scope new_scope(setup.settings()); |
| 28 Value new_value(&assignment, "goodbye"); |
| 29 new_scope.SetValue("v", new_value, &assignment); |
| 30 |
| 31 Err err; |
| 32 EXPECT_FALSE(new_scope.NonRecursiveMergeTo( |
| 33 setup.scope(), &assignment, "error", &err)); |
| 34 EXPECT_TRUE(err.has_error()); |
| 35 } |
| 36 |
| 37 // Don't flag values that technically collide but have the same value. |
| 38 { |
| 39 Scope new_scope(setup.settings()); |
| 40 Value new_value(&assignment, "hello"); |
| 41 new_scope.SetValue("v", new_value, &assignment); |
| 42 |
| 43 Err err; |
| 44 EXPECT_TRUE(new_scope.NonRecursiveMergeTo( |
| 45 setup.scope(), &assignment, "error", &err)); |
| 46 EXPECT_FALSE(err.has_error()); |
| 47 } |
| 48 } |
OLD | NEW |