aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/strings/strings_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/strings/strings_test.go')
-rw-r--r--libgo/go/strings/strings_test.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/libgo/go/strings/strings_test.go b/libgo/go/strings/strings_test.go
index c15aca3..6855ab4 100644
--- a/libgo/go/strings/strings_test.go
+++ b/libgo/go/strings/strings_test.go
@@ -812,7 +812,9 @@ var trimTests = []struct {
{"TrimLeft", "abba", "ab", ""},
{"TrimRight", "abba", "ab", ""},
{"TrimLeft", "abba", "a", "bba"},
+ {"TrimLeft", "abba", "b", "abba"},
{"TrimRight", "abba", "a", "abb"},
+ {"TrimRight", "abba", "b", "abba"},
{"Trim", "<tag>", "<>", "tag"},
{"Trim", "* listitem", " *", "listitem"},
{"Trim", `"quote"`, `"`, "quote"},
@@ -1581,7 +1583,30 @@ var CountTests = []struct {
func TestCount(t *testing.T) {
for _, tt := range CountTests {
if num := Count(tt.s, tt.sep); num != tt.num {
- t.Errorf("Count(\"%s\", \"%s\") = %d, want %d", tt.s, tt.sep, num, tt.num)
+ t.Errorf("Count(%q, %q) = %d, want %d", tt.s, tt.sep, num, tt.num)
+ }
+ }
+}
+
+var cutTests = []struct {
+ s, sep string
+ before, after string
+ found bool
+}{
+ {"abc", "b", "a", "c", true},
+ {"abc", "a", "", "bc", true},
+ {"abc", "c", "ab", "", true},
+ {"abc", "abc", "", "", true},
+ {"abc", "", "", "abc", true},
+ {"abc", "d", "abc", "", false},
+ {"", "d", "", "", false},
+ {"", "", "", "", true},
+}
+
+func TestCut(t *testing.T) {
+ for _, tt := range cutTests {
+ if before, after, found := Cut(tt.s, tt.sep); before != tt.before || after != tt.after || found != tt.found {
+ t.Errorf("Cut(%q, %q) = %q, %q, %v, want %q, %q, %v", tt.s, tt.sep, before, after, found, tt.before, tt.after, tt.found)
}
}
}
@@ -1864,6 +1889,13 @@ func BenchmarkTrimASCII(b *testing.B) {
}
}
+func BenchmarkTrimByte(b *testing.B) {
+ x := " the quick brown fox "
+ for i := 0; i < b.N; i++ {
+ Trim(x, " ")
+ }
+}
+
func BenchmarkIndexPeriodic(b *testing.B) {
key := "aa"
for _, skip := range [...]int{2, 4, 8, 16, 32, 64} {