| 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/string_utils.h" |
| 6 |
| 5 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
| 6 | 9 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/gn/err.h" | 11 #include "tools/gn/err.h" |
| 9 #include "tools/gn/scope.h" | 12 #include "tools/gn/scope.h" |
| 10 #include "tools/gn/settings.h" | 13 #include "tools/gn/settings.h" |
| 11 #include "tools/gn/string_utils.h" | |
| 12 #include "tools/gn/token.h" | 14 #include "tools/gn/token.h" |
| 13 #include "tools/gn/value.h" | 15 #include "tools/gn/value.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 bool CheckExpansionCase(const char* input, const char* expected, bool success) { | 19 bool CheckExpansionCase(const char* input, const char* expected, bool success) { |
| 18 Scope scope(static_cast<const Settings*>(nullptr)); | 20 Scope scope(static_cast<const Settings*>(nullptr)); |
| 19 int64_t one = 1; | 21 int64_t one = 1; |
| 20 scope.SetValue("one", Value(nullptr, one), nullptr); | 22 scope.SetValue("one", Value(nullptr, one), nullptr); |
| 21 scope.SetValue("onestring", Value(nullptr, "one"), nullptr); | 23 scope.SetValue("onestring", Value(nullptr, "one"), nullptr); |
| 22 | 24 |
| 23 // Nested scope called "onescope" with a value "one" inside it. | 25 // Nested scope called "onescope" with a value "one" inside it. |
| 24 scoped_ptr<Scope> onescope(new Scope(static_cast<const Settings*>(nullptr))); | 26 scoped_ptr<Scope> onescope(new Scope(static_cast<const Settings*>(nullptr))); |
| 25 onescope->SetValue("one", Value(nullptr, one), nullptr); | 27 onescope->SetValue("one", Value(nullptr, one), nullptr); |
| 26 scope.SetValue("onescope", Value(nullptr, onescope.Pass()), nullptr); | 28 scope.SetValue("onescope", Value(nullptr, std::move(onescope)), nullptr); |
| 27 | 29 |
| 28 // List called "onelist" with one value that maps to 1. | 30 // List called "onelist" with one value that maps to 1. |
| 29 Value onelist(nullptr, Value::LIST); | 31 Value onelist(nullptr, Value::LIST); |
| 30 onelist.list_value().push_back(Value(nullptr, one)); | 32 onelist.list_value().push_back(Value(nullptr, one)); |
| 31 scope.SetValue("onelist", onelist, nullptr); | 33 scope.SetValue("onelist", onelist, nullptr); |
| 32 | 34 |
| 33 // Construct the string token, which includes the quotes. | 35 // Construct the string token, which includes the quotes. |
| 34 std::string literal_string; | 36 std::string literal_string; |
| 35 literal_string.push_back('"'); | 37 literal_string.push_back('"'); |
| 36 literal_string.append(input); | 38 literal_string.append(input); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_TRUE(CheckExpansionCase("hello #${onescope.two}", nullptr, false)); | 94 EXPECT_TRUE(CheckExpansionCase("hello #${onescope.two}", nullptr, false)); |
| 93 | 95 |
| 94 // Accessing the list. | 96 // Accessing the list. |
| 95 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[0]}", "hello #1", true)); | 97 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[0]}", "hello #1", true)); |
| 96 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[1]}", nullptr, false)); | 98 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[1]}", nullptr, false)); |
| 97 | 99 |
| 98 // Trying some other (otherwise valid) expressions should fail. | 100 // Trying some other (otherwise valid) expressions should fail. |
| 99 EXPECT_TRUE(CheckExpansionCase("${1 + 2}", nullptr, false)); | 101 EXPECT_TRUE(CheckExpansionCase("${1 + 2}", nullptr, false)); |
| 100 EXPECT_TRUE(CheckExpansionCase("${print(1)}", nullptr, false)); | 102 EXPECT_TRUE(CheckExpansionCase("${print(1)}", nullptr, false)); |
| 101 } | 103 } |
| OLD | NEW |