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

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

Issue 2508953003: WTF: Add comments and tests for Unicode aware case-insensitive string operations. (Closed)
Patch Set: Created 4 years, 1 month 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 const char* expected = testDataList[i].expected; 329 const char* expected = testDataList[i].expected;
330 String source = String::fromUTF8(testDataList[i].source); 330 String source = String::fromUTF8(testDataList[i].source);
331 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) { 331 for (size_t j = 0; j < testDataList[i].localeListLength; ++j) {
332 const char* locale = testDataList[i].localeList[j]; 332 const char* locale = testDataList[i].localeList[j];
333 EXPECT_STREQ(expected, source.lower(locale).utf8().data()) 333 EXPECT_STREQ(expected, source.lower(locale).utf8().data())
334 << testDataList[i].sourceDescription << "; locale=" << locale; 334 << testDataList[i].sourceDescription << "; locale=" << locale;
335 } 335 }
336 } 336 }
337 } 337 }
338 338
339 TEST(StringTest, StartsWithIgnoringUnicodeCase) {
340 // [U+017F U+212A i a] starts with "sk".
341 EXPECT_TRUE(String::fromUTF8("\xC5\xBF\xE2\x84\xAAia")
342 .startsWith("sk", TextCaseInsensitive));
343 }
344
339 TEST(StringTest, StartsWithIgnoringASCIICase) { 345 TEST(StringTest, StartsWithIgnoringASCIICase) {
340 String allASCII("LINK"); 346 String allASCII("LINK");
341 String allASCIILowerCase("link"); 347 String allASCIILowerCase("link");
342 EXPECT_TRUE(allASCII.startsWith(allASCIILowerCase, TextCaseASCIIInsensitive)); 348 EXPECT_TRUE(allASCII.startsWith(allASCIILowerCase, TextCaseASCIIInsensitive));
343 String allASCIIMixedCase("lInK"); 349 String allASCIIMixedCase("lInK");
344 EXPECT_TRUE(allASCII.startsWith(allASCIIMixedCase, TextCaseASCIIInsensitive)); 350 EXPECT_TRUE(allASCII.startsWith(allASCIIMixedCase, TextCaseASCIIInsensitive));
345 String allASCIIDifferent("foo"); 351 String allASCIIDifferent("foo");
346 EXPECT_FALSE( 352 EXPECT_FALSE(
347 allASCII.startsWith(allASCIIDifferent, TextCaseASCIIInsensitive)); 353 allASCII.startsWith(allASCIIDifferent, TextCaseASCIIInsensitive));
348 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA"); 354 String nonASCII = String::fromUTF8("LIN\xE2\x84\xAA");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 String haystack2 = String::fromUTF8("aA\xCC\x88QA\xCC\x88qa\xCC\x88rfi"); 414 String haystack2 = String::fromUTF8("aA\xCC\x88QA\xCC\x88qa\xCC\x88rfi");
409 EXPECT_EQ(1u, haystack2.findIgnoringASCIICase(needle)); 415 EXPECT_EQ(1u, haystack2.findIgnoringASCIICase(needle));
410 EXPECT_EQ(4u, haystack2.findIgnoringASCIICase(needle, 2)); 416 EXPECT_EQ(4u, haystack2.findIgnoringASCIICase(needle, 2));
411 EXPECT_EQ(kNotFound, haystack2.findIgnoringASCIICase(needle, 5)); 417 EXPECT_EQ(kNotFound, haystack2.findIgnoringASCIICase(needle, 5));
412 } 418 }
413 419
414 TEST(StringTest, Lower) { 420 TEST(StringTest, Lower) {
415 EXPECT_STREQ("link", String("LINK").lower().ascii().data()); 421 EXPECT_STREQ("link", String("LINK").lower().ascii().data());
416 EXPECT_STREQ("link", String("lInk").lower().ascii().data()); 422 EXPECT_STREQ("link", String("lInk").lower().ascii().data());
417 EXPECT_STREQ("lin\xE1k", String("lIn\xC1k").lower().latin1().data()); 423 EXPECT_STREQ("lin\xE1k", String("lIn\xC1k").lower().latin1().data());
424 // U+212A -> k
418 EXPECT_STREQ("link", 425 EXPECT_STREQ("link",
419 String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data()); 426 String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data());
420 } 427 }
421 428
429 TEST(StringTest, Upper) {
430 EXPECT_STREQ("CROSS", String("cross").upper().utf8().data());
431 // U+017F -> S
432 EXPECT_STREQ("CROSS", String::fromUTF8("cro\xC5\xBFs").upper().utf8().data());
433 }
434
422 TEST(StringTest, Ensure16Bit) { 435 TEST(StringTest, Ensure16Bit) {
423 String string8("8bit"); 436 String string8("8bit");
424 EXPECT_TRUE(string8.is8Bit()); 437 EXPECT_TRUE(string8.is8Bit());
425 string8.ensure16Bit(); 438 string8.ensure16Bit();
426 EXPECT_FALSE(string8.is8Bit()); 439 EXPECT_FALSE(string8.is8Bit());
427 EXPECT_EQ("8bit", string8); 440 EXPECT_EQ("8bit", string8);
428 441
429 String string16(reinterpret_cast<const UChar*>(u"16bit")); 442 String string16(reinterpret_cast<const UChar*>(u"16bit"));
430 EXPECT_FALSE(string16.is8Bit()); 443 EXPECT_FALSE(string16.is8Bit());
431 string16.ensure16Bit(); 444 string16.ensure16Bit();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 EXPECT_EQ(CString("<null>"), toCStringThroughPrinter(String())); 493 EXPECT_EQ(CString("<null>"), toCStringThroughPrinter(String()));
481 494
482 static const UChar unicodeSample[] = {0x30C6, 0x30B9, 495 static const UChar unicodeSample[] = {0x30C6, 0x30B9,
483 0x30C8}; // "Test" in Japanese. 496 0x30C8}; // "Test" in Japanese.
484 EXPECT_EQ(CString("\"\\u30C6\\u30B9\\u30C8\""), 497 EXPECT_EQ(CString("\"\\u30C6\\u30B9\\u30C8\""),
485 toCStringThroughPrinter( 498 toCStringThroughPrinter(
486 String(unicodeSample, WTF_ARRAY_LENGTH(unicodeSample)))); 499 String(unicodeSample, WTF_ARRAY_LENGTH(unicodeSample))));
487 } 500 }
488 501
489 } // namespace WTF 502 } // 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