Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Unified Diff: ui/base/template_expressions_unittest.cc

Issue 1220793010: [ui/base;css] adding string template expression replacement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/template_expressions_unittest.cc
diff --git a/ui/base/template_expressions_unittest.cc b/ui/base/template_expressions_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5c363144ff0390a7b893b0d9ef17f397a0511b0
--- /dev/null
+++ b/ui/base/template_expressions_unittest.cc
@@ -0,0 +1,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

Powered by Google App Engine
This is Rietveld 408576698