diff options
author | David Symonds <dsymonds@golang.org> | 2009-06-24 19:02:29 -0700 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2009-06-24 19:02:29 -0700 |
commit | e3fe6186634f9b74b9f39924516e24b068b9e141 (patch) | |
tree | c423ba821d41ea2d673a7420ecf7c082aa827863 /src/pkg/bytes/bytes_test.go | |
parent | c9af30256dfa40f26f2a60e88b68dadfbabdd2ba (diff) | |
download | golang-e3fe6186634f9b74b9f39924516e24b068b9e141.tar.gz |
Change strings.Split, bytes.Split to take a maximum substring count argument.
R=rsc
APPROVED=r
DELTA=131 (39 added, 10 deleted, 82 changed)
OCL=30669
CL=30723
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
-rw-r--r-- | src/pkg/bytes/bytes_test.go | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 3fbe21c30..01adbccfd 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -75,24 +75,25 @@ func TestCompare(t *testing.T) { type ExplodeTest struct { s string; + n int; a []string; } var explodetests = []ExplodeTest { - ExplodeTest{ abcd, []string{"a", "b", "c", "d"} }, - ExplodeTest{ faces, []string{"☺", "☻", "☹" } }, + ExplodeTest{ abcd, 0, []string{"a", "b", "c", "d"} }, + ExplodeTest{ faces, 0, []string{"☺", "☻", "☹"} }, + ExplodeTest{ abcd, 2, []string{"a", "bcd"} }, } func TestExplode(t *testing.T) { - for i := 0; i < len(explodetests); i++ { - tt := explodetests[i]; - a := Explode(io.StringBytes(tt.s)); + for _, tt := range(explodetests) { + a := explode(io.StringBytes(tt.s), tt.n); result := arrayOfString(a); if !eq(result, tt.a) { - t.Errorf(`Explode("%s") = %v; want %v`, tt.s, result, tt.a); + t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a); continue; } s := Join(a, []byte{}); if string(s) != tt.s { - t.Errorf(`Join(Explode("%s"), "") = "%s"`, tt.s, s); + t.Errorf(`Join(Explode("%s", %d), "") = "%s"`, tt.s, tt.n, s); } } } @@ -101,30 +102,35 @@ func TestExplode(t *testing.T) { type SplitTest struct { s string; sep string; + n int; a []string; } var splittests = []SplitTest { - SplitTest{ abcd, "a", []string{"", "bcd"} }, - SplitTest{ abcd, "z", []string{"abcd"} }, - SplitTest{ abcd, "", []string{"a", "b", "c", "d"} }, - SplitTest{ commas, ",", []string{"1", "2", "3", "4"} }, - SplitTest{ dots, "...", []string{"1", ".2", ".3", ".4"} }, - SplitTest{ faces, "☹", []string{"☺☻", ""} }, - SplitTest{ faces, "~", []string{faces} }, - SplitTest{ faces, "", []string{"☺", "☻", "☹"} }, + SplitTest{ abcd, "a", 0, []string{"", "bcd"} }, + SplitTest{ abcd, "z", 0, []string{"abcd"} }, + SplitTest{ abcd, "", 0, []string{"a", "b", "c", "d"} }, + SplitTest{ commas, ",", 0, []string{"1", "2", "3", "4"} }, + SplitTest{ dots, "...", 0, []string{"1", ".2", ".3", ".4"} }, + SplitTest{ faces, "☹", 0, []string{"☺☻", ""} }, + SplitTest{ faces, "~", 0, []string{faces} }, + SplitTest{ faces, "", 0, []string{"☺", "☻", "☹"} }, + SplitTest{ "1 2 3 4", " ", 3, []string{"1", "2", "3 4"} }, + SplitTest{ "1 2 3", " ", 3, []string{"1", "2", "3"} }, + SplitTest{ "1 2", " ", 3, []string{"1", "2"} }, + SplitTest{ "123", "", 2, []string{"1", "23"} }, + SplitTest{ "123", "", 17, []string{"1", "2", "3"} }, } func TestSplit(t *testing.T) { - for i := 0; i < len(splittests); i++ { - tt := splittests[i]; - a := Split(io.StringBytes(tt.s), io.StringBytes(tt.sep)); + for _, tt := range splittests { + a := Split(io.StringBytes(tt.s), io.StringBytes(tt.sep), tt.n); result := arrayOfString(a); if !eq(result, tt.a) { - t.Errorf(`Split("%s", "%s") = %v; want %v`, tt.s, tt.sep, result, tt.a); + t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a); continue; } s := Join(a, io.StringBytes(tt.sep)); if string(s) != tt.s { - t.Errorf(`Join(Split("%s", "%s"), "%s") = "%s"`, tt.s, tt.sep, tt.sep, s); + t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s); } } } |