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

Side by Side Diff: base/strings/string_util_unittest.cc

Issue 1233043003: Remove some legacy versions of StartsWith and EndsWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « base/strings/string_util.h ('k') | base/test/test_suite.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stdarg.h> 8 #include <stdarg.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 parts.push_back(ASCIIToUTF16("c")); 699 parts.push_back(ASCIIToUTF16("c"));
700 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator)); 700 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator));
701 701
702 parts.push_back(ASCIIToUTF16("")); 702 parts.push_back(ASCIIToUTF16(""));
703 EXPECT_EQ(ASCIIToUTF16("a, b, c, "), JoinString(parts, separator)); 703 EXPECT_EQ(ASCIIToUTF16("a, b, c, "), JoinString(parts, separator));
704 parts.push_back(ASCIIToUTF16(" ")); 704 parts.push_back(ASCIIToUTF16(" "));
705 EXPECT_EQ(ASCIIToUTF16("a|b|c|| "), JoinString(parts, ASCIIToUTF16("|"))); 705 EXPECT_EQ(ASCIIToUTF16("a|b|c|| "), JoinString(parts, ASCIIToUTF16("|")));
706 } 706 }
707 707
708 TEST(StringUtilTest, StartsWith) { 708 TEST(StringUtilTest, StartsWith) {
709 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true)); 709 EXPECT_TRUE(StartsWith("javascript:url", "javascript",
710 EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true)); 710 base::CompareCase::SENSITIVE));
711 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false)); 711 EXPECT_FALSE(StartsWith("JavaScript:url", "javascript",
712 EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false)); 712 base::CompareCase::SENSITIVE));
713 EXPECT_FALSE(StartsWithASCII("java", "javascript", true)); 713 EXPECT_TRUE(StartsWith("javascript:url", "javascript",
714 EXPECT_FALSE(StartsWithASCII("java", "javascript", false)); 714 base::CompareCase::INSENSITIVE_ASCII));
715 EXPECT_FALSE(StartsWithASCII(std::string(), "javascript", false)); 715 EXPECT_TRUE(StartsWith("JavaScript:url", "javascript",
716 EXPECT_FALSE(StartsWithASCII(std::string(), "javascript", true)); 716 base::CompareCase::INSENSITIVE_ASCII));
717 EXPECT_TRUE(StartsWithASCII("java", std::string(), false)); 717 EXPECT_FALSE(StartsWith("java", "javascript", base::CompareCase::SENSITIVE));
718 EXPECT_TRUE(StartsWithASCII("java", std::string(), true)); 718 EXPECT_FALSE(StartsWith("java", "javascript",
719 base::CompareCase::INSENSITIVE_ASCII));
720 EXPECT_FALSE(StartsWith(std::string(), "javascript",
721 base::CompareCase::INSENSITIVE_ASCII));
722 EXPECT_FALSE(StartsWith(std::string(), "javascript",
723 base::CompareCase::SENSITIVE));
724 EXPECT_TRUE(StartsWith("java", std::string(),
725 base::CompareCase::INSENSITIVE_ASCII));
726 EXPECT_TRUE(StartsWith("java", std::string(), base::CompareCase::SENSITIVE));
719 727
720 EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"), 728 EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"),
721 ASCIIToUTF16("javascript"), true)); 729 ASCIIToUTF16("javascript"),
730 base::CompareCase::SENSITIVE));
722 EXPECT_FALSE(StartsWith(ASCIIToUTF16("JavaScript:url"), 731 EXPECT_FALSE(StartsWith(ASCIIToUTF16("JavaScript:url"),
723 ASCIIToUTF16("javascript"), true)); 732 ASCIIToUTF16("javascript"),
733 base::CompareCase::SENSITIVE));
724 EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"), 734 EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"),
725 ASCIIToUTF16("javascript"), false)); 735 ASCIIToUTF16("javascript"),
736 base::CompareCase::INSENSITIVE_ASCII));
726 EXPECT_TRUE(StartsWith(ASCIIToUTF16("JavaScript:url"), 737 EXPECT_TRUE(StartsWith(ASCIIToUTF16("JavaScript:url"),
727 ASCIIToUTF16("javascript"), false)); 738 ASCIIToUTF16("javascript"),
728 EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"), 739 base::CompareCase::INSENSITIVE_ASCII));
729 ASCIIToUTF16("javascript"), true)); 740 EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"), ASCIIToUTF16("javascript"),
730 EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"), 741 base::CompareCase::SENSITIVE));
731 ASCIIToUTF16("javascript"), false)); 742 EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"), ASCIIToUTF16("javascript"),
732 EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"), false)); 743 base::CompareCase::INSENSITIVE_ASCII));
733 EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"), true)); 744 EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"),
734 EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(), false)); 745 base::CompareCase::INSENSITIVE_ASCII));
735 EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(), true)); 746 EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"),
747 base::CompareCase::SENSITIVE));
748 EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(),
749 base::CompareCase::INSENSITIVE_ASCII));
750 EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(),
751 base::CompareCase::SENSITIVE));
736 } 752 }
737 753
738 TEST(StringUtilTest, EndsWith) { 754 TEST(StringUtilTest, EndsWith) {
739 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), 755 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), ASCIIToUTF16(".plugin"),
740 ASCIIToUTF16(".plugin"), true)); 756 base::CompareCase::SENSITIVE));
741 EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.Plugin"), 757 EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.Plugin"), ASCIIToUTF16(".plugin"),
742 ASCIIToUTF16(".plugin"), true)); 758 base::CompareCase::SENSITIVE));
743 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), 759 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), ASCIIToUTF16(".plugin"),
744 ASCIIToUTF16(".plugin"), false)); 760 base::CompareCase::INSENSITIVE_ASCII));
745 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.Plugin"), 761 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.Plugin"), ASCIIToUTF16(".plugin"),
746 ASCIIToUTF16(".plugin"), false)); 762 base::CompareCase::INSENSITIVE_ASCII));
747 EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"), true)); 763 EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"),
748 EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"), false)); 764 base::CompareCase::SENSITIVE));
749 EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"), 765 EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"),
750 ASCIIToUTF16(".plugin"), true)); 766 base::CompareCase::INSENSITIVE_ASCII));
751 EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"), 767 EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"), ASCIIToUTF16(".plugin"),
752 ASCIIToUTF16(".plugin"), false)); 768 base::CompareCase::SENSITIVE));
753 EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), false)); 769 EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"), ASCIIToUTF16(".plugin"),
754 EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), true)); 770 base::CompareCase::INSENSITIVE_ASCII));
755 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), false)); 771 EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"),
756 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), true)); 772 base::CompareCase::INSENSITIVE_ASCII));
757 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), 773 EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"),
758 ASCIIToUTF16(".plugin"), false)); 774 base::CompareCase::SENSITIVE));
759 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"), true)); 775 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(),
760 EXPECT_TRUE(EndsWith(string16(), string16(), false)); 776 base::CompareCase::INSENSITIVE_ASCII));
761 EXPECT_TRUE(EndsWith(string16(), string16(), true)); 777 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(),
778 base::CompareCase::SENSITIVE));
779 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"),
780 base::CompareCase::INSENSITIVE_ASCII));
781 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"),
782 base::CompareCase::SENSITIVE));
783 EXPECT_TRUE(
784 EndsWith(string16(), string16(), base::CompareCase::INSENSITIVE_ASCII));
785 EXPECT_TRUE(EndsWith(string16(), string16(), base::CompareCase::SENSITIVE));
762 } 786 }
763 787
764 TEST(StringUtilTest, GetStringFWithOffsets) { 788 TEST(StringUtilTest, GetStringFWithOffsets) {
765 std::vector<string16> subst; 789 std::vector<string16> subst;
766 subst.push_back(ASCIIToUTF16("1")); 790 subst.push_back(ASCIIToUTF16("1"));
767 subst.push_back(ASCIIToUTF16("2")); 791 subst.push_back(ASCIIToUTF16("2"));
768 std::vector<size_t> offsets; 792 std::vector<size_t> offsets;
769 793
770 ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $1. Your number is $2."), 794 ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $1. Your number is $2."),
771 subst, 795 subst,
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 const std::string live = kLive; 1109 const std::string live = kLive;
1086 std::string dead = live; 1110 std::string dead = live;
1087 strncpy(WriteInto(&dead, 5), kDead, 4); 1111 strncpy(WriteInto(&dead, 5), kDead, 4);
1088 EXPECT_EQ(kDead, dead); 1112 EXPECT_EQ(kDead, dead);
1089 EXPECT_EQ(4u, dead.size()); 1113 EXPECT_EQ(4u, dead.size());
1090 EXPECT_EQ(kLive, live); 1114 EXPECT_EQ(kLive, live);
1091 EXPECT_EQ(4u, live.size()); 1115 EXPECT_EQ(4u, live.size());
1092 } 1116 }
1093 1117
1094 } // namespace base 1118 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | base/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698