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

Unified Diff: third_party/WebKit/Source/wtf/text/StringViewTest.cpp

Issue 2162863002: Add StringView constructor that takes a ref to save a branch in CSSTokenizerInputStream::rangeAt (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo. Created 4 years, 5 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/StringViewTest.cpp
diff --git a/third_party/WebKit/Source/wtf/text/StringViewTest.cpp b/third_party/WebKit/Source/wtf/text/StringViewTest.cpp
index 6c8c620802fff555f98fc23c250917e54f3d497c..692764bb47e0bb606a1cffecd20759028f6cc883 100644
--- a/third_party/WebKit/Source/wtf/text/StringViewTest.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringViewTest.cpp
@@ -71,6 +71,62 @@ TEST(StringViewTest, ConstructionStringImpl16)
EXPECT_STREQ("3", StringView(impl16Bit.get(), 2, 1).toString().utf8().data());
}
+TEST(StringViewTest, ConstructionStringImplRef8)
+{
+ RefPtr<StringImpl> impl8Bit = StringImpl::create(kChars8, 5);
+
+ // StringView(StringImpl&);
+ ASSERT_TRUE(StringView(*impl8Bit).is8Bit());
+ EXPECT_FALSE(StringView(*impl8Bit).isNull());
+ EXPECT_EQ(impl8Bit->characters8(), StringView(*impl8Bit).characters8());
+ EXPECT_EQ(impl8Bit->length(), StringView(*impl8Bit).length());
+ EXPECT_STREQ(kChars, StringView(*impl8Bit).toString().utf8().data());
+
+ // StringView(StringImpl&, unsigned offset);
+ ASSERT_TRUE(StringView(*impl8Bit, 2).is8Bit());
+ EXPECT_FALSE(StringView(*impl8Bit, 2).isNull());
+ EXPECT_EQ(impl8Bit->characters8() + 2, StringView(*impl8Bit, 2).characters8());
+ EXPECT_EQ(3u, StringView(*impl8Bit, 2).length());
+ EXPECT_EQ(StringView("345"), StringView(*impl8Bit, 2));
+ EXPECT_STREQ("345", StringView(*impl8Bit, 2).toString().utf8().data());
+
+ // StringView(StringImpl&, unsigned offset, unsigned length);
+ ASSERT_TRUE(StringView(*impl8Bit, 2, 1).is8Bit());
+ EXPECT_FALSE(StringView(*impl8Bit, 2, 1).isNull());
+ EXPECT_EQ(impl8Bit->characters8() + 2, StringView(*impl8Bit, 2, 1).characters8());
+ EXPECT_EQ(1u, StringView(*impl8Bit, 2, 1).length());
+ EXPECT_EQ(StringView("3"), StringView(*impl8Bit, 2, 1));
+ EXPECT_STREQ("3", StringView(*impl8Bit, 2, 1).toString().utf8().data());
+}
+
+TEST(StringViewTest, ConstructionStringImplRef16)
+{
+ RefPtr<StringImpl> impl16Bit = StringImpl::create(kChars16, 5);
+
+ // StringView(StringImpl&);
+ ASSERT_FALSE(StringView(*impl16Bit).is8Bit());
+ EXPECT_FALSE(StringView(*impl16Bit).isNull());
+ EXPECT_EQ(impl16Bit->characters16(), StringView(*impl16Bit).characters16());
+ EXPECT_EQ(impl16Bit->length(), StringView(*impl16Bit).length());
+ EXPECT_STREQ(kChars, StringView(*impl16Bit).toString().utf8().data());
+
+ // StringView(StringImpl&, unsigned offset);
+ ASSERT_FALSE(StringView(*impl16Bit, 2).is8Bit());
+ EXPECT_FALSE(StringView(*impl16Bit, 2).isNull());
+ EXPECT_EQ(impl16Bit->characters16() + 2, StringView(*impl16Bit, 2).characters16());
+ EXPECT_EQ(3u, StringView(*impl16Bit, 2).length());
+ EXPECT_EQ(StringView("345"), StringView(*impl16Bit, 2));
+ EXPECT_STREQ("345", StringView(*impl16Bit, 2).toString().utf8().data());
+
+ // StringView(StringImpl&, unsigned offset, unsigned length);
+ ASSERT_FALSE(StringView(*impl16Bit, 2, 1).is8Bit());
+ EXPECT_FALSE(StringView(*impl16Bit, 2, 1).isNull());
+ EXPECT_EQ(impl16Bit->characters16() + 2, StringView(*impl16Bit, 2, 1).characters16());
+ EXPECT_EQ(1u, StringView(*impl16Bit, 2, 1).length());
+ EXPECT_EQ(StringView("3"), StringView(*impl16Bit, 2, 1));
+ EXPECT_STREQ("3", StringView(*impl16Bit, 2, 1).toString().utf8().data());
+}
+
TEST(StringViewTest, ConstructionString8)
{
String string8Bit = String(StringImpl::create(kChars8, 5));
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698