| 519 | } |
| 520 | |
| 521 | TEST(StringPieceTest, CheckCustom) { |
| 522 | StringPiece a("foobar"); |
| 523 | std::string s1("123"); |
| 524 | s1 += '\0'; |
| 525 | s1 += "456"; |
| 526 | StringPiece b(s1); |
| 527 | StringPiece e; |
| 528 | std::string s2; |
| 529 | |
| 530 | // CopyToString |
| 531 | a.CopyToString(&s2); |
| 532 | ASSERT_EQ(s2.size(), 6U); |
| 533 | ASSERT_EQ(s2, "foobar"); |
| 534 | b.CopyToString(&s2); |
| 535 | ASSERT_EQ(s2.size(), 7U); |
| 536 | ASSERT_EQ(s1, s2); |
| 537 | e.CopyToString(&s2); |
| 538 | ASSERT_TRUE(s2.empty()); |
| 539 | |
| 540 | // AppendToString |
| 541 | s2.erase(); |
| 542 | a.AppendToString(&s2); |
| 543 | ASSERT_EQ(s2.size(), 6U); |
| 544 | ASSERT_EQ(s2, "foobar"); |
| 545 | a.AppendToString(&s2); |
| 546 | ASSERT_EQ(s2.size(), 12U); |
| 547 | ASSERT_EQ(s2, "foobarfoobar"); |
| 548 | |
| 549 | // starts_with |
| 550 | ASSERT_TRUE(a.starts_with(a)); |
| 551 | ASSERT_TRUE(a.starts_with("foo")); |
| 552 | ASSERT_TRUE(a.starts_with(e)); |
| 553 | ASSERT_TRUE(b.starts_with(s1)); |
| 554 | ASSERT_TRUE(b.starts_with(b)); |
| 555 | ASSERT_TRUE(b.starts_with(e)); |
| 556 | ASSERT_TRUE(e.starts_with("")); |
| 557 | ASSERT_TRUE(!a.starts_with(b)); |
| 558 | ASSERT_TRUE(!b.starts_with(a)); |
| 559 | ASSERT_TRUE(!e.starts_with(a)); |
| 560 | |
| 561 | // ends with |
| 562 | ASSERT_TRUE(a.ends_with(a)); |
| 563 | ASSERT_TRUE(a.ends_with("bar")); |
| 564 | ASSERT_TRUE(a.ends_with(e)); |
| 565 | ASSERT_TRUE(b.ends_with(s1)); |
| 566 | ASSERT_TRUE(b.ends_with(b)); |
| 567 | ASSERT_TRUE(b.ends_with(e)); |
| 568 | ASSERT_TRUE(e.ends_with("")); |
| 569 | ASSERT_TRUE(!a.ends_with(b)); |
| 570 | ASSERT_TRUE(!b.ends_with(a)); |
| 571 | ASSERT_TRUE(!e.ends_with(a)); |
| 572 | |
| 573 | StringPiece c; |
| 574 | c.set("foobar", 6); |
| 575 | ASSERT_EQ(c, a); |
| 576 | c.set("foobar", 0); |
| 577 | ASSERT_EQ(c, e); |
| 578 | c.set("foobar", 7); |
nothing calls this directly
no test coverage detected