summaryrefslogtreecommitdiff
path: root/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-11-07 11:22:47 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2012-11-07 11:22:47 +0100
commitcfd86b747d32ac22246a1aa908eaa720c63a88c1 (patch)
tree24d68c6f61c464ecba1e05670b80390ea3b0e50c /Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp
parent69d7c744c9de19d152dbe2d8e46eb7dfd4511d1a (diff)
downloadqtwebkit-cfd86b747d32ac22246a1aa908eaa720c63a88c1.tar.gz
Imported WebKit commit 20271caf2e2c016d5cef40184cddeefeac4f1876 (http://svn.webkit.org/repository/webkit/trunk@133733)
New snapshot that contains all previous fixes as well as build fix for latest QtMultimedia API changes.
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp')
-rw-r--r--Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp45
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