Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: Source/wtf/text/WTFStringTest.cpp

Issue 1184043002: Fix unit test style in Source/wtf/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "wtf/text/WTFString.h"
27 28
28 #include "wtf/MathExtras.h" 29 #include "wtf/MathExtras.h"
29 #include "wtf/text/CString.h" 30 #include "wtf/text/CString.h"
30 #include "wtf/text/WTFString.h"
31 #include <gtest/gtest.h> 31 #include <gtest/gtest.h>
32 #include <limits> 32 #include <limits>
33 33
34 namespace { 34 namespace WTF {
35 35
36 TEST(WTF, StringCreationFromLiteral) 36 TEST(StringTest, CreationFromLiteral)
37 { 37 {
38 String stringFromLiteral("Explicit construction syntax"); 38 String stringFromLiteral("Explicit construction syntax");
39 ASSERT_EQ(strlen("Explicit construction syntax"), stringFromLiteral.length() ); 39 EXPECT_EQ(strlen("Explicit construction syntax"), stringFromLiteral.length() );
40 ASSERT_TRUE(stringFromLiteral == "Explicit construction syntax"); 40 EXPECT_TRUE(stringFromLiteral == "Explicit construction syntax");
41 ASSERT_TRUE(stringFromLiteral.is8Bit()); 41 EXPECT_TRUE(stringFromLiteral.is8Bit());
42 ASSERT_TRUE(String("Explicit construction syntax") == stringFromLiteral); 42 EXPECT_TRUE(String("Explicit construction syntax") == stringFromLiteral);
43 } 43 }
44 44
45 TEST(WTF, StringASCII) 45 TEST(StringTest, ASCII)
46 { 46 {
47 CString output; 47 CString output;
48 48
49 // Null String. 49 // Null String.
50 output = String().ascii(); 50 output = String().ascii();
51 ASSERT_STREQ("", output.data()); 51 EXPECT_STREQ("", output.data());
52 52
53 // Empty String. 53 // Empty String.
54 output = emptyString().ascii(); 54 output = emptyString().ascii();
55 ASSERT_STREQ("", output.data()); 55 EXPECT_STREQ("", output.data());
56 56
57 // Regular String. 57 // Regular String.
58 output = String("foobar").ascii(); 58 output = String("foobar").ascii();
59 ASSERT_STREQ("foobar", output.data()); 59 EXPECT_STREQ("foobar", output.data());
60 } 60 }
61 61
62 static void testNumberToStringECMAScript(double number, const char* reference) 62 static void testNumberToStringECMAScript(double number, const char* reference)
kochi 2015/06/15 03:34:22 Use anonymous namespace?
tkent 2015/06/15 04:45:57 Done.
63 { 63 {
64 CString numberString = String::numberToStringECMAScript(number).latin1(); 64 CString numberString = String::numberToStringECMAScript(number).latin1();
65 ASSERT_STREQ(reference, numberString.data()); 65 EXPECT_STREQ(reference, numberString.data());
66 } 66 }
67 67
68 TEST(WTF, StringNumberToStringECMAScriptBoundaries) 68 TEST(StringTest, NumberToStringECMAScriptBoundaries)
69 { 69 {
70 typedef std::numeric_limits<double> Limits; 70 typedef std::numeric_limits<double> Limits;
71 71
72 // Infinity. 72 // Infinity.
73 testNumberToStringECMAScript(Limits::infinity(), "Infinity"); 73 testNumberToStringECMAScript(Limits::infinity(), "Infinity");
74 testNumberToStringECMAScript(-Limits::infinity(), "-Infinity"); 74 testNumberToStringECMAScript(-Limits::infinity(), "-Infinity");
75 75
76 // NaN. 76 // NaN.
77 testNumberToStringECMAScript(-Limits::quiet_NaN(), "NaN"); 77 testNumberToStringECMAScript(-Limits::quiet_NaN(), "NaN");
78 78
79 // Zeros. 79 // Zeros.
80 testNumberToStringECMAScript(0, "0"); 80 testNumberToStringECMAScript(0, "0");
81 testNumberToStringECMAScript(-0, "0"); 81 testNumberToStringECMAScript(-0, "0");
82 82
83 // Min-Max. 83 // Min-Max.
84 testNumberToStringECMAScript(Limits::min(), "2.2250738585072014e-308"); 84 testNumberToStringECMAScript(Limits::min(), "2.2250738585072014e-308");
85 testNumberToStringECMAScript(Limits::max(), "1.7976931348623157e+308"); 85 testNumberToStringECMAScript(Limits::max(), "1.7976931348623157e+308");
86 } 86 }
87 87
88 TEST(WTF, StringNumberToStringECMAScriptRegularNumbers) 88 TEST(StringTest, NumberToStringECMAScriptRegularNumbers)
89 { 89 {
90 // Pi. 90 // Pi.
91 testNumberToStringECMAScript(piDouble, "3.141592653589793"); 91 testNumberToStringECMAScript(piDouble, "3.141592653589793");
92 testNumberToStringECMAScript(piFloat, "3.1415927410125732"); 92 testNumberToStringECMAScript(piFloat, "3.1415927410125732");
93 testNumberToStringECMAScript(piOverTwoDouble, "1.5707963267948966"); 93 testNumberToStringECMAScript(piOverTwoDouble, "1.5707963267948966");
94 testNumberToStringECMAScript(piOverTwoFloat, "1.5707963705062866"); 94 testNumberToStringECMAScript(piOverTwoFloat, "1.5707963705062866");
95 testNumberToStringECMAScript(piOverFourDouble, "0.7853981633974483"); 95 testNumberToStringECMAScript(piOverFourDouble, "0.7853981633974483");
96 testNumberToStringECMAScript(piOverFourFloat, "0.7853981852531433"); 96 testNumberToStringECMAScript(piOverFourFloat, "0.7853981852531433");
97 97
98 // e. 98 // e.
99 const double e = 2.71828182845904523536028747135266249775724709369995; 99 const double e = 2.71828182845904523536028747135266249775724709369995;
100 testNumberToStringECMAScript(e, "2.718281828459045"); 100 testNumberToStringECMAScript(e, "2.718281828459045");
101 101
102 // c, speed of light in m/s. 102 // c, speed of light in m/s.
103 const double c = 299792458; 103 const double c = 299792458;
104 testNumberToStringECMAScript(c, "299792458"); 104 testNumberToStringECMAScript(c, "299792458");
105 105
106 // Golen ratio. 106 // Golen ratio.
107 const double phi = 1.6180339887498948482; 107 const double phi = 1.6180339887498948482;
108 testNumberToStringECMAScript(phi, "1.618033988749895"); 108 testNumberToStringECMAScript(phi, "1.618033988749895");
109 } 109 }
110 110
111 TEST(WTF, StringReplaceWithLiteral) 111 TEST(StringTest, ReplaceWithLiteral)
112 { 112 {
113 // Cases for 8Bit source. 113 // Cases for 8Bit source.
114 String testString = "1224"; 114 String testString = "1224";
115 ASSERT_TRUE(testString.is8Bit()); 115 EXPECT_TRUE(testString.is8Bit());
116 testString.replaceWithLiteral('2', ""); 116 testString.replaceWithLiteral('2', "");
117 ASSERT_STREQ("14", testString.utf8().data()); 117 EXPECT_STREQ("14", testString.utf8().data());
118 118
119 testString = "1224"; 119 testString = "1224";
120 ASSERT_TRUE(testString.is8Bit()); 120 EXPECT_TRUE(testString.is8Bit());
121 testString.replaceWithLiteral('2', "3"); 121 testString.replaceWithLiteral('2', "3");
122 ASSERT_STREQ("1334", testString.utf8().data()); 122 EXPECT_STREQ("1334", testString.utf8().data());
123 123
124 testString = "1224"; 124 testString = "1224";
125 ASSERT_TRUE(testString.is8Bit()); 125 EXPECT_TRUE(testString.is8Bit());
126 testString.replaceWithLiteral('2', "555"); 126 testString.replaceWithLiteral('2', "555");
127 ASSERT_STREQ("15555554", testString.utf8().data()); 127 EXPECT_STREQ("15555554", testString.utf8().data());
128 128
129 testString = "1224"; 129 testString = "1224";
130 ASSERT_TRUE(testString.is8Bit()); 130 EXPECT_TRUE(testString.is8Bit());
131 testString.replaceWithLiteral('3', "NotFound"); 131 testString.replaceWithLiteral('3', "NotFound");
132 ASSERT_STREQ("1224", testString.utf8().data()); 132 EXPECT_STREQ("1224", testString.utf8().data());
133 133
134 // Cases for 16Bit source. 134 // Cases for 16Bit source.
135 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent. 135 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent.
136 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); 136 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
137 ASSERT_FALSE(testString.is8Bit()); 137 EXPECT_FALSE(testString.is8Bit());
138 testString.replaceWithLiteral(UChar(0x00E9), "e"); 138 testString.replaceWithLiteral(UChar(0x00E9), "e");
139 ASSERT_STREQ("resume", testString.utf8().data()); 139 EXPECT_STREQ("resume", testString.utf8().data());
140 140
141 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); 141 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
142 ASSERT_FALSE(testString.is8Bit()); 142 EXPECT_FALSE(testString.is8Bit());
143 testString.replaceWithLiteral(UChar(0x00E9), ""); 143 testString.replaceWithLiteral(UChar(0x00E9), "");
144 ASSERT_STREQ("rsum", testString.utf8().data()); 144 EXPECT_STREQ("rsum", testString.utf8().data());
145 145
146 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); 146 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
147 ASSERT_FALSE(testString.is8Bit()); 147 EXPECT_FALSE(testString.is8Bit());
148 testString.replaceWithLiteral('3', "NotFound"); 148 testString.replaceWithLiteral('3', "NotFound");
149 ASSERT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data()); 149 EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data());
150 } 150 }
151 151
152 TEST(WTF, StringComparisonOfSameStringVectors) 152 TEST(StringTest, ComparisonOfSameStringVectors)
153 { 153 {
154 Vector<String> stringVector; 154 Vector<String> stringVector;
155 stringVector.append("one"); 155 stringVector.append("one");
156 stringVector.append("two"); 156 stringVector.append("two");
157 157
158 Vector<String> sameStringVector; 158 Vector<String> sameStringVector;
159 sameStringVector.append("one"); 159 sameStringVector.append("one");
160 sameStringVector.append("two"); 160 sameStringVector.append("two");
161 161
162 ASSERT_EQ(stringVector, sameStringVector); 162 EXPECT_EQ(stringVector, sameStringVector);
163 } 163 }
164 164
165 TEST(WTF, SimplifyWhiteSpace) 165 TEST(WTF, SimplifyWhiteSpace)
166 { 166 {
167 String extraSpaces(" Hello world "); 167 String extraSpaces(" Hello world ");
168 ASSERT_EQ(String("Hello world"), extraSpaces.simplifyWhiteSpace()); 168 EXPECT_EQ(String("Hello world"), extraSpaces.simplifyWhiteSpace());
169 ASSERT_EQ(String(" Hello world "), extraSpaces.simplifyWhiteSpace(WTF::Do NotStripWhiteSpace)); 169 EXPECT_EQ(String(" Hello world "), extraSpaces.simplifyWhiteSpace(WTF::Do NotStripWhiteSpace));
170 170
171 String extraSpacesAndNewlines(" \nHello\n world\n "); 171 String extraSpacesAndNewlines(" \nHello\n world\n ");
172 ASSERT_EQ(String("Hello world"), extraSpacesAndNewlines.simplifyWhiteSpace() ); 172 EXPECT_EQ(String("Hello world"), extraSpacesAndNewlines.simplifyWhiteSpace() );
173 ASSERT_EQ(String(" Hello world "), extraSpacesAndNewlines.simplifyWhiteSp ace(WTF::DoNotStripWhiteSpace)); 173 EXPECT_EQ(String(" Hello world "), extraSpacesAndNewlines.simplifyWhiteSp ace(WTF::DoNotStripWhiteSpace));
174 174
175 String extraSpacesAndTabs(" \nHello\t world\t "); 175 String extraSpacesAndTabs(" \nHello\t world\t ");
176 ASSERT_EQ(String("Hello world"), extraSpacesAndTabs.simplifyWhiteSpace()); 176 EXPECT_EQ(String("Hello world"), extraSpacesAndTabs.simplifyWhiteSpace());
177 ASSERT_EQ(String(" Hello world "), extraSpacesAndTabs.simplifyWhiteSpace( WTF::DoNotStripWhiteSpace)); 177 EXPECT_EQ(String(" Hello world "), extraSpacesAndTabs.simplifyWhiteSpace( WTF::DoNotStripWhiteSpace));
178 } 178 }
179 179
180 struct CaseFoldingTestData { 180 struct CaseFoldingTestData {
181 const char* sourceDescription; 181 const char* sourceDescription;
182 const char* source; 182 const char* source;
183 const char** localeList; 183 const char** localeList;
184 size_t localeListLength; 184 size_t localeListLength;
185 const char* expected; 185 const char* expected;
186 }; 186 };
187 187
(...skipping 16 matching lines...) Expand all
204 const char* nonGreekLocales[] = { 204 const char* nonGreekLocales[] = {
205 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", 205 "en", "en-US", "en_US", "en@foo=bar", "EN", "En",
206 "ja", "tr", "az", "fil", "fi", "lt", }; 206 "ja", "tr", "az", "fil", "fi", "lt", };
207 const char* lithuanianLocales[] = { 207 const char* lithuanianLocales[] = {
208 "lt", "lt-LT", "lt_LT", "lt@foo=bar", "lt-US", "LT", "lt-lt", "lT", 208 "lt", "lt-LT", "lt_LT", "lt@foo=bar", "lt-US", "LT", "lt-lt", "lT",
209 }; 209 };
210 // Should not have "tr" or "az" because "lt" and 'tr/az' rules conflict with eac h other. 210 // Should not have "tr" or "az" because "lt" and 'tr/az' rules conflict with eac h other.
211 const char* nonLithuanianLocales[] = { 211 const char* nonLithuanianLocales[] = {
212 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", "ja", "fil", "fi", "el", } ; 212 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", "ja", "fil", "fi", "el", } ;
213 213
214 TEST(WTF, StringToUpperLocale) 214 TEST(StringTest, ToUpperLocale)
215 { 215 {
216 CaseFoldingTestData testDataList[] = { 216 CaseFoldingTestData testDataList[] = {
217 { 217 {
218 "Turkic input", 218 "Turkic input",
219 turkicInput, 219 turkicInput,
220 turkicLocales, 220 turkicLocales,
221 sizeof(turkicLocales) / sizeof(const char*), 221 sizeof(turkicLocales) / sizeof(const char*),
222 "IS\xC4\xB0\xC4\xB0 \xC4\xB0SII", 222 "IS\xC4\xB0\xC4\xB0 \xC4\xB0SII",
223 }, { 223 }, {
224 "Turkic input", 224 "Turkic input",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) { 256 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) {
257 const char* expected = testDataList[i].expected; 257 const char* expected = testDataList[i].expected;
258 String source = String::fromUTF8(testDataList[i].source); 258 String source = String::fromUTF8(testDataList[i].source);
259 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { 259 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) {
260 const char* locale = testDataList[i].localeList[j]; 260 const char* locale = testDataList[i].localeList[j];
261 EXPECT_STREQ(expected, source.upper(locale).utf8().data()) << testDa taList[i].sourceDescription << "; locale=" << locale; 261 EXPECT_STREQ(expected, source.upper(locale).utf8().data()) << testDa taList[i].sourceDescription << "; locale=" << locale;
262 } 262 }
263 } 263 }
264 } 264 }
265 265
266 TEST(WTF, StringToLowerLocale) 266 TEST(StringTest, ToLowerLocale)
267 { 267 {
268 CaseFoldingTestData testDataList[] = { 268 CaseFoldingTestData testDataList[] = {
269 { 269 {
270 "Turkic input", 270 "Turkic input",
271 turkicInput, 271 turkicInput,
272 turkicLocales, 272 turkicLocales,
273 sizeof(turkicLocales) / sizeof(const char*), 273 sizeof(turkicLocales) / sizeof(const char*),
274 "\xC4\xB1sii is\xC4\xB1\xC4\xB1", 274 "\xC4\xB1sii is\xC4\xB1\xC4\xB1",
275 }, { 275 }, {
276 "Turkic input", 276 "Turkic input",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA"); 328 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA");
329 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII)); 329 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII));
330 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower())); 330 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower()));
331 331
332 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII)); 332 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII));
333 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase)); 333 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase));
334 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase)); 334 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase));
335 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent)); 335 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent));
336 } 336 }
337 337
338 } // namespace 338 } // namespace WTF
OLDNEW
« Source/wtf/text/StringBuilderTest.cpp ('K') | « Source/wtf/text/StringOperatorsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698