Commit fb23d0eb authored by olli.syrjala's avatar olli.syrjala Committed by Commit bot

added test to test case converting with nonASCII

Tested case conversion with some nonascii utf
chars. Also some which should not be changed.
Test also Turkish dotless I with different locales.

Review URL: https://codereview.chromium.org/1104483002

Cr-Commit-Position: refs/heads/master@{#330486}
parent 70e99e87
...@@ -3,15 +3,17 @@ ...@@ -3,15 +3,17 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/i18n/rtl.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/icu/source/i18n/unicode/usearch.h"
namespace base { namespace base {
namespace { namespace {
// Test upper and lower case string conversion. // Test upper and lower case string conversion.
TEST(CaseConversionTest, UpperLower) { TEST(CaseConversionTest, UpperLower) {
string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); const string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE."));
const string16 expected_lower(ASCIIToUTF16("text with upper & lower case.")); const string16 expected_lower(ASCIIToUTF16("text with upper & lower case."));
const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE.")); const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE."));
...@@ -22,7 +24,57 @@ TEST(CaseConversionTest, UpperLower) { ...@@ -22,7 +24,57 @@ TEST(CaseConversionTest, UpperLower) {
EXPECT_EQ(expected_upper, result); EXPECT_EQ(expected_upper, result);
} }
// TODO(jshin): More tests are needed, especially with non-ASCII characters. TEST(CaseConversionTest, NonASCII) {
const string16 mixed(WideToUTF16(
L"\xC4\xD6\xE4\xF6\x20\xCF\xEF\x20\xF7\x25"
L"\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F07\x1F0F"
L"\x20\x1E00\x1E01"));
const string16 expected_lower(WideToUTF16(
L"\xE4\xF6\xE4\xF6\x20\xEF\xEF"
L"\x20\xF7\x25\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F07"
L"\x1F07\x20\x1E01\x1E01"));
const string16 expected_upper(WideToUTF16(
L"\xC4\xD6\xC4\xD6\x20\xCF\xCF"
L"\x20\xF7\x25\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F0F"
L"\x1F0F\x20\x1E00\x1E00"));
string16 result = base::i18n::ToLower(mixed);
EXPECT_EQ(expected_lower, result);
result = base::i18n::ToUpper(mixed);
EXPECT_EQ(expected_upper, result);
}
TEST(CaseConversionTest, TurkishLocaleConversion) {
const string16 mixed(WideToUTF16(L"\x49\x131"));
const string16 expected_lower(WideToUTF16(L"\x69\x131"));
const string16 expected_upper(WideToUTF16(L"\x49\x49"));
std::string default_locale(uloc_getDefault());
i18n::SetICUDefaultLocale("en_US");
string16 result = base::i18n::ToLower(mixed);
EXPECT_EQ(expected_lower, result);
result = base::i18n::ToUpper(mixed);
EXPECT_EQ(expected_upper, result);
i18n::SetICUDefaultLocale("tr");
const string16 expected_lower_turkish(WideToUTF16(L"\x131\x131"));
const string16 expected_upper_turkish(WideToUTF16(L"\x49\x49"));
result = base::i18n::ToLower(mixed);
EXPECT_EQ(expected_lower_turkish, result);
result = base::i18n::ToUpper(mixed);
EXPECT_EQ(expected_upper_turkish, result);
base::i18n::SetICUDefaultLocale(default_locale.data());
}
} // namespace } // namespace
} // namespace base } // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment