1
0
mirror of https://github.com/golang/go synced 2024-11-13 19:30:22 -07:00

strings: add test for Count

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12541050
This commit is contained in:
Pieter Droogendijk 2013-08-09 12:51:21 -07:00 committed by Brad Fitzpatrick
parent ecf3274143
commit 14903f6598

View File

@ -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 { func makeBenchInputHard() string {
tokens := [...]string{ tokens := [...]string{
"<a>", "<p>", "<b>", "<strong>", "<a>", "<p>", "<b>", "<strong>",