| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "wtf/text/WTFString.h" | 27 #include "wtf/text/WTFString.h" |
| 28 | 28 |
| 29 #include "wtf/MathExtras.h" | 29 #include "wtf/MathExtras.h" |
| 30 #include "wtf/text/CString.h" | 30 #include "wtf/text/CString.h" |
| 31 #include <gtest/gtest.h> | 31 #include <gtest/gtest.h> |
| 32 #include <limits> | 32 #include <limits> |
| 33 | 33 |
| 34 namespace WTF { | 34 namespace WTF { |
| 35 | 35 |
| 36 TEST(StringTest, CreationFromLiteral) | 36 TEST(StringTest, CreationFromLiteral) { |
| 37 { | 37 String stringFromLiteral("Explicit construction syntax"); |
| 38 String stringFromLiteral("Explicit construction syntax"); | 38 EXPECT_EQ(strlen("Explicit construction syntax"), stringFromLiteral.length()); |
| 39 EXPECT_EQ(strlen("Explicit construction syntax"), stringFromLiteral.length()
); | 39 EXPECT_TRUE(stringFromLiteral == "Explicit construction syntax"); |
| 40 EXPECT_TRUE(stringFromLiteral == "Explicit construction syntax"); | 40 EXPECT_TRUE(stringFromLiteral.is8Bit()); |
| 41 EXPECT_TRUE(stringFromLiteral.is8Bit()); | 41 EXPECT_TRUE(String("Explicit construction syntax") == stringFromLiteral); |
| 42 EXPECT_TRUE(String("Explicit construction syntax") == stringFromLiteral); | |
| 43 } | 42 } |
| 44 | 43 |
| 45 TEST(StringTest, ASCII) | 44 TEST(StringTest, ASCII) { |
| 46 { | 45 CString output; |
| 47 CString output; | |
| 48 | 46 |
| 49 // Null String. | 47 // Null String. |
| 50 output = String().ascii(); | 48 output = String().ascii(); |
| 51 EXPECT_STREQ("", output.data()); | 49 EXPECT_STREQ("", output.data()); |
| 52 | 50 |
| 53 // Empty String. | 51 // Empty String. |
| 54 output = emptyString().ascii(); | 52 output = emptyString().ascii(); |
| 55 EXPECT_STREQ("", output.data()); | 53 EXPECT_STREQ("", output.data()); |
| 56 | 54 |
| 57 // Regular String. | 55 // Regular String. |
| 58 output = String("foobar").ascii(); | 56 output = String("foobar").ascii(); |
| 59 EXPECT_STREQ("foobar", output.data()); | 57 EXPECT_STREQ("foobar", output.data()); |
| 60 } | 58 } |
| 61 | 59 |
| 62 namespace { | 60 namespace { |
| 63 | 61 |
| 64 void testNumberToStringECMAScript(double number, const char* reference) | 62 void testNumberToStringECMAScript(double number, const char* reference) { |
| 65 { | 63 CString numberString = String::numberToStringECMAScript(number).latin1(); |
| 66 CString numberString = String::numberToStringECMAScript(number).latin1(); | 64 EXPECT_STREQ(reference, numberString.data()); |
| 67 EXPECT_STREQ(reference, numberString.data()); | |
| 68 } | 65 } |
| 69 | 66 |
| 70 } // anonymous namespace | 67 } // anonymous namespace |
| 71 | 68 |
| 72 TEST(StringTest, NumberToStringECMAScriptBoundaries) | 69 TEST(StringTest, NumberToStringECMAScriptBoundaries) { |
| 73 { | 70 typedef std::numeric_limits<double> Limits; |
| 74 typedef std::numeric_limits<double> Limits; | |
| 75 | 71 |
| 76 // Infinity. | 72 // Infinity. |
| 77 testNumberToStringECMAScript(Limits::infinity(), "Infinity"); | 73 testNumberToStringECMAScript(Limits::infinity(), "Infinity"); |
| 78 testNumberToStringECMAScript(-Limits::infinity(), "-Infinity"); | 74 testNumberToStringECMAScript(-Limits::infinity(), "-Infinity"); |
| 79 | 75 |
| 80 // NaN. | 76 // NaN. |
| 81 testNumberToStringECMAScript(-Limits::quiet_NaN(), "NaN"); | 77 testNumberToStringECMAScript(-Limits::quiet_NaN(), "NaN"); |
| 82 | 78 |
| 83 // Zeros. | 79 // Zeros. |
| 84 testNumberToStringECMAScript(0, "0"); | 80 testNumberToStringECMAScript(0, "0"); |
| 85 testNumberToStringECMAScript(-0, "0"); | 81 testNumberToStringECMAScript(-0, "0"); |
| 86 | 82 |
| 87 // Min-Max. | 83 // Min-Max. |
| 88 testNumberToStringECMAScript(Limits::min(), "2.2250738585072014e-308"); | 84 testNumberToStringECMAScript(Limits::min(), "2.2250738585072014e-308"); |
| 89 testNumberToStringECMAScript(Limits::max(), "1.7976931348623157e+308"); | 85 testNumberToStringECMAScript(Limits::max(), "1.7976931348623157e+308"); |
| 90 } | 86 } |
| 91 | 87 |
| 92 TEST(StringTest, NumberToStringECMAScriptRegularNumbers) | 88 TEST(StringTest, NumberToStringECMAScriptRegularNumbers) { |
| 93 { | 89 // Pi. |
| 94 // Pi. | 90 testNumberToStringECMAScript(piDouble, "3.141592653589793"); |
| 95 testNumberToStringECMAScript(piDouble, "3.141592653589793"); | 91 testNumberToStringECMAScript(piFloat, "3.1415927410125732"); |
| 96 testNumberToStringECMAScript(piFloat, "3.1415927410125732"); | 92 testNumberToStringECMAScript(piOverTwoDouble, "1.5707963267948966"); |
| 97 testNumberToStringECMAScript(piOverTwoDouble, "1.5707963267948966"); | 93 testNumberToStringECMAScript(piOverTwoFloat, "1.5707963705062866"); |
| 98 testNumberToStringECMAScript(piOverTwoFloat, "1.5707963705062866"); | 94 testNumberToStringECMAScript(piOverFourDouble, "0.7853981633974483"); |
| 99 testNumberToStringECMAScript(piOverFourDouble, "0.7853981633974483"); | 95 testNumberToStringECMAScript(piOverFourFloat, "0.7853981852531433"); |
| 100 testNumberToStringECMAScript(piOverFourFloat, "0.7853981852531433"); | |
| 101 | 96 |
| 102 // e. | 97 // e. |
| 103 const double e = 2.71828182845904523536028747135266249775724709369995; | 98 const double e = 2.71828182845904523536028747135266249775724709369995; |
| 104 testNumberToStringECMAScript(e, "2.718281828459045"); | 99 testNumberToStringECMAScript(e, "2.718281828459045"); |
| 105 | 100 |
| 106 // c, speed of light in m/s. | 101 // c, speed of light in m/s. |
| 107 const double c = 299792458; | 102 const double c = 299792458; |
| 108 testNumberToStringECMAScript(c, "299792458"); | 103 testNumberToStringECMAScript(c, "299792458"); |
| 109 | 104 |
| 110 // Golen ratio. | 105 // Golen ratio. |
| 111 const double phi = 1.6180339887498948482; | 106 const double phi = 1.6180339887498948482; |
| 112 testNumberToStringECMAScript(phi, "1.618033988749895"); | 107 testNumberToStringECMAScript(phi, "1.618033988749895"); |
| 113 } | 108 } |
| 114 | 109 |
| 115 TEST(StringTest, ReplaceWithLiteral) | 110 TEST(StringTest, ReplaceWithLiteral) { |
| 116 { | 111 // Cases for 8Bit source. |
| 117 // Cases for 8Bit source. | 112 String testString = "1224"; |
| 118 String testString = "1224"; | 113 EXPECT_TRUE(testString.is8Bit()); |
| 119 EXPECT_TRUE(testString.is8Bit()); | 114 testString.replaceWithLiteral('2', ""); |
| 120 testString.replaceWithLiteral('2', ""); | 115 EXPECT_STREQ("14", testString.utf8().data()); |
| 121 EXPECT_STREQ("14", testString.utf8().data()); | |
| 122 | 116 |
| 123 testString = "1224"; | 117 testString = "1224"; |
| 124 EXPECT_TRUE(testString.is8Bit()); | 118 EXPECT_TRUE(testString.is8Bit()); |
| 125 testString.replaceWithLiteral('2', "3"); | 119 testString.replaceWithLiteral('2', "3"); |
| 126 EXPECT_STREQ("1334", testString.utf8().data()); | 120 EXPECT_STREQ("1334", testString.utf8().data()); |
| 127 | 121 |
| 128 testString = "1224"; | 122 testString = "1224"; |
| 129 EXPECT_TRUE(testString.is8Bit()); | 123 EXPECT_TRUE(testString.is8Bit()); |
| 130 testString.replaceWithLiteral('2', "555"); | 124 testString.replaceWithLiteral('2', "555"); |
| 131 EXPECT_STREQ("15555554", testString.utf8().data()); | 125 EXPECT_STREQ("15555554", testString.utf8().data()); |
| 132 | 126 |
| 133 testString = "1224"; | 127 testString = "1224"; |
| 134 EXPECT_TRUE(testString.is8Bit()); | 128 EXPECT_TRUE(testString.is8Bit()); |
| 135 testString.replaceWithLiteral('3', "NotFound"); | 129 testString.replaceWithLiteral('3', "NotFound"); |
| 136 EXPECT_STREQ("1224", testString.utf8().data()); | 130 EXPECT_STREQ("1224", testString.utf8().data()); |
| 137 | 131 |
| 138 // Cases for 16Bit source. | 132 // Cases for 16Bit source. |
| 139 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent. | 133 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent. |
| 140 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); | 134 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); |
| 141 EXPECT_FALSE(testString.is8Bit()); | 135 EXPECT_FALSE(testString.is8Bit()); |
| 142 testString.replaceWithLiteral(UChar(0x00E9), "e"); | 136 testString.replaceWithLiteral(UChar(0x00E9), "e"); |
| 143 EXPECT_STREQ("resume", testString.utf8().data()); | 137 EXPECT_STREQ("resume", testString.utf8().data()); |
| 144 | 138 |
| 145 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); | 139 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); |
| 146 EXPECT_FALSE(testString.is8Bit()); | 140 EXPECT_FALSE(testString.is8Bit()); |
| 147 testString.replaceWithLiteral(UChar(0x00E9), ""); | 141 testString.replaceWithLiteral(UChar(0x00E9), ""); |
| 148 EXPECT_STREQ("rsum", testString.utf8().data()); | 142 EXPECT_STREQ("rsum", testString.utf8().data()); |
| 149 | 143 |
| 150 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); | 144 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); |
| 151 EXPECT_FALSE(testString.is8Bit()); | 145 EXPECT_FALSE(testString.is8Bit()); |
| 152 testString.replaceWithLiteral('3', "NotFound"); | 146 testString.replaceWithLiteral('3', "NotFound"); |
| 153 EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data()); | 147 EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data()); |
| 154 } | 148 } |
| 155 | 149 |
| 156 TEST(StringTest, ComparisonOfSameStringVectors) | 150 TEST(StringTest, ComparisonOfSameStringVectors) { |
| 157 { | 151 Vector<String> stringVector; |
| 158 Vector<String> stringVector; | 152 stringVector.append("one"); |
| 159 stringVector.append("one"); | 153 stringVector.append("two"); |
| 160 stringVector.append("two"); | |
| 161 | 154 |
| 162 Vector<String> sameStringVector; | 155 Vector<String> sameStringVector; |
| 163 sameStringVector.append("one"); | 156 sameStringVector.append("one"); |
| 164 sameStringVector.append("two"); | 157 sameStringVector.append("two"); |
| 165 | 158 |
| 166 EXPECT_EQ(stringVector, sameStringVector); | 159 EXPECT_EQ(stringVector, sameStringVector); |
| 167 } | 160 } |
| 168 | 161 |
| 169 TEST(WTF, SimplifyWhiteSpace) | 162 TEST(WTF, SimplifyWhiteSpace) { |
| 170 { | 163 String extraSpaces(" Hello world "); |
| 171 String extraSpaces(" Hello world "); | 164 EXPECT_EQ(String("Hello world"), extraSpaces.simplifyWhiteSpace()); |
| 172 EXPECT_EQ(String("Hello world"), extraSpaces.simplifyWhiteSpace()); | 165 EXPECT_EQ(String(" Hello world "), extraSpaces.simplifyWhiteSpace(WTF::DoNo
tStripWhiteSpace)); |
| 173 EXPECT_EQ(String(" Hello world "), extraSpaces.simplifyWhiteSpace(WTF::Do
NotStripWhiteSpace)); | |
| 174 | 166 |
| 175 String extraSpacesAndNewlines(" \nHello\n world\n "); | 167 String extraSpacesAndNewlines(" \nHello\n world\n "); |
| 176 EXPECT_EQ(String("Hello world"), extraSpacesAndNewlines.simplifyWhiteSpace()
); | 168 EXPECT_EQ(String("Hello world"), extraSpacesAndNewlines.simplifyWhiteSpace()); |
| 177 EXPECT_EQ(String(" Hello world "), extraSpacesAndNewlines.simplifyWhiteSp
ace(WTF::DoNotStripWhiteSpace)); | 169 EXPECT_EQ(String(" Hello world "), extraSpacesAndNewlines.simplifyWhiteSpac
e(WTF::DoNotStripWhiteSpace)); |
| 178 | 170 |
| 179 String extraSpacesAndTabs(" \nHello\t world\t "); | 171 String extraSpacesAndTabs(" \nHello\t world\t "); |
| 180 EXPECT_EQ(String("Hello world"), extraSpacesAndTabs.simplifyWhiteSpace()); | 172 EXPECT_EQ(String("Hello world"), extraSpacesAndTabs.simplifyWhiteSpace()); |
| 181 EXPECT_EQ(String(" Hello world "), extraSpacesAndTabs.simplifyWhiteSpace(
WTF::DoNotStripWhiteSpace)); | 173 EXPECT_EQ(String(" Hello world "), extraSpacesAndTabs.simplifyWhiteSpace(WT
F::DoNotStripWhiteSpace)); |
| 182 } | 174 } |
| 183 | 175 |
| 184 struct CaseFoldingTestData { | 176 struct CaseFoldingTestData { |
| 185 const char* sourceDescription; | 177 const char* sourceDescription; |
| 186 const char* source; | 178 const char* source; |
| 187 const char** localeList; | 179 const char** localeList; |
| 188 size_t localeListLength; | 180 size_t localeListLength; |
| 189 const char* expected; | 181 const char* expected; |
| 190 }; | 182 }; |
| 191 | 183 |
| 192 // \xC4\xB0 = U+0130 (capital dotted I) | 184 // \xC4\xB0 = U+0130 (capital dotted I) |
| 193 // \xC4\xB1 = U+0131 (lowercase dotless I) | 185 // \xC4\xB1 = U+0131 (lowercase dotless I) |
| 194 const char* turkicInput = "Isi\xC4\xB0 \xC4\xB0s\xC4\xB1I"; | 186 const char* turkicInput = "Isi\xC4\xB0 \xC4\xB0s\xC4\xB1I"; |
| 195 const char* greekInput = "\xCE\x9F\xCE\x94\xCE\x8C\xCE\xA3 \xCE\x9F\xCE\xB4\xCF\
x8C\xCF\x82 \xCE\xA3\xCE\xBF \xCE\xA3\xCE\x9F o\xCE\xA3 \xCE\x9F\xCE\xA3 \xCF\x8
3 \xE1\xBC\x95\xCE\xBE"; | 187 const char* greekInput = "\xCE\x9F\xCE\x94\xCE\x8C\xCE\xA3 \xCE\x9F\xCE\xB4\xCF\
x8C\xCF\x82 \xCE\xA3\xCE\xBF \xCE\xA3\xCE\x9F o\xCE\xA3 \xCE\x9F\xCE\xA3 \xCF\x8
3 \xE1\xBC\x95\xCE\xBE"; |
| 196 const char* lithuanianInput = "I \xC3\x8F J J\xCC\x88 \xC4\xAE \xC4\xAE\xCC\x88
\xC3\x8C \xC3\x8D \xC4\xA8 xi\xCC\x87\xCC\x88 xj\xCC\x87\xCC\x88 x\xC4\xAF\xCC\x
87\xCC\x88 xi\xCC\x87\xCC\x80 xi\xCC\x87\xCC\x81 xi\xCC\x87\xCC\x83 XI X\xC3\x8F
XJ XJ\xCC\x88 X\xC4\xAE X\xC4\xAE\xCC\x88"; | 188 const char* lithuanianInput = "I \xC3\x8F J J\xCC\x88 \xC4\xAE \xC4\xAE\xCC\x88
\xC3\x8C \xC3\x8D \xC4\xA8 xi\xCC\x87\xCC\x88 xj\xCC\x87\xCC\x88 x\xC4\xAF\xCC\x
87\xCC\x88 xi\xCC\x87\xCC\x80 xi\xCC\x87\xCC\x81 xi\xCC\x87\xCC\x83 XI X\xC3\x8F
XJ XJ\xCC\x88 X\xC4\xAE X\xC4\xAE\xCC\x88"; |
| 197 | 189 |
| 198 | |
| 199 const char* turkicLocales[] = { | 190 const char* turkicLocales[] = { |
| 200 "tr", "tr-TR", "tr_TR", "tr@foo=bar", "tr-US", "TR", "tr-tr", "tR", | 191 "tr", "tr-TR", "tr_TR", "tr@foo=bar", "tr-US", "TR", "tr-tr", "tR", |
| 201 "az", "az-AZ", "az_AZ", "az@foo=bar", "az-US", "Az", "AZ-AZ", }; | 192 "az", "az-AZ", "az_AZ", "az@foo=bar", "az-US", "Az", "AZ-AZ", |
| 193 }; |
| 202 const char* nonTurkicLocales[] = { | 194 const char* nonTurkicLocales[] = { |
| 203 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", | 195 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", |
| 204 "ja", "el", "fil", "fi", "lt", }; | 196 "ja", "el", "fil", "fi", "lt", |
| 197 }; |
| 205 const char* greekLocales[] = { | 198 const char* greekLocales[] = { |
| 206 "el", "el-GR", "el_GR", "el@foo=bar", "el-US", "EL", "el-gr", "eL", | 199 "el", "el-GR", "el_GR", "el@foo=bar", "el-US", "EL", "el-gr", "eL", |
| 207 }; | 200 }; |
| 208 const char* nonGreekLocales[] = { | 201 const char* nonGreekLocales[] = { |
| 209 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", | 202 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", |
| 210 "ja", "tr", "az", "fil", "fi", "lt", }; | 203 "ja", "tr", "az", "fil", "fi", "lt", |
| 204 }; |
| 211 const char* lithuanianLocales[] = { | 205 const char* lithuanianLocales[] = { |
| 212 "lt", "lt-LT", "lt_LT", "lt@foo=bar", "lt-US", "LT", "lt-lt", "lT", | 206 "lt", "lt-LT", "lt_LT", "lt@foo=bar", "lt-US", "LT", "lt-lt", "lT", |
| 213 }; | 207 }; |
| 214 // Should not have "tr" or "az" because "lt" and 'tr/az' rules conflict with eac
h other. | 208 // Should not have "tr" or "az" because "lt" and 'tr/az' rules conflict with eac
h other. |
| 215 const char* nonLithuanianLocales[] = { | 209 const char* nonLithuanianLocales[] = { |
| 216 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", "ja", "fil", "fi", "el", }
; | 210 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", "ja", "fil", "fi", "el", |
| 211 }; |
| 217 | 212 |
| 218 TEST(StringTest, ToUpperLocale) | 213 TEST(StringTest, ToUpperLocale) { |
| 219 { | 214 CaseFoldingTestData testDataList[] = { |
| 220 CaseFoldingTestData testDataList[] = { | 215 { |
| 221 { | 216 "Turkic input", |
| 222 "Turkic input", | 217 turkicInput, |
| 223 turkicInput, | 218 turkicLocales, |
| 224 turkicLocales, | 219 sizeof(turkicLocales) / sizeof(const char*), |
| 225 sizeof(turkicLocales) / sizeof(const char*), | 220 "IS\xC4\xB0\xC4\xB0 \xC4\xB0SII", |
| 226 "IS\xC4\xB0\xC4\xB0 \xC4\xB0SII", | 221 }, |
| 227 }, { | 222 { |
| 228 "Turkic input", | 223 "Turkic input", |
| 229 turkicInput, | 224 turkicInput, |
| 230 nonTurkicLocales, | 225 nonTurkicLocales, |
| 231 sizeof(nonTurkicLocales) / sizeof(const char*), | 226 sizeof(nonTurkicLocales) / sizeof(const char*), |
| 232 "ISI\xC4\xB0 \xC4\xB0SII", | 227 "ISI\xC4\xB0 \xC4\xB0SII", |
| 233 }, { | 228 }, |
| 234 "Greek input", | 229 { |
| 235 greekInput, | 230 "Greek input", |
| 236 greekLocales, | 231 greekInput, |
| 237 sizeof(greekLocales) / sizeof(const char*), | 232 greekLocales, |
| 238 "\xCE\x9F\xCE\x94\xCE\x9F\xCE\xA3 \xCE\x9F\xCE\x94\xCE\x9F\xCE\xA3 \
xCE\xA3\xCE\x9F \xCE\xA3\xCE\x9F \x4F\xCE\xA3 \xCE\x9F\xCE\xA3 \xCE\xA3 \xCE\x95
\xCE\x9E", | 233 sizeof(greekLocales) / sizeof(const char*), |
| 239 }, { | 234 "\xCE\x9F\xCE\x94\xCE\x9F\xCE\xA3 \xCE\x9F\xCE\x94\xCE\x9F\xCE\xA3 \xC
E\xA3\xCE\x9F \xCE\xA3\xCE\x9F \x4F\xCE\xA3 \xCE\x9F\xCE\xA3 \xCE\xA3 \xCE\x95\x
CE\x9E", |
| 240 "Greek input", | 235 }, |
| 241 greekInput, | 236 { |
| 242 nonGreekLocales, | 237 "Greek input", |
| 243 sizeof(nonGreekLocales) / sizeof(const char*), | 238 greekInput, |
| 244 "\xCE\x9F\xCE\x94\xCE\x8C\xCE\xA3 \xCE\x9F\xCE\x94\xCE\x8C\xCE\xA3 \
xCE\xA3\xCE\x9F \xCE\xA3\xCE\x9F \x4F\xCE\xA3 \xCE\x9F\xCE\xA3 \xCE\xA3 \xE1\xBC
\x9D\xCE\x9E", | 239 nonGreekLocales, |
| 245 }, { | 240 sizeof(nonGreekLocales) / sizeof(const char*), |
| 246 "Lithuanian input", | 241 "\xCE\x9F\xCE\x94\xCE\x8C\xCE\xA3 \xCE\x9F\xCE\x94\xCE\x8C\xCE\xA3 \xC
E\xA3\xCE\x9F \xCE\xA3\xCE\x9F \x4F\xCE\xA3 \xCE\x9F\xCE\xA3 \xCE\xA3 \xE1\xBC\x
9D\xCE\x9E", |
| 247 lithuanianInput, | 242 }, |
| 248 lithuanianLocales, | 243 { |
| 249 sizeof(lithuanianLocales) / sizeof(const char*), | 244 "Lithuanian input", |
| 250 "I \xC3\x8F J J\xCC\x88 \xC4\xAE \xC4\xAE\xCC\x88 \xC3\x8C \xC3\x8D
\xC4\xA8 XI\xCC\x88 XJ\xCC\x88 X\xC4\xAE\xCC\x88 XI\xCC\x80 XI\xCC\x81 XI\xCC\x8
3 XI X\xC3\x8F XJ XJ\xCC\x88 X\xC4\xAE X\xC4\xAE\xCC\x88", | 245 lithuanianInput, |
| 251 }, { | 246 lithuanianLocales, |
| 252 "Lithuanian input", | 247 sizeof(lithuanianLocales) / sizeof(const char*), |
| 253 lithuanianInput, | 248 "I \xC3\x8F J J\xCC\x88 \xC4\xAE \xC4\xAE\xCC\x88 \xC3\x8C \xC3\x8D \x
C4\xA8 XI\xCC\x88 XJ\xCC\x88 X\xC4\xAE\xCC\x88 XI\xCC\x80 XI\xCC\x81 XI\xCC\x83
XI X\xC3\x8F XJ XJ\xCC\x88 X\xC4\xAE X\xC4\xAE\xCC\x88", |
| 254 nonLithuanianLocales, | 249 }, |
| 255 sizeof(nonLithuanianLocales) / sizeof(const char*), | 250 { |
| 256 "I \xC3\x8F J J\xCC\x88 \xC4\xAE \xC4\xAE\xCC\x88 \xC3\x8C \xC3\x8D
\xC4\xA8 XI\xCC\x87\xCC\x88 XJ\xCC\x87\xCC\x88 X\xC4\xAE\xCC\x87\xCC\x88 XI\xCC\
x87\xCC\x80 XI\xCC\x87\xCC\x81 XI\xCC\x87\xCC\x83 XI X\xC3\x8F XJ XJ\xCC\x88 X\x
C4\xAE X\xC4\xAE\xCC\x88", | 251 "Lithuanian input", |
| 257 }, | 252 lithuanianInput, |
| 258 }; | 253 nonLithuanianLocales, |
| 254 sizeof(nonLithuanianLocales) / sizeof(const char*), |
| 255 "I \xC3\x8F J J\xCC\x88 \xC4\xAE \xC4\xAE\xCC\x88 \xC3\x8C \xC3\x8D \x
C4\xA8 XI\xCC\x87\xCC\x88 XJ\xCC\x87\xCC\x88 X\xC4\xAE\xCC\x87\xCC\x88 XI\xCC\x8
7\xCC\x80 XI\xCC\x87\xCC\x81 XI\xCC\x87\xCC\x83 XI X\xC3\x8F XJ XJ\xCC\x88 X\xC4
\xAE X\xC4\xAE\xCC\x88", |
| 256 }, |
| 257 }; |
| 259 | 258 |
| 260 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i)
{ | 259 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) { |
| 261 const char* expected = testDataList[i].expected; | 260 const char* expected = testDataList[i].expected; |
| 262 String source = String::fromUTF8(testDataList[i].source); | 261 String source = String::fromUTF8(testDataList[i].source); |
| 263 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { | 262 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { |
| 264 const char* locale = testDataList[i].localeList[j]; | 263 const char* locale = testDataList[i].localeList[j]; |
| 265 EXPECT_STREQ(expected, source.upper(locale).utf8().data()) << testDa
taList[i].sourceDescription << "; locale=" << locale; | 264 EXPECT_STREQ(expected, source.upper(locale).utf8().data()) << testDataList
[i].sourceDescription << "; locale=" << locale; |
| 266 } | |
| 267 } | 265 } |
| 266 } |
| 268 } | 267 } |
| 269 | 268 |
| 270 TEST(StringTest, ToLowerLocale) | 269 TEST(StringTest, ToLowerLocale) { |
| 271 { | 270 CaseFoldingTestData testDataList[] = { |
| 272 CaseFoldingTestData testDataList[] = { | 271 { |
| 273 { | 272 "Turkic input", |
| 274 "Turkic input", | 273 turkicInput, |
| 275 turkicInput, | 274 turkicLocales, |
| 276 turkicLocales, | 275 sizeof(turkicLocales) / sizeof(const char*), |
| 277 sizeof(turkicLocales) / sizeof(const char*), | 276 "\xC4\xB1sii is\xC4\xB1\xC4\xB1", |
| 278 "\xC4\xB1sii is\xC4\xB1\xC4\xB1", | 277 }, |
| 279 }, { | 278 { |
| 280 "Turkic input", | 279 "Turkic input", |
| 281 turkicInput, | 280 turkicInput, |
| 282 nonTurkicLocales, | 281 nonTurkicLocales, |
| 283 sizeof(nonTurkicLocales) / sizeof(const char*), | 282 sizeof(nonTurkicLocales) / sizeof(const char*), |
| 284 // U+0130 is lowercased to U+0069 followed by U+0307 | 283 // U+0130 is lowercased to U+0069 followed by U+0307 |
| 285 "isii\xCC\x87 i\xCC\x87s\xC4\xB1i", | 284 "isii\xCC\x87 i\xCC\x87s\xC4\xB1i", |
| 286 }, { | 285 }, |
| 287 "Greek input", | 286 { |
| 288 greekInput, | 287 "Greek input", |
| 289 greekLocales, | 288 greekInput, |
| 290 sizeof(greekLocales) / sizeof(const char*), | 289 greekLocales, |
| 291 "\xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \
xCF\x83\xCE\xBF \xCF\x83\xCE\xBF \x6F\xCF\x82 \xCE\xBF\xCF\x82 \xCF\x83 \xE1\xBC
\x95\xCE\xBE", | 290 sizeof(greekLocales) / sizeof(const char*), |
| 292 }, { | 291 "\xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \xC
F\x83\xCE\xBF \xCF\x83\xCE\xBF \x6F\xCF\x82 \xCE\xBF\xCF\x82 \xCF\x83 \xE1\xBC\x
95\xCE\xBE", |
| 293 "Greek input", | 292 }, |
| 294 greekInput, | 293 { |
| 295 nonGreekLocales, | 294 "Greek input", |
| 296 sizeof(greekLocales) / sizeof(const char*), | 295 greekInput, |
| 297 "\xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \
xCF\x83\xCE\xBF \xCF\x83\xCE\xBF \x6F\xCF\x82 \xCE\xBF\xCF\x82 \xCF\x83 \xE1\xBC
\x95\xCE\xBE", | 296 nonGreekLocales, |
| 298 }, { | 297 sizeof(greekLocales) / sizeof(const char*), |
| 299 "Lithuanian input", | 298 "\xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \xCE\xBF\xCE\xB4\xCF\x8C\xCF\x82 \xC
F\x83\xCE\xBF \xCF\x83\xCE\xBF \x6F\xCF\x82 \xCE\xBF\xCF\x82 \xCF\x83 \xE1\xBC\x
95\xCE\xBE", |
| 300 lithuanianInput, | 299 }, |
| 301 lithuanianLocales, | 300 { |
| 302 sizeof(lithuanianLocales) / sizeof(const char*), | 301 "Lithuanian input", |
| 303 "i \xC3\xAF j j\xCC\x87\xCC\x88 \xC4\xAF \xC4\xAF\xCC\x87\xCC\x88 i\
xCC\x87\xCC\x80 i\xCC\x87\xCC\x81 i\xCC\x87\xCC\x83 xi\xCC\x87\xCC\x88 xj\xCC\x8
7\xCC\x88 x\xC4\xAF\xCC\x87\xCC\x88 xi\xCC\x87\xCC\x80 xi\xCC\x87\xCC\x81 xi\xCC
\x87\xCC\x83 xi x\xC3\xAF xj xj\xCC\x87\xCC\x88 x\xC4\xAF x\xC4\xAF\xCC\x87\xCC\
x88", | 302 lithuanianInput, |
| 304 }, { | 303 lithuanianLocales, |
| 305 "Lithuanian input", | 304 sizeof(lithuanianLocales) / sizeof(const char*), |
| 306 lithuanianInput, | 305 "i \xC3\xAF j j\xCC\x87\xCC\x88 \xC4\xAF \xC4\xAF\xCC\x87\xCC\x88 i\xC
C\x87\xCC\x80 i\xCC\x87\xCC\x81 i\xCC\x87\xCC\x83 xi\xCC\x87\xCC\x88 xj\xCC\x87\
xCC\x88 x\xC4\xAF\xCC\x87\xCC\x88 xi\xCC\x87\xCC\x80 xi\xCC\x87\xCC\x81 xi\xCC\x
87\xCC\x83 xi x\xC3\xAF xj xj\xCC\x87\xCC\x88 x\xC4\xAF x\xC4\xAF\xCC\x87\xCC\x8
8", |
| 307 nonLithuanianLocales, | 306 }, |
| 308 sizeof(nonLithuanianLocales) / sizeof(const char*), | 307 { |
| 309 "\x69 \xC3\xAF \x6A \x6A\xCC\x88 \xC4\xAF \xC4\xAF\xCC\x88 \xC3\xAC
\xC3\xAD \xC4\xA9 \x78\x69\xCC\x87\xCC\x88 \x78\x6A\xCC\x87\xCC\x88 \x78\xC4\xAF
\xCC\x87\xCC\x88 \x78\x69\xCC\x87\xCC\x80 \x78\x69\xCC\x87\xCC\x81 \x78\x69\xCC\
x87\xCC\x83 \x78\x69 \x78\xC3\xAF \x78\x6A \x78\x6A\xCC\x88 \x78\xC4\xAF \x78\xC
4\xAF\xCC\x88", | 308 "Lithuanian input", |
| 310 }, | 309 lithuanianInput, |
| 311 }; | 310 nonLithuanianLocales, |
| 311 sizeof(nonLithuanianLocales) / sizeof(const char*), |
| 312 "\x69 \xC3\xAF \x6A \x6A\xCC\x88 \xC4\xAF \xC4\xAF\xCC\x88 \xC3\xAC \x
C3\xAD \xC4\xA9 \x78\x69\xCC\x87\xCC\x88 \x78\x6A\xCC\x87\xCC\x88 \x78\xC4\xAF\x
CC\x87\xCC\x88 \x78\x69\xCC\x87\xCC\x80 \x78\x69\xCC\x87\xCC\x81 \x78\x69\xCC\x8
7\xCC\x83 \x78\x69 \x78\xC3\xAF \x78\x6A \x78\x6A\xCC\x88 \x78\xC4\xAF \x78\xC4\
xAF\xCC\x88", |
| 313 }, |
| 314 }; |
| 312 | 315 |
| 313 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i)
{ | 316 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) { |
| 314 const char* expected = testDataList[i].expected; | 317 const char* expected = testDataList[i].expected; |
| 315 String source = String::fromUTF8(testDataList[i].source); | 318 String source = String::fromUTF8(testDataList[i].source); |
| 316 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { | 319 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { |
| 317 const char* locale = testDataList[i].localeList[j]; | 320 const char* locale = testDataList[i].localeList[j]; |
| 318 EXPECT_STREQ(expected, source.lower(locale).utf8().data()) << testDa
taList[i].sourceDescription << "; locale=" << locale; | 321 EXPECT_STREQ(expected, source.lower(locale).utf8().data()) << testDataList
[i].sourceDescription << "; locale=" << locale; |
| 319 } | |
| 320 } | 322 } |
| 323 } |
| 321 } | 324 } |
| 322 | 325 |
| 323 TEST(WTF, StartsWithIgnoringASCIICase) | 326 TEST(WTF, StartsWithIgnoringASCIICase) { |
| 324 { | 327 String allASCII("LINK"); |
| 325 String allASCII("LINK"); | 328 String allASCIILowerCase("link"); |
| 326 String allASCIILowerCase("link"); | 329 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, allASCIILowerCase)); |
| 327 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, allASCIILowerCase)); | 330 String allASCIIMixedCase("lInK"); |
| 328 String allASCIIMixedCase("lInK"); | 331 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, allASCIIMixedCase)); |
| 329 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, allASCIIMixedCase)); | 332 String allASCIIDifferent("foo"); |
| 330 String allASCIIDifferent("foo"); | 333 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, allASCIIDifferent)); |
| 331 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, allASCIIDifferent)); | 334 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA"); |
| 332 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA"); | 335 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII)); |
| 333 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII)); | 336 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower())); |
| 334 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower())); | |
| 335 | 337 |
| 336 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII)); | 338 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII)); |
| 337 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase)); | 339 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase)); |
| 338 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase)); | 340 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase)); |
| 339 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent)); | 341 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent)); |
| 340 } | 342 } |
| 341 | 343 |
| 342 TEST(StringTest, Lower) | 344 TEST(StringTest, Lower) { |
| 343 { | 345 EXPECT_STREQ("link", String("LINK").lower().ascii().data()); |
| 344 EXPECT_STREQ("link", String("LINK").lower().ascii().data()); | 346 EXPECT_STREQ("link", String("lInk").lower().ascii().data()); |
| 345 EXPECT_STREQ("link", String("lInk").lower().ascii().data()); | 347 EXPECT_STREQ("lin\xE1k", String("lIn\xC1k").lower().latin1().data()); |
| 346 EXPECT_STREQ("lin\xE1k", String("lIn\xC1k").lower().latin1().data()); | 348 EXPECT_STREQ("link", String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data()
); |
| 347 EXPECT_STREQ("link", String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data
()); | |
| 348 } | 349 } |
| 349 | 350 |
| 350 } // namespace WTF | 351 } // namespace WTF |
| OLD | NEW |