| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/gn/escape.h" | 8 #include "tools/gn/escape.h" |
| 9 #include "tools/gn/file_template.h" | 9 #include "tools/gn/file_template.h" |
| 10 | 10 |
| 11 TEST(FileTemplate, Static) { | 11 TEST(FileTemplate, Static) { |
| 12 std::vector<std::string> templates; | 12 std::vector<std::string> templates; |
| 13 templates.push_back("something_static"); | 13 templates.push_back("something_static"); |
| 14 FileTemplate t(templates); | 14 FileTemplate t(templates); |
| 15 EXPECT_FALSE(t.has_substitutions()); | 15 EXPECT_FALSE(t.has_substitutions()); |
| 16 | 16 |
| 17 std::vector<std::string> result; | 17 std::vector<std::string> result; |
| 18 t.ApplyString("", &result); | 18 t.ApplyString("", &result); |
| 19 ASSERT_EQ(1u, result.size()); | 19 ASSERT_EQ(1u, result.size()); |
| 20 EXPECT_EQ("something_static", result[0]); | 20 EXPECT_EQ("something_static", result[0]); |
| 21 | 21 |
| 22 result.clear(); |
| 22 t.ApplyString("lalala", &result); | 23 t.ApplyString("lalala", &result); |
| 23 ASSERT_EQ(1u, result.size()); | 24 ASSERT_EQ(1u, result.size()); |
| 24 EXPECT_EQ("something_static", result[0]); | 25 EXPECT_EQ("something_static", result[0]); |
| 25 } | 26 } |
| 26 | 27 |
| 27 TEST(FileTemplate, Typical) { | 28 TEST(FileTemplate, Typical) { |
| 28 std::vector<std::string> templates; | 29 std::vector<std::string> templates; |
| 29 templates.push_back("foo/{{source_name_part}}.cc"); | 30 templates.push_back("foo/{{source_name_part}}.cc"); |
| 30 templates.push_back("foo/{{source_name_part}}.h"); | 31 templates.push_back("foo/{{source_name_part}}.h"); |
| 31 FileTemplate t(templates); | 32 FileTemplate t(templates); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 EscapeOptions options; | 81 EscapeOptions options; |
| 81 options.mode = ESCAPE_NINJA_SHELL; | 82 options.mode = ESCAPE_NINJA_SHELL; |
| 82 t.WriteNinjaVariablesForSubstitution(out, "../../foo/bar.txt", options); | 83 t.WriteNinjaVariablesForSubstitution(out, "../../foo/bar.txt", options); |
| 83 | 84 |
| 84 // Just the variables used above should be written. | 85 // Just the variables used above should be written. |
| 85 EXPECT_EQ( | 86 EXPECT_EQ( |
| 86 " source = ../../foo/bar.txt\n" | 87 " source = ../../foo/bar.txt\n" |
| 87 " source_name_part = bar\n", | 88 " source_name_part = bar\n", |
| 88 out.str()); | 89 out.str()); |
| 89 } | 90 } |
| OLD | NEW |