]> Cypherpunks repositories - gostls13.git/commitdiff
strings: add test for Count
authorPieter Droogendijk <pieter@binky.org.uk>
Fri, 9 Aug 2013 19:51:21 +0000 (12:51 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 9 Aug 2013 19:51:21 +0000 (12:51 -0700)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12541050

src/pkg/strings/strings_test.go

index 5ffb4e208c92d17d8406162695a99208492d4470..df0dd7165abdc7094573859dd0c98dd7c4fd6165 100644 (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 {
        tokens := [...]string{
                "<a>", "<p>", "<b>", "<strong>",