diff options
| author | Andrey Mirtchovski <mirtchovski@gmail.com> | 2009-12-15 21:09:55 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-12-15 21:09:55 -0800 |
| commit | 7f501c06f789f2c70623738faaab18e555d26722 (patch) | |
| tree | 647f7903c2ba2fa88fe3b8a203393eabbfff4962 /src/pkg/bytes/bytes_test.go | |
| parent | d5bcf7bf41ee730765e07bf686c7ecc3b0f64d62 (diff) | |
| download | go-7f501c06f789f2c70623738faaab18e555d26722.tar.xz | |
bytes, strings: add new function Fields
R=rsc, r, phf
CC=golang-dev
https://golang.org/cl/170046
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
| -rw-r--r-- | src/pkg/bytes/bytes_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 4c6d4166a0..28ec55e3a9 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -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 { |
