diff options
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp')
-rw-r--r-- | Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp index 213a655aa..35d64844c 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp @@ -26,6 +26,7 @@ #include "config.h" #include <wtf/text/StringImpl.h> +#include <wtf/text/WTFString.h> namespace TestWebKitAPI { @@ -68,4 +69,48 @@ TEST(WTF, StringImplFromLiteralLoop16BitConversion) } } +TEST(WTF, StringImplReplaceWithLiteral) +{ + RefPtr<StringImpl> testStringImpl = StringImpl::createFromLiteral("1224"); + ASSERT_TRUE(testStringImpl->is8Bit()); + + // Cases for 8Bit source. + testStringImpl = testStringImpl->replace('2', "", 0); + ASSERT_TRUE(equal(testStringImpl.get(), "14")); + + testStringImpl = StringImpl::createFromLiteral("1224"); + ASSERT_TRUE(testStringImpl->is8Bit()); + + testStringImpl = testStringImpl->replace('3', "NotFound", 8); + ASSERT_TRUE(equal(testStringImpl.get(), "1224")); + + testStringImpl = testStringImpl->replace('2', "3", 1); + ASSERT_TRUE(equal(testStringImpl.get(), "1334")); + + testStringImpl = StringImpl::createFromLiteral("1224"); + ASSERT_TRUE(testStringImpl->is8Bit()); + testStringImpl = testStringImpl->replace('2', "555", 3); + ASSERT_TRUE(equal(testStringImpl.get(), "15555554")); + + // Cases for 16Bit source. + String testString = String::fromUTF8("résumé"); + ASSERT_FALSE(testString.impl()->is8Bit()); + + testStringImpl = testString.impl()->replace('2', "NotFound", 8); + ASSERT_TRUE(equal(testStringImpl.get(), String::fromUTF8("résumé").impl())); + + testStringImpl = testString.impl()->replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "e", 1); + ASSERT_TRUE(equal(testStringImpl.get(), "resume")); + + testString = String::fromUTF8("résumé"); + ASSERT_FALSE(testString.impl()->is8Bit()); + testStringImpl = testString.impl()->replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "", 0); + ASSERT_TRUE(equal(testStringImpl.get(), "rsum")); + + testString = String::fromUTF8("résumé"); + ASSERT_FALSE(testString.impl()->is8Bit()); + testStringImpl = testString.impl()->replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "555", 3); + ASSERT_TRUE(equal(testStringImpl.get(), "r555sum555")); +} + } // namespace TestWebKitAPI |