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

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

Issue 1499933003: Use ASCII case-insensitive matching for attribute selectors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WTF -> StringTest Created 5 years 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
« no previous file with comments | « third_party/WebKit/Source/wtf/text/WTFString.h ('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
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) { 313 for (size_t i = 0; i < sizeof(testDataList) / sizeof(testDataList[0]); ++i) {
314 const char* expected = testDataList[i].expected; 314 const char* expected = testDataList[i].expected;
315 String source = String::fromUTF8(testDataList[i].source); 315 String source = String::fromUTF8(testDataList[i].source);
316 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { 316 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) {
317 const char* locale = testDataList[i].localeList[j]; 317 const char* locale = testDataList[i].localeList[j];
318 EXPECT_STREQ(expected, source.lower(locale).utf8().data()) << testDa taList[i].sourceDescription << "; locale=" << locale; 318 EXPECT_STREQ(expected, source.lower(locale).utf8().data()) << testDa taList[i].sourceDescription << "; locale=" << locale;
319 } 319 }
320 } 320 }
321 } 321 }
322 322
323 TEST(WTF, StartsWithIgnoringASCIICase) 323 TEST(StringTest, StartsWithIgnoringASCIICase)
324 { 324 {
325 String allASCII("LINK"); 325 String allASCII("LINK");
326 String allASCIILowerCase("link"); 326 String allASCIILowerCase("link");
327 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, allASCIILowerCase)); 327 EXPECT_TRUE(allASCII.startsWith(allASCIILowerCase, TextCaseASCIIInsensitive) );
328 String allASCIIMixedCase("lInK"); 328 String allASCIIMixedCase("lInK");
329 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, allASCIIMixedCase)); 329 EXPECT_TRUE(allASCII.startsWith(allASCIIMixedCase, TextCaseASCIIInsensitive) );
330 String allASCIIDifferent("foo"); 330 String allASCIIDifferent("foo");
331 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, allASCIIDifferent)); 331 EXPECT_FALSE(allASCII.startsWith(allASCIIDifferent, TextCaseASCIIInsensitive ));
332 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA"); 332 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA");
333 EXPECT_FALSE(startsWithIgnoringASCIICase(allASCII, nonASCII)); 333 EXPECT_FALSE(allASCII.startsWith(nonASCII, TextCaseASCIIInsensitive));
334 EXPECT_TRUE(startsWithIgnoringASCIICase(allASCII, nonASCII.lower())); 334 EXPECT_TRUE(allASCII.startsWith(nonASCII.lower(), TextCaseASCIIInsensitive)) ;
335 335
336 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCII)); 336 EXPECT_FALSE(nonASCII.startsWith(allASCII, TextCaseASCIIInsensitive));
337 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIILowerCase)); 337 EXPECT_FALSE(nonASCII.startsWith(allASCIILowerCase, TextCaseASCIIInsensitive ));
338 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIMixedCase)); 338 EXPECT_FALSE(nonASCII.startsWith(allASCIIMixedCase, TextCaseASCIIInsensitive ));
339 EXPECT_FALSE(startsWithIgnoringASCIICase(nonASCII, allASCIIDifferent)); 339 EXPECT_FALSE(nonASCII.startsWith(allASCIIDifferent, TextCaseASCIIInsensitive ));
340 }
341
342 TEST(StringTest, EndsWithIgnoringASCIICase)
343 {
344 String allASCII("LINK");
345 String allASCIILowerCase("link");
346 EXPECT_TRUE(allASCII.endsWith(allASCIILowerCase, TextCaseASCIIInsensitive));
347 String allASCIIMixedCase("lInK");
348 EXPECT_TRUE(allASCII.endsWith(allASCIIMixedCase, TextCaseASCIIInsensitive));
349 String allASCIIDifferent("foo");
350 EXPECT_FALSE(allASCII.endsWith(allASCIIDifferent, TextCaseASCIIInsensitive)) ;
351 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA");
352 EXPECT_FALSE(allASCII.endsWith(nonASCII, TextCaseASCIIInsensitive));
353 EXPECT_TRUE(allASCII.endsWith(nonASCII.lower(), TextCaseASCIIInsensitive));
354
355 EXPECT_FALSE(nonASCII.endsWith(allASCII, TextCaseASCIIInsensitive));
356 EXPECT_FALSE(nonASCII.endsWith(allASCIILowerCase, TextCaseASCIIInsensitive)) ;
357 EXPECT_FALSE(nonASCII.endsWith(allASCIIMixedCase, TextCaseASCIIInsensitive)) ;
358 EXPECT_FALSE(nonASCII.endsWith(allASCIIDifferent, TextCaseASCIIInsensitive)) ;
359 }
360
361 TEST(StringTest, EqualIgnoringASCIICase)
362 {
363 String allASCII("LINK");
364 String allASCIILowerCase("link");
365 EXPECT_TRUE(equalIgnoringASCIICase(allASCII, allASCIILowerCase));
366 String allASCIIMixedCase("lInK");
367 EXPECT_TRUE(equalIgnoringASCIICase(allASCII, allASCIIMixedCase));
368 String allASCIIDifferent("foo");
369 EXPECT_FALSE(equalIgnoringASCIICase(allASCII, allASCIIDifferent));
370 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA");
371 EXPECT_FALSE(equalIgnoringASCIICase(allASCII, nonASCII));
372 EXPECT_TRUE(equalIgnoringASCIICase(allASCII, nonASCII.lower()));
373
374 EXPECT_FALSE(equalIgnoringASCIICase(nonASCII, allASCII));
375 EXPECT_FALSE(equalIgnoringASCIICase(nonASCII, allASCIILowerCase));
376 EXPECT_FALSE(equalIgnoringASCIICase(nonASCII, allASCIIMixedCase));
377 EXPECT_FALSE(equalIgnoringASCIICase(nonASCII, allASCIIDifferent));
378 }
379
380 TEST(StringTest, FindIgnoringASCIICase)
381 {
382 String needle = String::fromUTF8("a\xCC\x88qa\xCC\x88");
383
384 // Multiple matches, non-overlapping
385 String haystack1 = String::fromUTF8("aA\xCC\x88QA\xCC\x88sA\xCC\x88qa\xCC\x8 8rfi\xC3\xA4q\xC3\xA4");
386 EXPECT_EQ(1u, haystack1.findIgnoringASCIICase(needle));
387 EXPECT_EQ(7u, haystack1.findIgnoringASCIICase(needle, 2));
388 EXPECT_EQ(kNotFound, haystack1.findIgnoringASCIICase(needle, 8));
389
390 // Multiple matches, overlapping
391 String haystack2 = String::fromUTF8("aA\xCC\x88QA\xCC\x88qa\xCC\x88rfi");
392 EXPECT_EQ(1u, haystack2.findIgnoringASCIICase(needle));
393 EXPECT_EQ(4u, haystack2.findIgnoringASCIICase(needle, 2));
394 EXPECT_EQ(kNotFound, haystack2.findIgnoringASCIICase(needle, 5));
340 } 395 }
341 396
342 TEST(StringTest, Lower) 397 TEST(StringTest, Lower)
343 { 398 {
344 EXPECT_STREQ("link", String("LINK").lower().ascii().data()); 399 EXPECT_STREQ("link", String("LINK").lower().ascii().data());
345 EXPECT_STREQ("link", String("lInk").lower().ascii().data()); 400 EXPECT_STREQ("link", String("lInk").lower().ascii().data());
346 EXPECT_STREQ("lin\xE1k", String("lIn\xC1k").lower().latin1().data()); 401 EXPECT_STREQ("lin\xE1k", String("lIn\xC1k").lower().latin1().data());
347 EXPECT_STREQ("link", String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data ()); 402 EXPECT_STREQ("link", String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data ());
348 } 403 }
349 404
350 } // namespace WTF 405 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/WTFString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698