FAQ
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/

Search Discussions

  • Rick Arnold at Nov 26, 2012 at 4:39 pm

    On Monday, November 26, 2012 10:16:53 AM UTC-5, rsc wrote:
    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.
    Thanks, I will check these out. So you think the results should be the same
    as strings.SplitN where possible? What we discussed on golang-nuts (and the
    function documentation) says it will return the opposite of FindAllIndex(),
    which doesn't necessarily match unless I'm understanding it differently.

    For instance:

    strings.SplitN("foo:and:bar:foo", "foo", -1) --> ["", ":and:bar:", ""]

    regexp.MustCompile("foo").FindAllIndex([]byte("foo:and:bar:foo"), -1) --> [0,
    3], [12, 15]
    (so the result string would be everything not contained in [0, 3] and [12,
    15] or ":and:bar:")


    If so, do you have a better way of describing how the function works for
    the documentation? It sounds like you mostly want the behavior of patch set
    5?

    Thanks,
    Rick
  • Russ Cox at Nov 26, 2012 at 4:39 pm
    I think if you have a literal string s and you use strings.SplitN, and
    then you convert to use an equivalent regexp with Split, the behavior
    needs to not change at all, not even in corner cases.

    Russ

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 26, '12 at 3:16p
activeNov 26, '12 at 4:39p
posts3
users2
websitegolang.org

2 users in discussion

Russ Cox: 2 posts Rick Arnold: 1 post

People

Translate

site design / logo © 2022 Grokbase