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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringViewTest.cpp

Issue 2033293002: Implement StringImpl sharing for StringView::toString(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix preload scanner bug. Created 4 years, 6 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
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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 EXPECT_TRUE(StringView(String(kChars), 5).isEmpty()); 311 EXPECT_TRUE(StringView(String(kChars), 5).isEmpty());
312 EXPECT_TRUE(StringView(String(kChars), 4, 0).isEmpty()); 312 EXPECT_TRUE(StringView(String(kChars), 4, 0).isEmpty());
313 EXPECT_TRUE(StringView().isEmpty()); 313 EXPECT_TRUE(StringView().isEmpty());
314 EXPECT_TRUE(StringView("").isEmpty()); 314 EXPECT_TRUE(StringView("").isEmpty());
315 EXPECT_TRUE(StringView(reinterpret_cast<const UChar*>(u"")).isEmpty()); 315 EXPECT_TRUE(StringView(reinterpret_cast<const UChar*>(u"")).isEmpty());
316 EXPECT_FALSE(StringView(kChars16).isEmpty()); 316 EXPECT_FALSE(StringView(kChars16).isEmpty());
317 } 317 }
318 318
319 TEST(StringViewTest, ToString) 319 TEST(StringViewTest, ToString)
320 { 320 {
321 // Empty string optimization.
322 EXPECT_EQ(emptyString().impl(), StringView("").toString().impl()); 321 EXPECT_EQ(emptyString().impl(), StringView("").toString().impl());
322 EXPECT_EQ(nullAtom.impl(), StringView().toString().impl());
323 // NOTE: All the construction tests also check toString(). 323 // NOTE: All the construction tests also check toString().
324 } 324 }
325 325
326 TEST(StringViewTest, ToAtomicString) 326 TEST(StringViewTest, ToAtomicString)
327 { 327 {
328 EXPECT_EQ(AtomicString(), nullAtom); 328 EXPECT_EQ(nullAtom.impl(), StringView().toAtomicString());
329 EXPECT_EQ(AtomicString(""), emptyAtom); 329 EXPECT_EQ(emptyAtom.impl(), StringView("").toAtomicString());
330 EXPECT_EQ(AtomicString("12"), StringView(kChars8, 2).toAtomicString()); 330 EXPECT_EQ(AtomicString("12"), StringView(kChars8, 2).toAtomicString());
331 // AtomicString will convert to 8bit if possible when creating the string. 331 // AtomicString will convert to 8bit if possible when creating the string.
332 EXPECT_EQ(AtomicString("12"), StringView(kChars16, 2).toAtomicString()); 332 EXPECT_EQ(AtomicString("12").impl(), StringView(kChars16, 2).toAtomicString( ).impl());
333 }
334
335 TEST(StringViewTest, ToStringImplSharing)
336 {
337 String string(kChars);
338 EXPECT_EQ(string.impl(), StringView(string).sharedImpl());
339 EXPECT_EQ(string.impl(), StringView(string).toString().impl());
340 EXPECT_EQ(string.impl(), StringView(string).toAtomicString().impl());
333 } 341 }
334 342
335 TEST(StringViewTest, NullString) 343 TEST(StringViewTest, NullString)
336 { 344 {
337 EXPECT_TRUE(StringView().isNull()); 345 EXPECT_TRUE(StringView().isNull());
338 EXPECT_TRUE(StringView(String()).isNull()); 346 EXPECT_TRUE(StringView(String()).isNull());
339 EXPECT_TRUE(StringView(AtomicString()).isNull()); 347 EXPECT_TRUE(StringView(AtomicString()).isNull());
340 EXPECT_TRUE(StringView(static_cast<const char*>(nullptr)).isNull()); 348 EXPECT_TRUE(StringView(static_cast<const char*>(nullptr)).isNull());
341 StringView view(kChars); 349 StringView view(kChars);
342 EXPECT_FALSE(view.isNull()); 350 EXPECT_FALSE(view.isNull());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 401
394 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK")); 402 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK"));
395 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL")); 403 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL"));
396 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th")); 404 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th"));
397 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk")); 405 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk"));
398 406
399 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), "")); 407 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), ""));
400 } 408 }
401 409
402 } // namespace WTF 410 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698