mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes, strings: add new function Fields
R=rsc, r, phf CC=golang-dev https://golang.org/cl/170046
This commit is contained in:
parent
d5bcf7bf41
commit
7f501c06f7
4 changed files with 132 additions and 0 deletions
|
|
@ -180,6 +180,36 @@ func TestSplitAfter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type FieldsTest struct {
|
||||
s string
|
||||
a []string
|
||||
}
|
||||
|
||||
var fieldstests = []FieldsTest{
|
||||
FieldsTest{"", []string{}},
|
||||
FieldsTest{" ", []string{}},
|
||||
FieldsTest{" \t ", []string{}},
|
||||
FieldsTest{" abc ", []string{"abc"}},
|
||||
FieldsTest{"1 2 3 4", []string{"1", "2", "3", "4"}},
|
||||
FieldsTest{"1 2 3 4", []string{"1", "2", "3", "4"}},
|
||||
FieldsTest{"1\t\t2\t\t3\t4", []string{"1", "2", "3", "4"}},
|
||||
FieldsTest{"1\u20002\u20013\u20024", []string{"1", "2", "3", "4"}},
|
||||
FieldsTest{"\u2000\u2001\u2002", []string{}},
|
||||
FieldsTest{"\n™\t™\n", []string{"™", "™"}},
|
||||
FieldsTest{faces, []string{faces}},
|
||||
}
|
||||
|
||||
func TestFields(t *testing.T) {
|
||||
for _, tt := range fieldstests {
|
||||
a := Fields(tt.s)
|
||||
if !eq(a, tt.a) {
|
||||
t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test case for any function which accepts and returns a single string.
|
||||
type StringTest struct {
|
||||
in, out string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue