diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2019-04-02 22:38:39 +0200 |
---|---|---|
committer | Tobias Klauser <tobias.klauser@gmail.com> | 2019-04-03 14:46:01 +0000 |
commit | 94507d2213fbd0a5e3b5276904f41c6bc0e03aba (patch) | |
tree | 224766cb5fe0081ffe118ab49f379d5eadcdd2ce /src/bytes | |
parent | e014184c438699b1637b1d623492f33669105002 (diff) | |
download | go-94507d2213fbd0a5e3b5276904f41c6bc0e03aba.tar.gz go-94507d2213fbd0a5e3b5276904f41c6bc0e03aba.zip |
bytes: merge explodetests into splittests
splittests already contains most of the tests that cover explode. Add
the missing ones and skip the append test for empty results which would
otherwise lead to an "index out of range" panic.
Change-Id: I2cb922282d2676be9ef85f186513075ae17c0243
Reviewed-on: https://go-review.googlesource.com/c/go/+/170126
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/bytes')
-rw-r--r-- | src/bytes/bytes_test.go | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go index 4b000a3d2b..d760d4b52a 100644 --- a/src/bytes/bytes_test.go +++ b/src/bytes/bytes_test.go @@ -677,34 +677,6 @@ func BenchmarkCountSingle(b *testing.B) { }) } -type ExplodeTest struct { - s string - n int - a []string -} - -var explodetests = []ExplodeTest{ - {"", -1, []string{}}, - {abcd, -1, []string{"a", "b", "c", "d"}}, - {faces, -1, []string{"☺", "☻", "☹"}}, - {abcd, 2, []string{"a", "bcd"}}, -} - -func TestExplode(t *testing.T) { - for _, tt := range explodetests { - a := SplitN([]byte(tt.s), nil, tt.n) - result := sliceOfString(a) - if !eq(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", %d), "") = "%s"`, tt.s, tt.n, s) - } - } -} - type SplitTest struct { s string sep string @@ -713,7 +685,9 @@ type SplitTest struct { } var splittests = []SplitTest{ + {"", "", -1, []string{}}, {abcd, "a", 0, nil}, + {abcd, "", 2, []string{"a", "bcd"}}, {abcd, "a", -1, []string{"", "bcd"}}, {abcd, "z", -1, []string{"abcd"}}, {abcd, "", -1, []string{"a", "b", "c", "d"}}, @@ -743,7 +717,7 @@ func TestSplit(t *testing.T) { t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a) continue } - if tt.n == 0 { + if tt.n == 0 || len(a) == 0 { continue } |