| Index: tools/gn/string_utils_unittest.cc
|
| diff --git a/tools/gn/string_utils_unittest.cc b/tools/gn/string_utils_unittest.cc
|
| index cb5506596892847277fec36049492e44ffc7e513..951a84912750dfa7c554072ac4ee119af882859d 100644
|
| --- a/tools/gn/string_utils_unittest.cc
|
| +++ b/tools/gn/string_utils_unittest.cc
|
| @@ -18,6 +18,16 @@ bool CheckExpansionCase(const char* input, const char* expected, bool success) {
|
| scope.SetValue("one", Value(nullptr, one), nullptr);
|
| scope.SetValue("onestring", Value(nullptr, "one"), nullptr);
|
|
|
| + // Nested scope called "onescope" with a value "one" inside it.
|
| + scoped_ptr<Scope> onescope(new Scope(static_cast<const Settings*>(nullptr)));
|
| + onescope->SetValue("one", Value(nullptr, one), nullptr);
|
| + scope.SetValue("onescope", Value(nullptr, onescope.Pass()), nullptr);
|
| +
|
| + // List called "onelist" with one value that maps to 1.
|
| + Value onelist(nullptr, Value::LIST);
|
| + onelist.list_value().push_back(Value(nullptr, one));
|
| + scope.SetValue("onelist", onelist, nullptr);
|
| +
|
| // Construct the string token, which includes the quotes.
|
| std::string literal_string;
|
| literal_string.push_back('"');
|
| @@ -37,12 +47,13 @@ bool CheckExpansionCase(const char* input, const char* expected, bool success) {
|
|
|
| if (!success)
|
| return true; // Don't check result on failure.
|
| + printf("%s\n", result.string_value().c_str());
|
| return result.string_value() == expected;
|
| }
|
|
|
| } // namespace
|
|
|
| -TEST(StringUtils, ExpandStringLiteral) {
|
| +TEST(StringUtils, ExpandStringLiteralIdentifier) {
|
| EXPECT_TRUE(CheckExpansionCase("", "", true));
|
| EXPECT_TRUE(CheckExpansionCase("hello", "hello", true));
|
| EXPECT_TRUE(CheckExpansionCase("hello #$one", "hello #1", true));
|
| @@ -51,6 +62,8 @@ TEST(StringUtils, ExpandStringLiteral) {
|
| EXPECT_TRUE(CheckExpansionCase("hello #${one}one", "hello #1one", true));
|
| EXPECT_TRUE(CheckExpansionCase("hello #${one}$one", "hello #11", true));
|
| EXPECT_TRUE(CheckExpansionCase("$onestring${one}$one", "one11", true));
|
| + EXPECT_TRUE(CheckExpansionCase("$onescope", "{\n one = 1\n}", true));
|
| + EXPECT_TRUE(CheckExpansionCase("$onelist", "[1]", true));
|
|
|
| // Errors
|
| EXPECT_TRUE(CheckExpansionCase("hello #$", nullptr, false));
|
| @@ -70,3 +83,17 @@ TEST(StringUtils, ExpandStringLiteral) {
|
| const char* out = "\"$\\";
|
| EXPECT_TRUE(CheckExpansionCase(in, out, true));
|
| }
|
| +
|
| +TEST(StringUtils, ExpandStringLiteralExpression) {
|
| + // Accessing the scope.
|
| + EXPECT_TRUE(CheckExpansionCase("hello #${onescope.one}", "hello #1", true));
|
| + EXPECT_TRUE(CheckExpansionCase("hello #${onescope.two}", nullptr, false));
|
| +
|
| + // Accessing the list.
|
| + EXPECT_TRUE(CheckExpansionCase("hello #${onelist[0]}", "hello #1", true));
|
| + EXPECT_TRUE(CheckExpansionCase("hello #${onelist[1]}", nullptr, false));
|
| +
|
| + // Trying some other (otherwise valid) expressions should fail.
|
| + EXPECT_TRUE(CheckExpansionCase("${1 + 2}", nullptr, false));
|
| + EXPECT_TRUE(CheckExpansionCase("${print(1)}", nullptr, false));
|
| +}
|
|
|