summaryrefslogtreecommitdiff
path: root/src/pkg/testing/regexp_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-08 15:14:54 -0700
committerRuss Cox <rsc@golang.org>2009-10-08 15:14:54 -0700
commit79244ca7360f32db37710ab74c72214146397edf (patch)
tree0f7c5551b95f4e5dd567a4ac3233afeb0da61e99 /src/pkg/testing/regexp_test.go
parent71b9ef8c235f052495a1fb29bd3945f7094998a9 (diff)
downloadgolang-79244ca7360f32db37710ab74c72214146397edf.tar.gz
more lgtm files from gofmt
R=gri OCL=35485 CL=35488
Diffstat (limited to 'src/pkg/testing/regexp_test.go')
-rw-r--r--src/pkg/testing/regexp_test.go127
1 files changed, 64 insertions, 63 deletions
diff --git a/src/pkg/testing/regexp_test.go b/src/pkg/testing/regexp_test.go
index 367a61d8c..d24e801b9 100644
--- a/src/pkg/testing/regexp_test.go
+++ b/src/pkg/testing/regexp_test.go
@@ -33,22 +33,23 @@ type stringError struct {
re string;
err string;
}
+
var bad_re = []stringError{
- stringError{ `*`, ErrBareClosure },
- stringError{ `(abc`, ErrUnmatchedLpar },
- stringError{ `abc)`, ErrUnmatchedRpar },
- stringError{ `x[a-z`, ErrUnmatchedLbkt },
- stringError{ `abc]`, ErrUnmatchedRbkt },
- stringError{ `[z-a]`, ErrBadRange },
- stringError{ `abc\`, ErrExtraneousBackslash },
- stringError{ `a**`, ErrBadClosure },
- stringError{ `a*+`, ErrBadClosure },
- stringError{ `a??`, ErrBadClosure },
- stringError{ `*`, ErrBareClosure },
- stringError{ `\x`, ErrBadBackslash },
+ stringError{`*`, ErrBareClosure},
+ stringError{`(abc`, ErrUnmatchedLpar},
+ stringError{`abc)`, ErrUnmatchedRpar},
+ stringError{`x[a-z`, ErrUnmatchedLbkt},
+ stringError{`abc]`, ErrUnmatchedRbkt},
+ stringError{`[z-a]`, ErrBadRange},
+ stringError{`abc\`, ErrExtraneousBackslash},
+ stringError{`a**`, ErrBadClosure},
+ stringError{`a*+`, ErrBadClosure},
+ stringError{`a??`, ErrBadClosure},
+ stringError{`*`, ErrBareClosure},
+ stringError{`\x`, ErrBadBackslash},
}
-type vec []int;
+type vec []int
type tester struct {
re string;
@@ -56,33 +57,33 @@ type tester struct {
match vec;
}
-var matches = []tester {
- tester{ ``, "", vec{0,0} },
- tester{ `a`, "a", vec{0,1} },
- tester{ `x`, "y", vec{} },
- tester{ `b`, "abc", vec{1,2} },
- tester{ `.`, "a", vec{0,1} },
- tester{ `.*`, "abcdef", vec{0,6} },
- tester{ `^abcd$`, "abcd", vec{0,4} },
- tester{ `^bcd'`, "abcdef", vec{} },
- tester{ `^abcd$`, "abcde", vec{} },
- tester{ `a+`, "baaab", vec{1,4} },
- tester{ `a*`, "baaab", vec{0,0} },
- tester{ `[a-z]+`, "abcd", vec{0,4} },
- tester{ `[^a-z]+`, "ab1234cd", vec{2,6} },
- tester{ `[a\-\]z]+`, "az]-bcz", vec{0,4} },
- tester{ `[^\n]+`, "abcd\n", vec{0,4} },
- tester{ `[日本語]+`, "日本語日本語", vec{0,18} },
- tester{ `()`, "", vec{0,0, 0,0} },
- tester{ `(a)`, "a", vec{0,1, 0,1} },
- tester{ `(.)(.)`, "日a", vec{0,4, 0,3, 3,4} },
- tester{ `(.*)`, "", vec{0,0, 0,0} },
- tester{ `(.*)`, "abcd", vec{0,4, 0,4} },
- tester{ `(..)(..)`, "abcd", vec{0,4, 0,2, 2,4} },
- tester{ `(([^xyz]*)(d))`, "abcd", vec{0,4, 0,4, 0,3, 3,4} },
- 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} },
+var matches = []tester{
+ tester{``, "", vec{0, 0}},
+ tester{`a`, "a", vec{0, 1}},
+ tester{`x`, "y", vec{}},
+ tester{`b`, "abc", vec{1, 2}},
+ tester{`.`, "a", vec{0, 1}},
+ tester{`.*`, "abcdef", vec{0, 6}},
+ tester{`^abcd$`, "abcd", vec{0, 4}},
+ tester{`^bcd'`, "abcdef", vec{}},
+ tester{`^abcd$`, "abcde", vec{}},
+ tester{`a+`, "baaab", vec{1, 4}},
+ tester{`a*`, "baaab", vec{0, 0}},
+ tester{`[a-z]+`, "abcd", vec{0, 4}},
+ tester{`[^a-z]+`, "ab1234cd", vec{2, 6}},
+ tester{`[a\-\]z]+`, "az]-bcz", vec{0, 4}},
+ tester{`[^\n]+`, "abcd\n", vec{0, 4}},
+ tester{`[日本語]+`, "日本語日本語", vec{0, 18}},
+ tester{`()`, "", vec{0, 0, 0, 0}},
+ tester{`(a)`, "a", vec{0, 1, 0, 1}},
+ tester{`(.)(.)`, "日a", vec{0, 4, 0, 3, 3, 4}},
+ tester{`(.*)`, "", vec{0, 0, 0, 0}},
+ tester{`(.*)`, "abcd", vec{0, 4, 0, 4}},
+ tester{`(..)(..)`, "abcd", vec{0, 4, 0, 2, 2, 4}},
+ tester{`(([^xyz]*)(d))`, "abcd", vec{0, 4, 0, 4, 0, 3, 3, 4}},
+ 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}},
}
func compileTest(t *T, expr string, error string) *Regexp {
@@ -90,7 +91,7 @@ func compileTest(t *T, expr string, error string) *Regexp {
if err != error {
t.Error("compiling `", expr, "`; unexpected error: ", err);
}
- return re
+ return re;
}
func printVec(t *T, m []int) {
@@ -99,7 +100,7 @@ func printVec(t *T, m []int) {
t.Log("\t<no match>");
} else {
for i := 0; i < l; i = i+2 {
- t.Log("\t", m[i], ",", m[i+1])
+ t.Log("\t", m[i], ",", m[i+1]);
}
}
}
@@ -110,7 +111,7 @@ func printStrings(t *T, m []string) {
t.Log("\t<no match>");
} else {
for i := 0; i < l; i = i+2 {
- t.Logf("\t%q", m[i])
+ t.Logf("\t%q", m[i]);
}
}
}
@@ -121,7 +122,7 @@ func printBytes(t *T, b [][]byte) {
t.Log("\t<no match>");
} else {
for i := 0; i < l; i = i+2 {
- t.Logf("\t%q", b[i])
+ t.Logf("\t%q", b[i]);
}
}
}
@@ -129,46 +130,46 @@ func printBytes(t *T, b [][]byte) {
func equal(m1, m2 []int) bool {
l := len(m1);
if l != len(m2) {
- return false
+ return false;
}
for i := 0; i < l; i++ {
if m1[i] != m2[i] {
- return false
+ return false;
}
}
- return true
+ return true;
}
func equalStrings(m1, m2 []string) bool {
l := len(m1);
if l != len(m2) {
- return false
+ return false;
}
for i := 0; i < l; i++ {
if m1[i] != m2[i] {
- return false
+ return false;
}
}
- return true
+ return true;
}
func equalBytes(m1 [][]byte, m2 []string) bool {
l := len(m1);
if l != len(m2) {
- return false
+ return false;
}
for i := 0; i < l; i++ {
if string(m1[i]) != m2[i] {
- return false
+ return false;
}
}
- return true
+ return true;
}
func executeTest(t *T, expr string, str string, match []int) {
re := compileTest(t, expr, "");
if re == nil {
- return
+ return;
}
m := re.ExecuteString(str);
if !equal(m, match) {
@@ -195,21 +196,21 @@ func TestGoodCompile(t *T) {
func TestBadCompile(t *T) {
for i := 0; i < len(bad_re); i++ {
- compileTest(t, bad_re[i].re, bad_re[i].err)
+ compileTest(t, bad_re[i].re, bad_re[i].err);
}
}
func TestExecute(t *T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
- executeTest(t, test.re, test.text, test.match)
+ executeTest(t, test.re, test.text, test.match);
}
}
func matchTest(t *T, expr string, str string, match []int) {
re := compileTest(t, expr, "");
if re == nil {
- return
+ return;
}
m := re.MatchString(str);
if m != (len(match) > 0) {
@@ -225,18 +226,18 @@ func matchTest(t *T, expr string, str string, match []int) {
func TestMatch(t *T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
- matchTest(t, test.re, test.text, test.match)
+ matchTest(t, test.re, test.text, test.match);
}
}
func matchStringsTest(t *T, expr string, str string, match []int) {
re := compileTest(t, expr, "");
if re == nil {
- return
+ return;
}
strs := make([]string, len(match)/2);
for i := 0; i < len(match); i++ {
- strs[i/2] = str[match[i] : match[i+1]]
+ strs[i/2] = str[match[i]:match[i+1]];
}
m := re.MatchStrings(str);
if !equalStrings(m, strs) {
@@ -258,14 +259,14 @@ func matchStringsTest(t *T, expr string, str string, match []int) {
func TestMatchStrings(t *T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
- matchTest(t, test.re, test.text, test.match)
+ matchTest(t, test.re, test.text, test.match);
}
}
func matchFunctionTest(t *T, expr string, str string, match []int) {
m, err := MatchString(expr, str);
if err == "" {
- return
+ return;
}
if m != (len(match) > 0) {
t.Error("function Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0);
@@ -275,6 +276,6 @@ func matchFunctionTest(t *T, expr string, str string, match []int) {
func TestMatchFunction(t *T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
- matchFunctionTest(t, test.re, test.text, test.match)
+ matchFunctionTest(t, test.re, test.text, test.match);
}
}