Add the ability to code generated prepopulated static nested structs
[chromium-blink-merge.git] / tools / gn / function_process_file_template_unittest.cc
bloba455222a5494c000be9e12a81085d2a3f32e24b6
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) {
10 TestWithScope setup;
12 std::vector<Value> args;
14 Value sources(nullptr, Value::LIST);
15 sources.list_value().push_back(Value(nullptr, "//src/foo.txt"));
16 args.push_back(sources);
18 Value expansion(nullptr, "1234{{source_name_part}}5678");
19 args.push_back(expansion);
21 Err err;
22 Value result =
23 functions::RunProcessFileTemplate(setup.scope(), nullptr, 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) {
33 TestWithScope setup;
35 std::vector<Value> args;
37 Value sources(nullptr, Value::LIST);
38 sources.list_value().push_back(Value(nullptr, "//src/one.txt"));
39 sources.list_value().push_back(Value(nullptr, "//src/two.txt"));
40 args.push_back(sources);
42 Value expansions(nullptr, Value::LIST);
43 expansions.list_value().push_back(
44 Value(nullptr, "1234{{source_name_part}}5678"));
45 expansions.list_value().push_back(
46 Value(nullptr, "ABCD{{source_file_part}}EFGH"));
47 args.push_back(expansions);
49 Err err;
50 Value result =
51 functions::RunProcessFileTemplate(setup.scope(), nullptr, 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());