OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/template_expressions.h" | 5 #include "ui/base/template_expressions.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace ui { | 9 namespace ui { |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 substitutions)); | 47 substitutions)); |
48 } | 48 } |
49 | 49 |
50 TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsRaw) { | 50 TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsRaw) { |
51 static TemplateReplacements substitutions; | 51 static TemplateReplacements substitutions; |
52 substitutions["rawSample"] = "<a href=\"example.com\">hello</a>"; | 52 substitutions["rawSample"] = "<a href=\"example.com\">hello</a>"; |
53 EXPECT_EQ("<a href=\"example.com\">hello</a>", | 53 EXPECT_EQ("<a href=\"example.com\">hello</a>", |
54 ReplaceTemplateExpressions("$i18nRaw{rawSample}", substitutions)); | 54 ReplaceTemplateExpressions("$i18nRaw{rawSample}", substitutions)); |
55 } | 55 } |
56 | 56 |
57 TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPolymerQuoting) { | |
58 static TemplateReplacements substitutions; | |
59 substitutions["singleSample"] = "don't do it"; | |
60 substitutions["doubleSample"] = "\"mood\" said the cow"; | |
Dan Beam
2017/02/14 02:34:45
nit: moo
dschuyler
2017/02/14 17:59:36
Done.
| |
61 // This resolves |Call('don\'t do it')| to Polymer, which is presented as | |
62 // |don't do it| to the user. | |
63 EXPECT_EQ("<div>[[Call('don\\'t do it')]]", | |
64 ReplaceTemplateExpressions( | |
65 "<div>[[Call('$i18nPolymer{singleSample}')]]", substitutions)); | |
66 // This resolves |Call('\"mood\" said the cow')| to Polymer, which is | |
67 // presented as |"mood" said the cow| to the user. | |
68 EXPECT_EQ("<div>[[Call('\\\"mood\\\" said the cow')]]", | |
69 ReplaceTemplateExpressions( | |
70 "<div>[[Call('$i18nPolymer{doubleSample}')]]", substitutions)); | |
71 } | |
72 | |
73 TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPolymerMixed) { | |
74 static TemplateReplacements substitutions; | |
75 substitutions["punctuationSample"] = "a\"b'c<d>e&f"; | |
76 substitutions["htmlSample"] = "<div>hello</div>"; | |
77 EXPECT_EQ("a\\\"b\\'c<d>e&f", | |
78 ReplaceTemplateExpressions("$i18nPolymer{punctuationSample}", | |
79 substitutions)); | |
80 EXPECT_EQ("<div>hello</div>", ReplaceTemplateExpressions( | |
81 "$i18nPolymer{htmlSample}", substitutions)); | |
82 EXPECT_EQ("multiple: <div>hello</div>, a\\\"b\\'c<d>e&f.", | |
83 ReplaceTemplateExpressions("multiple: $i18nPolymer{htmlSample}, " | |
84 "$i18nPolymer{punctuationSample}.", | |
85 substitutions)); | |
86 } | |
87 | |
57 } // namespace ui | 88 } // namespace ui |
OLD | NEW |