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. 4 5 #include "testing/gtest/include/gtest/gtest.h" 6 #include "tools/gn/functions.h" 7 #include "tools/gn/test_with_scope.h" 8 9 TEST(FunctionProcessFileTemplates, SingleString) { 10 TestWithScope setup; 11 12 std::vector<Value> args; 13 14 Value sources(NULL, Value::LIST); 15 sources.list_value().push_back(Value(NULL, "//src/foo.txt")); 16 args.push_back(sources); 17 18 Value expansion(NULL, "1234{{source_name_part}}5678"); 19 args.push_back(expansion); 20 21 Err err; 22 Value result = functions::RunProcessFileTemplate( 23 setup.scope(), NULL, args, &err); 24 EXPECT_FALSE(err.has_error()); 25 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()); 30 } 31 32 TEST(FunctionProcessFileTemplates, MultipleStrings) { 33 TestWithScope setup; 34 35 std::vector<Value> args; 36 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); 41 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); 48 49 Err err; 50 Value result = functions::RunProcessFileTemplate( 51 setup.scope(), NULL, args, &err); 52 EXPECT_FALSE(err.has_error()); 53 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()); 64 } 65