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

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: apply review comments 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
« no previous file with comments | « Source/wtf/text/StringOperatorsTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace {
63
64 void testNumberToStringECMAScript(double number, const char* reference)
63 { 65 {
64 CString numberString = String::numberToStringECMAScript(number).latin1(); 66 CString numberString = String::numberToStringECMAScript(number).latin1();
65 ASSERT_STREQ(reference, numberString.data()); 67 EXPECT_STREQ(reference, numberString.data());
66 } 68 }
67 69
68 TEST(WTF, StringNumberToStringECMAScriptBoundaries) 70 } // anonymous namespace
71
72 TEST(StringTest, NumberToStringECMAScriptBoundaries)
69 { 73 {
70 typedef std::numeric_limits<double> Limits; 74 typedef std::numeric_limits<double> Limits;
71 75
72 // Infinity. 76 // Infinity.
73 testNumberToStringECMAScript(Limits::infinity(), "Infinity"); 77 testNumberToStringECMAScript(Limits::infinity(), "Infinity");
74 testNumberToStringECMAScript(-Limits::infinity(), "-Infinity"); 78 testNumberToStringECMAScript(-Limits::infinity(), "-Infinity");
75 79
76 // NaN. 80 // NaN.
77 testNumberToStringECMAScript(-Limits::quiet_NaN(), "NaN"); 81 testNumberToStringECMAScript(-Limits::quiet_NaN(), "NaN");
78 82
79 // Zeros. 83 // Zeros.
80 testNumberToStringECMAScript(0, "0"); 84 testNumberToStringECMAScript(0, "0");
81 testNumberToStringECMAScript(-0, "0"); 85 testNumberToStringECMAScript(-0, "0");
82 86
83 // Min-Max. 87 // Min-Max.
84 testNumberToStringECMAScript(Limits::min(), "2.2250738585072014e-308"); 88 testNumberToStringECMAScript(Limits::min(), "2.2250738585072014e-308");
85 testNumberToStringECMAScript(Limits::max(), "1.7976931348623157e+308"); 89 testNumberToStringECMAScript(Limits::max(), "1.7976931348623157e+308");
86 } 90 }
87 91
88 TEST(WTF, StringNumberToStringECMAScriptRegularNumbers) 92 TEST(StringTest, NumberToStringECMAScriptRegularNumbers)
89 { 93 {
90 // Pi. 94 // Pi.
91 testNumberToStringECMAScript(piDouble, "3.141592653589793"); 95 testNumberToStringECMAScript(piDouble, "3.141592653589793");
92 testNumberToStringECMAScript(piFloat, "3.1415927410125732"); 96 testNumberToStringECMAScript(piFloat, "3.1415927410125732");
93 testNumberToStringECMAScript(piOverTwoDouble, "1.5707963267948966"); 97 testNumberToStringECMAScript(piOverTwoDouble, "1.5707963267948966");
94 testNumberToStringECMAScript(piOverTwoFloat, "1.5707963705062866"); 98 testNumberToStringECMAScript(piOverTwoFloat, "1.5707963705062866");
95 testNumberToStringECMAScript(piOverFourDouble, "0.7853981633974483"); 99 testNumberToStringECMAScript(piOverFourDouble, "0.7853981633974483");
96 testNumberToStringECMAScript(piOverFourFloat, "0.7853981852531433"); 100 testNumberToStringECMAScript(piOverFourFloat, "0.7853981852531433");
97 101
98 // e. 102 // e.
99 const double e = 2.71828182845904523536028747135266249775724709369995; 103 const double e = 2.71828182845904523536028747135266249775724709369995;
100 testNumberToStringECMAScript(e, "2.718281828459045"); 104 testNumberToStringECMAScript(e, "2.718281828459045");
101 105
102 // c, speed of light in m/s. 106 // c, speed of light in m/s.
103 const double c = 299792458; 107 const double c = 299792458;
104 testNumberToStringECMAScript(c, "299792458"); 108 testNumberToStringECMAScript(c, "299792458");
105 109
106 // Golen ratio. 110 // Golen ratio.
107 const double phi = 1.6180339887498948482; 111 const double phi = 1.6180339887498948482;
108 testNumberToStringECMAScript(phi, "1.618033988749895"); 112 testNumberToStringECMAScript(phi, "1.618033988749895");
109 } 113 }
110 114
111 TEST(WTF, StringReplaceWithLiteral) 115 TEST(StringTest, ReplaceWithLiteral)
112 { 116 {
113 // Cases for 8Bit source. 117 // Cases for 8Bit source.
114 String testString = "1224"; 118 String testString = "1224";
115 ASSERT_TRUE(testString.is8Bit()); 119 EXPECT_TRUE(testString.is8Bit());
116 testString.replaceWithLiteral('2', ""); 120 testString.replaceWithLiteral('2', "");
117 ASSERT_STREQ("14", testString.utf8().data()); 121 EXPECT_STREQ("14", testString.utf8().data());
118 122
119 testString = "1224"; 123 testString = "1224";
120 ASSERT_TRUE(testString.is8Bit()); 124 EXPECT_TRUE(testString.is8Bit());
121 testString.replaceWithLiteral('2', "3"); 125 testString.replaceWithLiteral('2', "3");
122 ASSERT_STREQ("1334", testString.utf8().data()); 126 EXPECT_STREQ("1334", testString.utf8().data());
123 127
124 testString = "1224"; 128 testString = "1224";
125 ASSERT_TRUE(testString.is8Bit()); 129 EXPECT_TRUE(testString.is8Bit());
126 testString.replaceWithLiteral('2', "555"); 130 testString.replaceWithLiteral('2', "555");
127 ASSERT_STREQ("15555554", testString.utf8().data()); 131 EXPECT_STREQ("15555554", testString.utf8().data());
128 132
129 testString = "1224"; 133 testString = "1224";
130 ASSERT_TRUE(testString.is8Bit()); 134 EXPECT_TRUE(testString.is8Bit());
131 testString.replaceWithLiteral('3', "NotFound"); 135 testString.replaceWithLiteral('3', "NotFound");
132 ASSERT_STREQ("1224", testString.utf8().data()); 136 EXPECT_STREQ("1224", testString.utf8().data());
133 137
134 // Cases for 16Bit source. 138 // Cases for 16Bit source.
135 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent. 139 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent.
136 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); 140 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
137 ASSERT_FALSE(testString.is8Bit()); 141 EXPECT_FALSE(testString.is8Bit());
138 testString.replaceWithLiteral(UChar(0x00E9), "e"); 142 testString.replaceWithLiteral(UChar(0x00E9), "e");
139 ASSERT_STREQ("resume", testString.utf8().data()); 143 EXPECT_STREQ("resume", testString.utf8().data());
140 144
141 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); 145 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
142 ASSERT_FALSE(testString.is8Bit()); 146 EXPECT_FALSE(testString.is8Bit());
143 testString.replaceWithLiteral(UChar(0x00E9), ""); 147 testString.replaceWithLiteral(UChar(0x00E9), "");
144 ASSERT_STREQ("rsum", testString.utf8().data()); 148 EXPECT_STREQ("rsum", testString.utf8().data());
145 149
146 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); 150 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
147 ASSERT_FALSE(testString.is8Bit()); 151 EXPECT_FALSE(testString.is8Bit());
148 testString.replaceWithLiteral('3', "NotFound"); 152 testString.replaceWithLiteral('3', "NotFound");
149 ASSERT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data()); 153 EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data());
150 } 154 }
151 155
152 TEST(WTF, StringComparisonOfSameStringVectors) 156 TEST(StringTest, ComparisonOfSameStringVectors)
153 { 157 {
154 Vector<String> stringVector; 158 Vector<String> stringVector;
155 stringVector.append("one"); 159 stringVector.append("one");
156 stringVector.append("two"); 160 stringVector.append("two");
157 161
158 Vector<String> sameStringVector; 162 Vector<String> sameStringVector;
159 sameStringVector.append("one"); 163 sameStringVector.append("one");
160 sameStringVector.append("two"); 164 sameStringVector.append("two");
161 165
162 ASSERT_EQ(stringVector, sameStringVector); 166 EXPECT_EQ(stringVector, sameStringVector);
163 } 167 }
164 168
165 TEST(WTF, SimplifyWhiteSpace) 169 TEST(WTF, SimplifyWhiteSpace)
166 { 170 {
167 String extraSpaces(" Hello world "); 171 String extraSpaces(" Hello world ");
168 ASSERT_EQ(String("Hello world"), extraSpaces.simplifyWhiteSpace()); 172 EXPECT_EQ(String("Hello world"), extraSpaces.simplifyWhiteSpace());
169 ASSERT_EQ(String(" Hello world "), extraSpaces.simplifyWhiteSpace(WTF::Do NotStripWhiteSpace)); 173 EXPECT_EQ(String(" Hello world "), extraSpaces.simplifyWhiteSpace(WTF::Do NotStripWhiteSpace));
170 174
171 String extraSpacesAndNewlines(" \nHello\n world\n "); 175 String extraSpacesAndNewlines(" \nHello\n world\n ");
172 ASSERT_EQ(String("Hello world"), extraSpacesAndNewlines.simplifyWhiteSpace() ); 176 EXPECT_EQ(String("Hello world"), extraSpacesAndNewlines.simplifyWhiteSpace() );
173 ASSERT_EQ(String(" Hello world "), extraSpacesAndNewlines.simplifyWhiteSp ace(WTF::DoNotStripWhiteSpace)); 177 EXPECT_EQ(String(" Hello world "), extraSpacesAndNewlines.simplifyWhiteSp ace(WTF::DoNotStripWhiteSpace));
174 178
175 String extraSpacesAndTabs(" \nHello\t world\t "); 179 String extraSpacesAndTabs(" \nHello\t world\t ");
176 ASSERT_EQ(String("Hello world"), extraSpacesAndTabs.simplifyWhiteSpace()); 180 EXPECT_EQ(String("Hello world"), extraSpacesAndTabs.simplifyWhiteSpace());
177 ASSERT_EQ(String(" Hello world "), extraSpacesAndTabs.simplifyWhiteSpace( WTF::DoNotStripWhiteSpace)); 181 EXPECT_EQ(String(" Hello world "), extraSpacesAndTabs.simplifyWhiteSpace( WTF::DoNotStripWhiteSpace));
178 } 182 }
179 183
180 struct CaseFoldingTestData { 184 struct CaseFoldingTestData {
181 const char* sourceDescription; 185 const char* sourceDescription;
182 const char* source; 186 const char* source;
183 const char** localeList; 187 const char** localeList;
184 size_t localeListLength; 188 size_t localeListLength;
185 const char* expected; 189 const char* expected;
186 }; 190 };
187 191
(...skipping 16 matching lines...) Expand all
204 const char* nonGreekLocales[] = { 208 const char* nonGreekLocales[] = {
205 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", 209 "en", "en-US", "en_US", "en@foo=bar", "EN", "En",
206 "ja", "tr", "az", "fil", "fi", "lt", }; 210 "ja", "tr", "az", "fil", "fi", "lt", };
207 const char* lithuanianLocales[] = { 211 const char* lithuanianLocales[] = {
208 "lt", "lt-LT", "lt_LT", "lt@foo=bar", "lt-US", "LT", "lt-lt", "lT", 212 "lt", "lt-LT", "lt_LT", "lt@foo=bar", "lt-US", "LT", "lt-lt", "lT",
209 }; 213 };
210 // Should not have "tr" or "az" because "lt" and 'tr/az' rules conflict with eac h other. 214 // Should not have "tr" or "az" because "lt" and 'tr/az' rules conflict with eac h other.
211 const char* nonLithuanianLocales[] = { 215 const char* nonLithuanianLocales[] = {
212 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", "ja", "fil", "fi", "el", } ; 216 "en", "en-US", "en_US", "en@foo=bar", "EN", "En", "ja", "fil", "fi", "el", } ;
213 217
214 TEST(WTF, StringToUpperLocale) 218 TEST(StringTest, ToUpperLocale)
215 { 219 {
216 CaseFoldingTestData testDataList[] = { 220 CaseFoldingTestData testDataList[] = {
217 { 221 {
218 "Turkic input", 222 "Turkic input",
219 turkicInput, 223 turkicInput,
220 turkicLocales, 224 turkicLocales,
221 sizeof(turkicLocales) / sizeof(const char*), 225 sizeof(turkicLocales) / sizeof(const char*),
222 "IS\xC4\xB0\xC4\xB0 \xC4\xB0SII", 226 "IS\xC4\xB0\xC4\xB0 \xC4\xB0SII",
223 }, { 227 }, {
224 "Turkic input", 228 "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) { 260 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) {
257 const char* expected = testDataList[i].expected; 261 const char* expected = testDataList[i].expected;
258 String source = String::fromUTF8(testDataList[i].source); 262 String source = String::fromUTF8(testDataList[i].source);
259 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { 263 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) {
260 const char* locale = testDataList[i].localeList[j]; 264 const char* locale = testDataList[i].localeList[j];
261 EXPECT_STREQ(expected, source.upper(locale).utf8().data()) << testDa taList[i].sourceDescription << "; locale=" << locale; 265 EXPECT_STREQ(expected, source.upper(locale).utf8().data()) << testDa taList[i].sourceDescription << "; locale=" << locale;
262 } 266 }
263 } 267 }
264 } 268 }
265 269
266 TEST(WTF, StringToLowerLocale) 270 TEST(StringTest, ToLowerLocale)
267 { 271 {
268 CaseFoldingTestData testDataList[] = { 272 CaseFoldingTestData testDataList[] = {
269 { 273 {
270 "Turkic input", 274 "Turkic input",
271 turkicInput, 275 turkicInput,
272 turkicLocales, 276 turkicLocales,
273 sizeof(turkicLocales) / sizeof(const char*), 277 sizeof(turkicLocales) / sizeof(const char*),
274 "\xC4\xB1sii is\xC4\xB1\xC4\xB1", 278 "\xC4\xB1sii is\xC4\xB1\xC4\xB1",
275 }, { 279 }, {
276 "Turkic input", 280 "Turkic input",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA"); 332 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA");
329 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII)); 333 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII));
330 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower())); 334 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower()));
331 335
332 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII)); 336 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII));
333 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase)); 337 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase));
334 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase)); 338 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase));
335 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent)); 339 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent));
336 } 340 }
337 341
338 } // namespace 342 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/text/StringOperatorsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698