summaryrefslogtreecommitdiffstats
path: root/ui/base/template_expressions_unittest.cc
blob: f5c363144ff0390a7b893b0d9ef17f397a0511b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/template_expressions.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace ui {

TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) {
  std::map<base::StringPiece, std::string> substitutions;
  substitutions["test"] = "word";
  substitutions["5"] = "number";
  substitutions[""] = "blank";

  EXPECT_EQ(ReplaceTemplateExpressions("${}", substitutions), "blank");
  EXPECT_EQ(ReplaceTemplateExpressions("", substitutions), "");
  EXPECT_EQ(ReplaceTemplateExpressions("${test}", substitutions), "word");
  EXPECT_EQ(ReplaceTemplateExpressions("${5} ", substitutions), "number ");
  EXPECT_EQ(
      ReplaceTemplateExpressions("multiple: ${test}, ${5}.", substitutions),
      "multiple: word, number.");
}

TEST(TemplateExpressionsTest,
     ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) {
  std::map<base::StringPiece, std::string> substitutions;
  substitutions["a"] = "x";
  EXPECT_EQ(ReplaceTemplateExpressions("$ $$ $$$", substitutions), "$ $$ $$$");
  EXPECT_EQ(ReplaceTemplateExpressions("$${a}", substitutions), "$x");
  EXPECT_EQ(ReplaceTemplateExpressions("$$${a}", substitutions), "$$x");
  EXPECT_EQ(ReplaceTemplateExpressions("$12", substitutions), "$12");
}

}  // namespace ui