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

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

Issue 2033503002: Add StringView::toAtomicString(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests. 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
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.cpp ('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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 321 // Empty string optimization.
322 EXPECT_EQ(emptyString().impl(), StringView("").toString().impl()); 322 EXPECT_EQ(emptyString().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)
327 {
328 EXPECT_EQ(AtomicString(), nullAtom);
329 EXPECT_EQ(AtomicString(""), emptyAtom);
330 EXPECT_EQ(AtomicString("12"), StringView(kChars8, 2).toAtomicString());
331 // AtomicString will convert to 8bit if possible when creating the string.
332 EXPECT_EQ(AtomicString("12"), StringView(kChars16, 2).toAtomicString());
333 }
334
326 TEST(StringViewTest, NullString) 335 TEST(StringViewTest, NullString)
327 { 336 {
328 EXPECT_TRUE(StringView().isNull()); 337 EXPECT_TRUE(StringView().isNull());
329 EXPECT_TRUE(StringView(String()).isNull()); 338 EXPECT_TRUE(StringView(String()).isNull());
330 EXPECT_TRUE(StringView(AtomicString()).isNull()); 339 EXPECT_TRUE(StringView(AtomicString()).isNull());
331 EXPECT_TRUE(StringView(static_cast<const char*>(nullptr)).isNull()); 340 EXPECT_TRUE(StringView(static_cast<const char*>(nullptr)).isNull());
332 StringView view(kChars); 341 StringView view(kChars);
333 EXPECT_FALSE(view.isNull()); 342 EXPECT_FALSE(view.isNull());
334 view.clear(); 343 view.clear();
335 EXPECT_TRUE(view.isNull()); 344 EXPECT_TRUE(view.isNull());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 393
385 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK")); 394 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK"));
386 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL")); 395 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL"));
387 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th")); 396 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th"));
388 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk")); 397 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk"));
389 398
390 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), "")); 399 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), ""));
391 } 400 }
392 401
393 } // namespace WTF 402 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698