From c6f23bb7c1cdc83cea7e0cec5c912a67d1b19988 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 20 Feb 2013 15:57:18 -0800 Subject: [PATCH] image/png: use Scanner in reader_test. R=nigeltao CC=golang-dev https://golang.org/cl/7399044 --- src/pkg/image/png/reader_test.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/pkg/image/png/reader_test.go b/src/pkg/image/png/reader_test.go index 8223f521cc3..b682bd0968b 100644 --- a/src/pkg/image/png/reader_test.go +++ b/src/pkg/image/png/reader_test.go @@ -208,7 +208,7 @@ func TestReader(t *testing.T) { } piper, pipew := io.Pipe() - pb := bufio.NewReader(piper) + pb := bufio.NewScanner(piper) go sng(pipew, fn, img) defer piper.Close() @@ -219,7 +219,7 @@ func TestReader(t *testing.T) { continue } defer sf.Close() - sb := bufio.NewReader(sf) + sb := bufio.NewScanner(sf) if err != nil { t.Error(fn, err) continue @@ -227,24 +227,28 @@ func TestReader(t *testing.T) { // Compare the two, in SNG format, line by line. for { - ps, perr := pb.ReadString('\n') - ss, serr := sb.ReadString('\n') - if perr == io.EOF && serr == io.EOF { + pdone := pb.Scan() + sdone := sb.Scan() + if pdone && sdone { break } - if perr != nil { - t.Error(fn, perr) - break - } - if serr != nil { - t.Error(fn, serr) + if pdone || sdone { + t.Errorf("%s: Different sizes", fn) break } + ps := pb.Text() + ss := sb.Text() if ps != ss { t.Errorf("%s: Mismatch\n%sversus\n%s\n", fn, ps, ss) break } } + if pb.Err() != nil { + t.Error(fn, pb.Err()) + } + if sb.Err() != nil { + t.Error(fn, sb.Err()) + } } }