Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/i18n/case_conversion.h" | 5 #include "base/i18n/case_conversion.h" |
| 6 #include "base/i18n/rtl.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 9 |
| 9 namespace base { | 10 namespace base { |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 // Test upper and lower case string conversion. | 13 // Test upper and lower case string conversion. |
| 13 TEST(CaseConversionTest, UpperLower) { | 14 TEST(CaseConversionTest, UpperLower) { |
| 14 string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); | 15 const string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); |
| 15 const string16 expected_lower(ASCIIToUTF16("text with upper & lower case.")); | 16 const string16 expected_lower(ASCIIToUTF16("text with upper & lower case.")); |
| 16 const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE.")); | 17 const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE.")); |
| 17 | 18 |
| 18 string16 result = base::i18n::ToLower(mixed); | 19 string16 result = base::i18n::ToLower(mixed); |
| 19 EXPECT_EQ(expected_lower, result); | 20 EXPECT_EQ(expected_lower, result); |
| 20 | 21 |
| 21 result = base::i18n::ToUpper(mixed); | 22 result = base::i18n::ToUpper(mixed); |
| 22 EXPECT_EQ(expected_upper, result); | 23 EXPECT_EQ(expected_upper, result); |
| 23 } | 24 } |
| 24 | 25 |
| 25 // TODO(jshin): More tests are needed, especially with non-ASCII characters. | 26 TEST(CaseConversionTest, NonASCII) { |
| 27 const string16 mixed(WideToUTF16(L"\xC4\xD6\xE4\xF6\x20\xCF\xEF\x20\xF7\x25" | |
| 28 L"\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F07\x1F0F" | |
| 29 L"\x20\x1E00\x1E01")); | |
| 30 const string16 expected_lower(WideToUTF16(L"\xE4\xF6\xE4\xF6\x20\xEF\xEF" | |
| 31 L"\x20\xF7\x25\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F07" | |
| 32 L"\x1F07\x20\x1E01\x1E01")); | |
| 33 const string16 expected_upper(WideToUTF16(L"\xC4\xD6\xC4\xD6\x20\xCF\xCF" | |
| 34 L"\x20\xF7\x25\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F0F" | |
| 35 L"\x1F0F\x20\x1E00\x1E00")); | |
| 36 | |
| 37 string16 result = base::i18n::ToLower(mixed); | |
| 38 EXPECT_EQ(expected_lower, result); | |
| 39 | |
| 40 result = base::i18n::ToUpper(mixed); | |
| 41 EXPECT_EQ(expected_upper, result); | |
| 42 } | |
| 43 | |
| 44 TEST(CaseConversionTest, TurkishLocaleConversion) { | |
| 45 const string16 mixed(WideToUTF16(L"\x49\x131")); | |
| 46 const string16 expected_lower(WideToUTF16(L"\x69\x131")); | |
| 47 const string16 expected_upper(WideToUTF16(L"\x49\x49")); | |
| 48 | |
| 49 string16 result = base::i18n::ToLower(mixed); | |
| 50 EXPECT_EQ(expected_lower, result); | |
| 51 | |
| 52 result = base::i18n::ToUpper(mixed); | |
| 53 EXPECT_EQ(expected_upper, result); | |
| 54 | |
| 55 i18n::SetICUDefaultLocale("tr"); | |
|
jungshik at Google
2015/05/12 20:30:37
You'd better save the original ICU locale and rest
| |
| 56 | |
| 57 const string16 expected_lower_turkish(WideToUTF16(L"\x131\x131")); | |
| 58 const string16 expected_upper_turkish(WideToUTF16(L"\x49\x49")); | |
| 59 | |
| 60 result = base::i18n::ToLower(mixed); | |
| 61 EXPECT_EQ(expected_lower_turkish, result); | |
| 62 | |
| 63 result = base::i18n::ToUpper(mixed); | |
| 64 EXPECT_EQ(expected_upper_turkish, result); | |
| 65 } | |
| 26 | 66 |
| 27 } // namespace | 67 } // namespace |
| 28 } // namespace base | 68 } // namespace base |
| 69 | |
| 70 | |
| 71 | |
| OLD | NEW |