Added strings.FieldsFunc, a generalization of strings.Fields in style of the strings.Trim*Func functions.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/824051
This commit is contained in:
Kyle Consalus 2010-04-19 16:36:50 -07:00 committed by Rob Pike
parent 47c4416b7e
commit ad2c5a4984
2 changed files with 25 additions and 2 deletions

View file

@ -222,6 +222,22 @@ func TestFields(t *testing.T) {
}
}
func TestFieldsFunc(t *testing.T) {
pred := func(c int) bool { return c == 'X' }
var fieldsFuncTests = []FieldsTest{
FieldsTest{"", []string{}},
FieldsTest{"XX", []string{}},
FieldsTest{"XXhiXXX", []string{"hi"}},
FieldsTest{"aXXbXXXcX", []string{"a", "b", "c"}},
}
for _, tt := range fieldsFuncTests {
a := FieldsFunc(tt.s, pred)
if !eq(a, tt.a) {
t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a)
}
}
}
// Test case for any function which accepts and returns a single string.
type StringTest struct {