1 // Copyright 2015 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 "ui/base/template_expressions.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(TemplateExpressionsTest
, ReplaceTemplateExpressionsPieces
) {
12 std::map
<base::StringPiece
, std::string
> substitutions
;
13 substitutions
["test"] = "word";
14 substitutions
["5"] = "number";
15 substitutions
[""] = "blank";
17 EXPECT_EQ(ReplaceTemplateExpressions("${}", substitutions
), "blank");
18 EXPECT_EQ(ReplaceTemplateExpressions("", substitutions
), "");
19 EXPECT_EQ(ReplaceTemplateExpressions("${test}", substitutions
), "word");
20 EXPECT_EQ(ReplaceTemplateExpressions("${5} ", substitutions
), "number ");
22 ReplaceTemplateExpressions("multiple: ${test}, ${5}.", substitutions
),
23 "multiple: word, number.");
26 TEST(TemplateExpressionsTest
,
27 ReplaceTemplateExpressionsConsecutiveDollarSignsPieces
) {
28 std::map
<base::StringPiece
, std::string
> substitutions
;
29 substitutions
["a"] = "x";
30 EXPECT_EQ(ReplaceTemplateExpressions("$ $$ $$$", substitutions
), "$ $$ $$$");
31 EXPECT_EQ(ReplaceTemplateExpressions("$${a}", substitutions
), "$x");
32 EXPECT_EQ(ReplaceTemplateExpressions("$$${a}", substitutions
), "$$x");
33 EXPECT_EQ(ReplaceTemplateExpressions("$12", substitutions
), "$12");