| 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 12 matching lines...) Expand all Loading... |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "wtf/text/StringImpl.h" | 26 #include "wtf/text/StringImpl.h" |
| 27 | 27 |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "wtf/text/WTFString.h" | 29 #include "wtf/text/WTFString.h" |
| 30 | 30 |
| 31 namespace WTF { | 31 namespace WTF { |
| 32 | 32 |
| 33 TEST(StringImplTest, Create8Bit) | 33 TEST(StringImplTest, Create8Bit) { |
| 34 { | 34 RefPtr<StringImpl> testStringImpl = StringImpl::create("1224"); |
| 35 RefPtr<StringImpl> testStringImpl = StringImpl::create("1224"); | 35 EXPECT_TRUE(testStringImpl->is8Bit()); |
| 36 EXPECT_TRUE(testStringImpl->is8Bit()); | |
| 37 } | 36 } |
| 38 | 37 |
| 39 TEST(StringImplTest, Latin1CaseFoldTable) | 38 TEST(StringImplTest, Latin1CaseFoldTable) { |
| 40 { | 39 LChar symbol = 0xff; |
| 41 LChar symbol = 0xff; | 40 while (symbol--) { |
| 42 while (symbol--) { | 41 EXPECT_EQ(Unicode::foldCase(symbol), |
| 43 EXPECT_EQ(Unicode::foldCase(symbol), StringImpl::latin1CaseFoldTable[sym
bol]); | 42 StringImpl::latin1CaseFoldTable[symbol]); |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 | 45 |
| 47 TEST(StringImplTest, LowerASCII) | 46 TEST(StringImplTest, LowerASCII) { |
| 48 { | 47 RefPtr<StringImpl> testStringImpl = StringImpl::create("link"); |
| 49 RefPtr<StringImpl> testStringImpl = StringImpl::create("link"); | 48 EXPECT_TRUE(testStringImpl->is8Bit()); |
| 50 EXPECT_TRUE(testStringImpl->is8Bit()); | 49 EXPECT_TRUE(StringImpl::create("a\xE1")->is8Bit()); |
| 51 EXPECT_TRUE(StringImpl::create("a\xE1")->is8Bit()); | |
| 52 | 50 |
| 53 EXPECT_TRUE(equal(testStringImpl.get(), StringImpl::create("link")->lowerASC
II().get())); | 51 EXPECT_TRUE(equal(testStringImpl.get(), |
| 54 EXPECT_TRUE(equal(testStringImpl.get(), StringImpl::create("LINK")->lowerASC
II().get())); | 52 StringImpl::create("link")->lowerASCII().get())); |
| 55 EXPECT_TRUE(equal(testStringImpl.get(), StringImpl::create("lInk")->lowerASC
II().get())); | 53 EXPECT_TRUE(equal(testStringImpl.get(), |
| 54 StringImpl::create("LINK")->lowerASCII().get())); |
| 55 EXPECT_TRUE(equal(testStringImpl.get(), |
| 56 StringImpl::create("lInk")->lowerASCII().get())); |
| 56 | 57 |
| 57 EXPECT_TRUE(equal(StringImpl::create("LINK")->lower().get(), StringImpl::cre
ate("LINK")->lowerASCII().get())); | 58 EXPECT_TRUE(equal(StringImpl::create("LINK")->lower().get(), |
| 58 EXPECT_TRUE(equal(StringImpl::create("lInk")->lower().get(), StringImpl::cre
ate("lInk")->lowerASCII().get())); | 59 StringImpl::create("LINK")->lowerASCII().get())); |
| 60 EXPECT_TRUE(equal(StringImpl::create("lInk")->lower().get(), |
| 61 StringImpl::create("lInk")->lowerASCII().get())); |
| 59 | 62 |
| 60 EXPECT_TRUE(equal(StringImpl::create("a\xE1").get(), StringImpl::create("A\x
E1")->lowerASCII().get())); | 63 EXPECT_TRUE(equal(StringImpl::create("a\xE1").get(), |
| 61 EXPECT_TRUE(equal(StringImpl::create("a\xC1").get(), StringImpl::create("A\x
C1")->lowerASCII().get())); | 64 StringImpl::create("A\xE1")->lowerASCII().get())); |
| 65 EXPECT_TRUE(equal(StringImpl::create("a\xC1").get(), |
| 66 StringImpl::create("A\xC1")->lowerASCII().get())); |
| 62 | 67 |
| 63 EXPECT_FALSE(equal(StringImpl::create("a\xE1").get(), StringImpl::create("a\
xC1")->lowerASCII().get())); | 68 EXPECT_FALSE(equal(StringImpl::create("a\xE1").get(), |
| 64 EXPECT_FALSE(equal(StringImpl::create("A\xE1").get(), StringImpl::create("A\
xC1")->lowerASCII().get())); | 69 StringImpl::create("a\xC1")->lowerASCII().get())); |
| 70 EXPECT_FALSE(equal(StringImpl::create("A\xE1").get(), |
| 71 StringImpl::create("A\xC1")->lowerASCII().get())); |
| 65 | 72 |
| 66 static const UChar test[5] = { 0x006c, 0x0069, 0x006e, 0x006b, 0 }; // link | 73 static const UChar test[5] = {0x006c, 0x0069, 0x006e, 0x006b, 0}; // link |
| 67 static const UChar testCapitalized[5] = { 0x004c, 0x0049, 0x004e, 0x004b, 0
}; // LINK | 74 static const UChar testCapitalized[5] = {0x004c, 0x0049, 0x004e, 0x004b, |
| 75 0}; // LINK |
| 68 | 76 |
| 69 RefPtr<StringImpl> testStringImpl16 = StringImpl::create(test, 4); | 77 RefPtr<StringImpl> testStringImpl16 = StringImpl::create(test, 4); |
| 70 EXPECT_FALSE(testStringImpl16->is8Bit()); | 78 EXPECT_FALSE(testStringImpl16->is8Bit()); |
| 71 | 79 |
| 72 EXPECT_TRUE(equal(testStringImpl16.get(), StringImpl::create(test, 4)->lower
ASCII().get())); | 80 EXPECT_TRUE(equal(testStringImpl16.get(), |
| 73 EXPECT_TRUE(equal(testStringImpl16.get(), StringImpl::create(testCapitalized
, 4)->lowerASCII().get())); | 81 StringImpl::create(test, 4)->lowerASCII().get())); |
| 82 EXPECT_TRUE( |
| 83 equal(testStringImpl16.get(), |
| 84 StringImpl::create(testCapitalized, 4)->lowerASCII().get())); |
| 74 | 85 |
| 75 static const UChar testWithNonASCII[3] = { 0x0061, 0x00e1, 0 }; // a\xE1 | 86 static const UChar testWithNonASCII[3] = {0x0061, 0x00e1, 0}; // a\xE1 |
| 76 static const UChar testWithNonASCIIComparison[3] = { 0x0061, 0x00c1, 0 }; //
a\xC1 | 87 static const UChar testWithNonASCIIComparison[3] = {0x0061, 0x00c1, |
| 77 static const UChar testWithNonASCIICapitalized[3] = { 0x0041, 0x00e1, 0 }; /
/ A\xE1 | 88 0}; // a\xC1 |
| 89 static const UChar testWithNonASCIICapitalized[3] = {0x0041, 0x00e1, |
| 90 0}; // A\xE1 |
| 78 | 91 |
| 79 EXPECT_TRUE(equal(StringImpl::create(testWithNonASCII, 2).get(), StringImpl:
:create(testWithNonASCIICapitalized, 2)->lowerASCII().get())); | 92 EXPECT_TRUE(equal( |
| 80 EXPECT_FALSE(equal(StringImpl::create(testWithNonASCII, 2).get(), StringImpl
::create(testWithNonASCIIComparison, 2)->lowerASCII().get())); | 93 StringImpl::create(testWithNonASCII, 2).get(), |
| 94 StringImpl::create(testWithNonASCIICapitalized, 2)->lowerASCII().get())); |
| 95 EXPECT_FALSE(equal( |
| 96 StringImpl::create(testWithNonASCII, 2).get(), |
| 97 StringImpl::create(testWithNonASCIIComparison, 2)->lowerASCII().get())); |
| 81 } | 98 } |
| 82 | 99 |
| 83 } // namespace WTF | 100 } // namespace WTF |
| OLD | NEW |