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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "wtf/text/StringView.h" 5 #include "wtf/text/StringView.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "wtf/text/AtomicString.h" 8 #include "wtf/text/AtomicString.h"
9 #include "wtf/text/StringImpl.h" 9 #include "wtf/text/StringImpl.h"
10 #include "wtf/text/WTFString.h" 10 #include "wtf/text/WTFString.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // StringView(StringImpl*, unsigned offset, unsigned length); 65 // StringView(StringImpl*, unsigned offset, unsigned length);
66 ASSERT_FALSE(StringView(impl16Bit.get(), 2, 1).is8Bit()); 66 ASSERT_FALSE(StringView(impl16Bit.get(), 2, 1).is8Bit());
67 EXPECT_FALSE(StringView(impl16Bit.get(), 2, 1).isNull()); 67 EXPECT_FALSE(StringView(impl16Bit.get(), 2, 1).isNull());
68 EXPECT_EQ(impl16Bit->characters16() + 2, StringView(impl16Bit.get(), 2, 1).c haracters16()); 68 EXPECT_EQ(impl16Bit->characters16() + 2, StringView(impl16Bit.get(), 2, 1).c haracters16());
69 EXPECT_EQ(1u, StringView(impl16Bit.get(), 2, 1).length()); 69 EXPECT_EQ(1u, StringView(impl16Bit.get(), 2, 1).length());
70 EXPECT_EQ(StringView("3"), StringView(impl16Bit.get(), 2, 1)); 70 EXPECT_EQ(StringView("3"), StringView(impl16Bit.get(), 2, 1));
71 EXPECT_STREQ("3", StringView(impl16Bit.get(), 2, 1).toString().utf8().data() ); 71 EXPECT_STREQ("3", StringView(impl16Bit.get(), 2, 1).toString().utf8().data() );
72 } 72 }
73 73
74 TEST(StringViewTest, ConstructionStringImplRef8)
75 {
76 RefPtr<StringImpl> impl8Bit = StringImpl::create(kChars8, 5);
77
78 // StringView(StringImpl&);
79 ASSERT_TRUE(StringView(*impl8Bit).is8Bit());
80 EXPECT_FALSE(StringView(*impl8Bit).isNull());
81 EXPECT_EQ(impl8Bit->characters8(), StringView(*impl8Bit).characters8());
82 EXPECT_EQ(impl8Bit->length(), StringView(*impl8Bit).length());
83 EXPECT_STREQ(kChars, StringView(*impl8Bit).toString().utf8().data());
84
85 // StringView(StringImpl&, unsigned offset);
86 ASSERT_TRUE(StringView(*impl8Bit, 2).is8Bit());
87 EXPECT_FALSE(StringView(*impl8Bit, 2).isNull());
88 EXPECT_EQ(impl8Bit->characters8() + 2, StringView(*impl8Bit, 2).characters8( ));
89 EXPECT_EQ(3u, StringView(*impl8Bit, 2).length());
90 EXPECT_EQ(StringView("345"), StringView(*impl8Bit, 2));
91 EXPECT_STREQ("345", StringView(*impl8Bit, 2).toString().utf8().data());
92
93 // StringView(StringImpl&, unsigned offset, unsigned length);
94 ASSERT_TRUE(StringView(*impl8Bit, 2, 1).is8Bit());
95 EXPECT_FALSE(StringView(*impl8Bit, 2, 1).isNull());
96 EXPECT_EQ(impl8Bit->characters8() + 2, StringView(*impl8Bit, 2, 1).character s8());
97 EXPECT_EQ(1u, StringView(*impl8Bit, 2, 1).length());
98 EXPECT_EQ(StringView("3"), StringView(*impl8Bit, 2, 1));
99 EXPECT_STREQ("3", StringView(*impl8Bit, 2, 1).toString().utf8().data());
100 }
101
102 TEST(StringViewTest, ConstructionStringImplRef16)
103 {
104 RefPtr<StringImpl> impl16Bit = StringImpl::create(kChars16, 5);
105
106 // StringView(StringImpl&);
107 ASSERT_FALSE(StringView(*impl16Bit).is8Bit());
108 EXPECT_FALSE(StringView(*impl16Bit).isNull());
109 EXPECT_EQ(impl16Bit->characters16(), StringView(*impl16Bit).characters16());
110 EXPECT_EQ(impl16Bit->length(), StringView(*impl16Bit).length());
111 EXPECT_STREQ(kChars, StringView(*impl16Bit).toString().utf8().data());
112
113 // StringView(StringImpl&, unsigned offset);
114 ASSERT_FALSE(StringView(*impl16Bit, 2).is8Bit());
115 EXPECT_FALSE(StringView(*impl16Bit, 2).isNull());
116 EXPECT_EQ(impl16Bit->characters16() + 2, StringView(*impl16Bit, 2).character s16());
117 EXPECT_EQ(3u, StringView(*impl16Bit, 2).length());
118 EXPECT_EQ(StringView("345"), StringView(*impl16Bit, 2));
119 EXPECT_STREQ("345", StringView(*impl16Bit, 2).toString().utf8().data());
120
121 // StringView(StringImpl&, unsigned offset, unsigned length);
122 ASSERT_FALSE(StringView(*impl16Bit, 2, 1).is8Bit());
123 EXPECT_FALSE(StringView(*impl16Bit, 2, 1).isNull());
124 EXPECT_EQ(impl16Bit->characters16() + 2, StringView(*impl16Bit, 2, 1).charac ters16());
125 EXPECT_EQ(1u, StringView(*impl16Bit, 2, 1).length());
126 EXPECT_EQ(StringView("3"), StringView(*impl16Bit, 2, 1));
127 EXPECT_STREQ("3", StringView(*impl16Bit, 2, 1).toString().utf8().data());
128 }
129
74 TEST(StringViewTest, ConstructionString8) 130 TEST(StringViewTest, ConstructionString8)
75 { 131 {
76 String string8Bit = String(StringImpl::create(kChars8, 5)); 132 String string8Bit = String(StringImpl::create(kChars8, 5));
77 133
78 // StringView(const String&); 134 // StringView(const String&);
79 ASSERT_TRUE(StringView(string8Bit).is8Bit()); 135 ASSERT_TRUE(StringView(string8Bit).is8Bit());
80 EXPECT_FALSE(StringView(string8Bit).isNull()); 136 EXPECT_FALSE(StringView(string8Bit).isNull());
81 EXPECT_EQ(string8Bit.characters8(), StringView(string8Bit).characters8()); 137 EXPECT_EQ(string8Bit.characters8(), StringView(string8Bit).characters8());
82 EXPECT_EQ(string8Bit.length(), StringView(string8Bit).length()); 138 EXPECT_EQ(string8Bit.length(), StringView(string8Bit).length());
83 EXPECT_STREQ(kChars, StringView(string8Bit).toString().utf8().data()); 139 EXPECT_STREQ(kChars, StringView(string8Bit).toString().utf8().data());
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 443
388 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK")); 444 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK"));
389 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL")); 445 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL"));
390 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th")); 446 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th"));
391 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk")); 447 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk"));
392 448
393 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), "")); 449 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), ""));
394 } 450 }
395 451
396 } // namespace WTF 452 } // namespace WTF
OLDNEW
« 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