mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
47c4416b7e
commit
ad2c5a4984
2 changed files with 25 additions and 2 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue