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

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: removed string16 versions of template expansions 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..3450d1e3164885651244e5c7ee90d9ca1e826cfa
--- /dev/null
+++ b/ui/base/template_expressions_unittest.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 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 "base/strings/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ui {
+
+TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) {
+ std::map<base::StringPiece, std::string> substitutions;
+ substitutions["one"] = "9a";
+ substitutions["b"] = "8b";
+ substitutions["cc"] = "7c";
+ substitutions["four"] = "6d";
+ substitutions["very long with spaces"] = "5e";
+ substitutions[""] = "4f";
+ substitutions["&"] = "3g";
+ substitutions["$"] = "2h";
+ substitutions["$$"] = "1i";
+
+ EXPECT_STREQ(
+ ReplaceTemplateExpressions("${ab${cd}ef}", substitutions).c_str(), "ef}");
+ EXPECT_STREQ(ReplaceTemplateExpressions("${}", substitutions).c_str(), "4f");
+ EXPECT_STREQ(ReplaceTemplateExpressions("", substitutions).c_str(), "");
Dan Beam 2015/07/14 21:23:40 it seems like you do the same thing pretty often.
dschuyler 2015/07/15 00:11:04 On why not, well it kinda feels like adding more c
Dan Beam 2015/07/15 16:36:25 because you have to add a helper method?
dschuyler 2015/07/15 18:47:05 Based on the new info that the EXPECT_EQ works wel
+ EXPECT_STREQ(ReplaceTemplateExpressions(
+ "${one}a,${b}b,${cc}c,${four}d,${very long with "
+ "spaces}e,${}f,${&}g,${$}h,${$$}i",
+ substitutions).c_str(),
+ "9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii");
+}
+
+TEST(TemplateExpressionsTest,
+ ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) {
+ std::map<base::StringPiece, std::string> substitutions;
+ substitutions["a"] = "9a";
+ substitutions["b"] = "8b";
+ substitutions["c"] = "7c";
+ EXPECT_STREQ(ReplaceTemplateExpressions("$${a} $$${b} $$$${c} $$",
+ substitutions).c_str(),
+ "${a} $${b} $$${c} $");
+ EXPECT_STREQ(ReplaceTemplateExpressions("$12", substitutions).c_str(), "12");
+ EXPECT_STREQ(ReplaceTemplateExpressions("$$", substitutions).c_str(), "$");
+ EXPECT_STREQ(ReplaceTemplateExpressions("$", substitutions).c_str(), "");
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698