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

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

Issue 2024373002: Replace CSSParserString with StringView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Match arguments to equalStringView. 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // StringView(const UChar* chars, unsigned length); 282 // StringView(const UChar* chars, unsigned length);
283 ASSERT_FALSE(StringView(kChars16, 2).is8Bit()); 283 ASSERT_FALSE(StringView(kChars16, 2).is8Bit());
284 EXPECT_FALSE(StringView(kChars16, 2).isNull()); 284 EXPECT_FALSE(StringView(kChars16, 2).isNull());
285 EXPECT_EQ(kChars16, StringView(kChars16, 2).characters16()); 285 EXPECT_EQ(kChars16, StringView(kChars16, 2).characters16());
286 EXPECT_EQ(StringView("12"), StringView(kChars16, 2)); 286 EXPECT_EQ(StringView("12"), StringView(kChars16, 2));
287 EXPECT_EQ(StringView(reinterpret_cast<const UChar*>(u"12")), StringView(kCha rs16, 2)); 287 EXPECT_EQ(StringView(reinterpret_cast<const UChar*>(u"12")), StringView(kCha rs16, 2));
288 EXPECT_EQ(2u, StringView(kChars16, 2).length()); 288 EXPECT_EQ(2u, StringView(kChars16, 2).length());
289 EXPECT_EQ(String("12"), StringView(kChars16, 2).toString()); 289 EXPECT_EQ(String("12"), StringView(kChars16, 2).toString());
290 } 290 }
291 291
292 TEST(StringViewTest, ConstructionRawBytes)
293 {
294 // StringView(const void* bytes, unsigned length, bool is8Bit);
295 StringView view8(reinterpret_cast<const void*>(kChars), 2, true);
296 ASSERT_TRUE(view8.is8Bit());
297 EXPECT_EQ(2u, view8.length());
298 EXPECT_EQ("12", view8);
299
300 StringView view16(reinterpret_cast<const void*>(kChars16), 3, false);
301 ASSERT_FALSE(view16.is8Bit());
302 EXPECT_EQ(3u, view16.length());
303 EXPECT_EQ("123", view16);
304 }
305
292 TEST(StringViewTest, IsEmpty) 306 TEST(StringViewTest, IsEmpty)
293 { 307 {
294 EXPECT_FALSE(StringView(kChars).isEmpty()); 308 EXPECT_FALSE(StringView(kChars).isEmpty());
295 EXPECT_TRUE(StringView(kChars, 0).isEmpty()); 309 EXPECT_TRUE(StringView(kChars, 0).isEmpty());
296 EXPECT_FALSE(StringView(String(kChars)).isEmpty()); 310 EXPECT_FALSE(StringView(String(kChars)).isEmpty());
297 EXPECT_TRUE(StringView(String(kChars), 5).isEmpty()); 311 EXPECT_TRUE(StringView(String(kChars), 5).isEmpty());
298 EXPECT_TRUE(StringView(String(kChars), 4, 0).isEmpty()); 312 EXPECT_TRUE(StringView(String(kChars), 4, 0).isEmpty());
299 EXPECT_TRUE(StringView().isEmpty()); 313 EXPECT_TRUE(StringView().isEmpty());
300 EXPECT_TRUE(StringView("").isEmpty()); 314 EXPECT_TRUE(StringView("").isEmpty());
301 EXPECT_TRUE(StringView(reinterpret_cast<const UChar*>(u"")).isEmpty()); 315 EXPECT_TRUE(StringView(reinterpret_cast<const UChar*>(u"")).isEmpty());
(...skipping 12 matching lines...) Expand all
314 EXPECT_TRUE(StringView().isNull()); 328 EXPECT_TRUE(StringView().isNull());
315 EXPECT_TRUE(StringView(String()).isNull()); 329 EXPECT_TRUE(StringView(String()).isNull());
316 EXPECT_TRUE(StringView(AtomicString()).isNull()); 330 EXPECT_TRUE(StringView(AtomicString()).isNull());
317 EXPECT_TRUE(StringView(static_cast<const char*>(nullptr)).isNull()); 331 EXPECT_TRUE(StringView(static_cast<const char*>(nullptr)).isNull());
318 StringView view(kChars); 332 StringView view(kChars);
319 EXPECT_FALSE(view.isNull()); 333 EXPECT_FALSE(view.isNull());
320 view.clear(); 334 view.clear();
321 EXPECT_TRUE(view.isNull()); 335 EXPECT_TRUE(view.isNull());
322 EXPECT_EQ(String(), StringView()); 336 EXPECT_EQ(String(), StringView());
323 EXPECT_TRUE(StringView().toString().isNull()); 337 EXPECT_TRUE(StringView().toString().isNull());
338 EXPECT_FALSE(equalStringView(StringView(), ""));
339 EXPECT_TRUE(equalStringView(StringView(), StringView()));
340 EXPECT_FALSE(equalStringView(StringView(), "abc"));
341 EXPECT_FALSE(equalStringView("abc", StringView()));
342 EXPECT_FALSE(equalIgnoringASCIICase(StringView(), ""));
343 EXPECT_TRUE(equalIgnoringASCIICase(StringView(), StringView()));
344 EXPECT_FALSE(equalIgnoringASCIICase(StringView(), "abc"));
345 EXPECT_FALSE(equalIgnoringASCIICase("abc", StringView()));
346 }
347
348 TEST(StringViewTest, IndexAccess)
349 {
350 StringView view8(kChars8);
351 EXPECT_EQ('1', view8[0]);
352 EXPECT_EQ('3', view8[2]);
353 StringView view16(kChars16);
354 EXPECT_EQ('1', view16[0]);
355 EXPECT_EQ('3', view16[2]);
356 }
357
358 TEST(StringViewTest, EqualIgnoringASCIICase)
359 {
360 static const char* link8 = "link";
361 static const char* linkCaps8 = "LINK";
362 static const char* nonASCII8 = "a\xE1";
363 static const char* nonASCIICaps8 = "A\xE1";
364 static const char* nonASCIIInvalid8 = "a\xC1";
365
366 static const UChar link16[5] = { 0x006c, 0x0069, 0x006e, 0x006b, 0 }; // lin k
367 static const UChar linkCaps16[5] = { 0x004c, 0x0049, 0x004e, 0x004b, 0 }; // LINK
368 static const UChar nonASCII16[3] = { 0x0061, 0x00e1, 0 }; // a\xE1
369 static const UChar nonASCIICaps16[3] = { 0x0041, 0x00e1, 0 }; // A\xE1
370 static const UChar nonASCIIInvalid16[3] = { 0x0061, 0x00c1, 0 }; // a\xC1
371
372 EXPECT_TRUE(equalIgnoringASCIICase(StringView(link16), link8));
373 EXPECT_TRUE(equalIgnoringASCIICase(StringView(link16), linkCaps16));
374 EXPECT_TRUE(equalIgnoringASCIICase(StringView(link16), linkCaps8));
375 EXPECT_TRUE(equalIgnoringASCIICase(StringView(link8), linkCaps8));
376 EXPECT_TRUE(equalIgnoringASCIICase(StringView(link8), link16));
377
378 EXPECT_TRUE(equalIgnoringASCIICase(StringView(nonASCII8), nonASCIICaps8));
379 EXPECT_TRUE(equalIgnoringASCIICase(StringView(nonASCII8), nonASCIICaps16));
380 EXPECT_TRUE(equalIgnoringASCIICase(StringView(nonASCII16), nonASCIICaps16));
381 EXPECT_TRUE(equalIgnoringASCIICase(StringView(nonASCII16), nonASCIICaps8));
382 EXPECT_FALSE(equalIgnoringASCIICase(StringView(nonASCII8), nonASCIIInvalid8) );
383 EXPECT_FALSE(equalIgnoringASCIICase(StringView(nonASCII8), nonASCIIInvalid16 ));
384
385 EXPECT_TRUE(equalIgnoringASCIICase(StringView("link"), "lInK"));
386 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "INKL"));
387 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link"), "link different leng th"));
388 EXPECT_FALSE(equalIgnoringASCIICase(StringView("link different length"), "li nk"));
389
390 EXPECT_TRUE(equalIgnoringASCIICase(StringView(""), ""));
324 } 391 }
325 392
326 } // namespace WTF 393 } // 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