From f913830148bade4b4cf34ecb64fbcfaa13a04573 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 20 Feb 2013 13:37:45 -0800 Subject: [PATCH] regexp: use Scanner in exec_test R=rsc CC=golang-dev https://golang.org/cl/7381046 --- src/pkg/regexp/exec_test.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pkg/regexp/exec_test.go b/src/pkg/regexp/exec_test.go index d3eddf2a744..9dfaed713f7 100644 --- a/src/pkg/regexp/exec_test.go +++ b/src/pkg/regexp/exec_test.go @@ -89,7 +89,7 @@ func testRE2(t *testing.T, file string) { txt = f } lineno := 0 - r := bufio.NewReader(txt) + scanner := bufio.NewScanner(txt) var ( str []string input []string @@ -99,16 +99,8 @@ func testRE2(t *testing.T, file string) { nfail int ncase int ) - for { - line, err := r.ReadString('\n') - if err != nil { - if err == io.EOF { - break - } - t.Fatalf("%s:%d: %v", file, lineno, err) - } - line = line[:len(line)-1] // chop \n - lineno++ + for lineno := 1; scanner.Scan(); lineno++ { + line := scanner.Text() switch { case line == "": t.Fatalf("%s:%d: unexpected blank line", file, lineno) @@ -204,6 +196,9 @@ func testRE2(t *testing.T, file string) { 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 { t.Fatalf("%s:%d: out of sync: have %d strings left at EOF", file, lineno, len(input)) }