1 // Copyright 2014 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.
5 #include "third_party/libaddressinput/src/cpp/src/rule.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 TEST(RuleTest
, CanonicalizeSubKeyTest
) {
13 i18n::addressinput::Rule rule
;
14 ASSERT_TRUE(rule
.ParseSerializedRule(base::WideToUTF8(
15 L
"{ \"sub_keys\": \"FOO~BAR~B\u00C4Z~\u0415\u0416\","
16 L
" \"sub_names\": \"Foolandia~Bartopolis~B\u00E4zmonia~"
17 L
"\u0415\u0436ville\" }")));
18 EXPECT_EQ(4U, rule
.GetSubKeys().size());
22 // If empty, expect failure.
23 const wchar_t* output
;
32 { L
"Bartopolis", L
"BAR" },
33 { L
"BARTOPOLIS", L
"BAR" },
34 { L
"BaRToPoLiS", L
"BAR" },
36 { L
"B\u00C4Z", L
"B\u00C4Z" },
37 { L
"BAZ", L
"B\u00C4Z" },
38 { L
"B\u00E4zmonia", L
"B\u00C4Z" },
39 { L
"bazmonia", L
"B\u00C4Z" },
40 // Non-ascii (Cyrillic) case sensitivity.
41 { L
"\u0415\u0416", L
"\u0415\u0416" },
42 { L
"\u0415\u0416VILLE", L
"\u0415\u0416" },
43 { L
"\u0435\u0436", L
"\u0415\u0416" },
44 { L
"\u0435\u0436VILLE", L
"\u0415\u0416" },
45 { L
"\u0435\u0436VILL", L
"" },
48 const size_t num_cases
= sizeof(expectations
) / sizeof(expectations
[0]);
49 for (size_t i
= 0; i
< num_cases
; ++i
) {
50 const std::string
input(base::WideToUTF8(expectations
[i
].input
));
51 const std::string
expected_output(base::WideToUTF8(expectations
[i
].output
));
53 EXPECT_EQ(!expected_output
.empty(),
54 rule
.CanonicalizeSubKey(input
, true, &output
))
55 << "Failed for input " << input
;
56 EXPECT_EQ(expected_output
, output
);