diff options
author | Rob Pike <r@golang.org> | 2009-11-14 12:23:24 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-11-14 12:23:24 -0800 |
commit | 995ef119197b8d9a71f2e8c46388cf4c59e0faaf (patch) | |
tree | 55781db4cd00616d878a58b0229133037d0335db /src/pkg/regexp/all_test.go | |
parent | f9496250ad7138ef6885522b116e16225cac8c8b (diff) | |
download | golang-995ef119197b8d9a71f2e8c46388cf4c59e0faaf.tar.gz |
move evaluation of null-matching instructions one iteration earlier.
performance hit of about 20% but more intuitive results for submatches.
we need a good regexp package at some point.
Fixes issue 110.
R=rsc
CC=golang-dev
http://codereview.appspot.com/152131
Diffstat (limited to 'src/pkg/regexp/all_test.go')
-rw-r--r-- | src/pkg/regexp/all_test.go | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/pkg/regexp/all_test.go b/src/pkg/regexp/all_test.go index 04453a9d5..a9f23d70c 100644 --- a/src/pkg/regexp/all_test.go +++ b/src/pkg/regexp/all_test.go @@ -66,6 +66,8 @@ var matches = []tester{ tester{`b`, "abc", vec{1, 2}}, tester{`.`, "a", vec{0, 1}}, tester{`.*`, "abcdef", vec{0, 6}}, + tester{`^`, "abcde", vec{0, 0}}, + tester{`$`, "abcde", vec{5, 5}}, tester{`^abcd$`, "abcd", vec{0, 4}}, tester{`^bcd'`, "abcdef", vec{}}, tester{`^abcd$`, "abcde", vec{}}, @@ -86,6 +88,7 @@ var matches = []tester{ tester{`((a|b|c)*(d))`, "abcd", vec{0, 4, 0, 4, 2, 3, 3, 4}}, tester{`(((a|b|c)*)(d))`, "abcd", vec{0, 4, 0, 4, 0, 3, 2, 3, 3, 4}}, tester{`a*(|(b))c*`, "aacc", vec{0, 4, 2, 2, -1, -1}}, + tester{`(.*).*`, "ab", vec{0, 2, 0, 2}}, } func compileTest(t *testing.T, expr string, error os.Error) *Regexp { @@ -182,12 +185,12 @@ func matchTest(t *testing.T, expr string, str string, match []int) { } m := re.MatchString(str); if m != (len(match) > 0) { - t.Errorf("MatchString failure on %#q matching %q: %d should be %d", expr, str, m, len(match) > 0) + t.Errorf("MatchString failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0) } // now try bytes m = re.Match(strings.Bytes(str)); if m != (len(match) > 0) { - t.Errorf("Match failure on %#q matching %q: %d should be %d", expr, str, m, len(match) > 0) + t.Errorf("Match failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0) } } @@ -377,14 +380,7 @@ var matchCases = []matchCase{ } func printStringSlice(t *testing.T, s []string) { - l := len(s); - if l == 0 { - t.Log("\t<empty>") - } else { - for i := 0; i < l; i++ { - t.Logf("\t%q", s[i]) - } - } + t.Logf("%#v", s) } func TestAllMatches(t *testing.T) { |