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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "ui/base/template_expressions.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace ui {
11
12 TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) {
13 std::map<base::StringPiece, std::string> substitutions;
14 substitutions["one"] = "9a";
15 substitutions["b"] = "8b";
16 substitutions["cc"] = "7c";
17 substitutions["four"] = "6d";
18 substitutions["very long with spaces"] = "5e";
19 substitutions[""] = "4f";
20 substitutions["&"] = "3g";
21 substitutions["$"] = "2h";
22 substitutions["$$"] = "1i";
23
24 EXPECT_STREQ(
25 ReplaceTemplateExpressions("${ab${cd}ef}", substitutions).c_str(), "ef}");
26 EXPECT_STREQ(ReplaceTemplateExpressions("${}", substitutions).c_str(), "4f");
27 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
28 EXPECT_STREQ(ReplaceTemplateExpressions(
29 "${one}a,${b}b,${cc}c,${four}d,${very long with "
30 "spaces}e,${}f,${&}g,${$}h,${$$}i",
31 substitutions).c_str(),
32 "9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii");
33 }
34
35 TEST(TemplateExpressionsTest,
36 ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) {
37 std::map<base::StringPiece, std::string> substitutions;
38 substitutions["a"] = "9a";
39 substitutions["b"] = "8b";
40 substitutions["c"] = "7c";
41 EXPECT_STREQ(ReplaceTemplateExpressions("$${a} $$${b} $$$${c} $$",
42 substitutions).c_str(),
43 "${a} $${b} $$${c} $");
44 EXPECT_STREQ(ReplaceTemplateExpressions("$12", substitutions).c_str(), "12");
45 EXPECT_STREQ(ReplaceTemplateExpressions("$$", substitutions).c_str(), "$");
46 EXPECT_STREQ(ReplaceTemplateExpressions("$", substitutions).c_str(), "");
47 }
48
49 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698