aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings
diff options
context:
space:
mode:
authorPieter Droogendijk <pieter@binky.org.uk>2013-08-09 12:51:21 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2013-08-09 12:51:21 -0700
commit14903f65984a113d2558195b2dd862368d1c96ef (patch)
tree2ae617a3756c54c1306d9f79f2233f7e73e92cc4 /src/pkg/strings
parentecf3274143a512153b4b85b77a06aacd620fcfa9 (diff)
downloadgo-14903f65984a113d2558195b2dd862368d1c96ef.tar.xz
strings: add test for Count
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12541050
Diffstat (limited to 'src/pkg/strings')
-rw-r--r--src/pkg/strings/strings_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go
index 5ffb4e208c..df0dd7165a 100644
--- a/src/pkg/strings/strings_test.go
+++ b/src/pkg/strings/strings_test.go
@@ -1010,6 +1010,30 @@ func TestEqualFold(t *testing.T) {
}
}
+var CountTests = []struct {
+ s, sep string
+ num int
+}{
+ {"", "", 1},
+ {"", "notempty", 0},
+ {"notempty", "", 9},
+ {"smaller", "not smaller", 0},
+ {"12345678987654321", "6", 2},
+ {"611161116", "6", 3},
+ {"notequal", "NotEqual", 0},
+ {"equal", "equal", 1},
+ {"abc1231231123q", "123", 3},
+ {"11111", "11", 2},
+}
+
+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)
+ }
+ }
+}
+
func makeBenchInputHard() string {
tokens := [...]string{
"<a>", "<p>", "<b>", "<strong>",