I think if you make these test changes you will find that the matching
loop needs a little bit more work. I would suggest looking at the
implementation of strings.SplitN for inspiration.
Also, if you pass n-1 to FindAllIndex you should be able to simplify the
loop a little, because you won't have to worry about using too many
matches.
https://codereview.appspot.com/6846048/diff/13001/src/pkg/regexp/all_test.go
File src/pkg/regexp/all_test.go (right):
https://codereview.appspot.com/6846048/diff/13001/src/pkg/regexp/all_test.go#newcode421
src/pkg/regexp/all_test.go:421: var tests = []struct {
Please move this up out of the function.
var splitTests = []...
func TestSplit(t *testing.T) {
...
https://codereview.appspot.com/6846048/diff/13001/src/pkg/regexp/all_test.go#newcode448
src/pkg/regexp/all_test.go:448: {"abaabaccadaaae", "a*", 5,
[]string{"b", "b", "c", "c", "daaae"}},
Please add
{":x:y:z:", ":", -1, []string{"", "x", "y", "z", ""}}
https://codereview.appspot.com/6846048/diff/13001/src/pkg/regexp/all_test.go#newcode460
src/pkg/regexp/all_test.go:460: t.Errorf("#%d: %q: got %#v; want %#v",
i, test.r, split, test.out)
%#v is fine here but you might find %q a little more readable
https://codereview.appspot.com/6846048/diff/13001/src/pkg/regexp/all_test.go#newcode461
src/pkg/regexp/all_test.go:461: }
add
if QuoteMeta(test.r) == test.r {
strsplit := strings.SplitN(test.s, test.r, test.n)
if !reflect.DeepEqual(split, strsplit) {
t.Errorf("#%d: Split(%q, %q, %d): regexp vs strings
mismatch\nregexp=%q\nstrings=%q", i, test.s, test.r, test.n, split,
strsplit)
}
}
https://codereview.appspot.com/6846048/