Commit f9138301 authored by Rob Pike's avatar Rob Pike

regexp: use Scanner in exec_test

R=rsc
CC=golang-dev
https://golang.org/cl/7381046
parent 9dcf3eee
...@@ -89,7 +89,7 @@ func testRE2(t *testing.T, file string) { ...@@ -89,7 +89,7 @@ func testRE2(t *testing.T, file string) {
txt = f txt = f
} }
lineno := 0 lineno := 0
r := bufio.NewReader(txt) scanner := bufio.NewScanner(txt)
var ( var (
str []string str []string
input []string input []string
...@@ -99,16 +99,8 @@ func testRE2(t *testing.T, file string) { ...@@ -99,16 +99,8 @@ func testRE2(t *testing.T, file string) {
nfail int nfail int
ncase int ncase int
) )
for { for lineno := 1; scanner.Scan(); lineno++ {
line, err := r.ReadString('\n') line := scanner.Text()
if err != nil {
if err == io.EOF {
break
}
t.Fatalf("%s:%d: %v", file, lineno, err)
}
line = line[:len(line)-1] // chop \n
lineno++
switch { switch {
case line == "": case line == "":
t.Fatalf("%s:%d: unexpected blank line", file, lineno) t.Fatalf("%s:%d: unexpected blank line", file, lineno)
...@@ -204,6 +196,9 @@ func testRE2(t *testing.T, file string) { ...@@ -204,6 +196,9 @@ func testRE2(t *testing.T, file string) {
t.Fatalf("%s:%d: out of sync: %s\n", file, lineno, line) t.Fatalf("%s:%d: out of sync: %s\n", file, lineno, line)
} }
} }
if err := scanner.Err(); err != nil {
t.Fatalf("%s:%d: %v", file, lineno, err)
}
if len(input) != 0 { if len(input) != 0 {
t.Fatalf("%s:%d: out of sync: have %d strings left at EOF", file, lineno, len(input)) t.Fatalf("%s:%d: out of sync: have %d strings left at EOF", file, lineno, len(input))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment