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
|
|
@ -254,6 +254,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(strings.Bytes(tt.s))
|
||||
result := arrayOfString(a)
|
||||
if !eq(result, 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 byte array.
|
||||
// For ease of creation, we write the byte arrays as strings.
|
||||
type StringTest struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue