1 // Copyright 2014 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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/functions.h"
7 #include "tools/gn/test_with_scope.h"
9 TEST(FunctionProcessFileTemplates
, SingleString
) {
12 std::vector
<Value
> args
;
14 Value
sources(NULL
, Value::LIST
);
15 sources
.list_value().push_back(Value(NULL
, "//src/foo.txt"));
16 args
.push_back(sources
);
18 Value
expansion(NULL
, "1234{{source_name_part}}5678");
19 args
.push_back(expansion
);
22 Value result
= functions::RunProcessFileTemplate(
23 setup
.scope(), NULL
, args
, &err
);
24 EXPECT_FALSE(err
.has_error());
26 ASSERT_TRUE(result
.type() == Value::LIST
);
27 ASSERT_EQ(1u, result
.list_value().size());
28 ASSERT_TRUE(result
.list_value()[0].type() == Value::STRING
);
29 ASSERT_EQ("1234foo5678", result
.list_value()[0].string_value());
32 TEST(FunctionProcessFileTemplates
, MultipleStrings
) {
35 std::vector
<Value
> args
;
37 Value
sources(NULL
, Value::LIST
);
38 sources
.list_value().push_back(Value(NULL
, "//src/one.txt"));
39 sources
.list_value().push_back(Value(NULL
, "//src/two.txt"));
40 args
.push_back(sources
);
42 Value
expansions(NULL
, Value::LIST
);
43 expansions
.list_value().push_back(
44 Value(NULL
, "1234{{source_name_part}}5678"));
45 expansions
.list_value().push_back(
46 Value(NULL
, "ABCD{{source_file_part}}EFGH"));
47 args
.push_back(expansions
);
50 Value result
= functions::RunProcessFileTemplate(
51 setup
.scope(), NULL
, args
, &err
);
52 EXPECT_FALSE(err
.has_error());
54 ASSERT_TRUE(result
.type() == Value::LIST
);
55 ASSERT_EQ(4u, result
.list_value().size());
56 ASSERT_TRUE(result
.list_value()[0].type() == Value::STRING
);
57 ASSERT_TRUE(result
.list_value()[1].type() == Value::STRING
);
58 ASSERT_TRUE(result
.list_value()[2].type() == Value::STRING
);
59 ASSERT_TRUE(result
.list_value()[3].type() == Value::STRING
);
60 ASSERT_EQ("1234one5678", result
.list_value()[0].string_value());
61 ASSERT_EQ("ABCDone.txtEFGH", result
.list_value()[1].string_value());
62 ASSERT_EQ("1234two5678", result
.list_value()[2].string_value());
63 ASSERT_EQ("ABCDtwo.txtEFGH", result
.list_value()[3].string_value());