diff options
Diffstat (limited to 'src/pkg/strconv/fp_test.go')
-rw-r--r-- | src/pkg/strconv/fp_test.go | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/pkg/strconv/fp_test.go b/src/pkg/strconv/fp_test.go index 171defa44..6de2f8bc6 100644 --- a/src/pkg/strconv/fp_test.go +++ b/src/pkg/strconv/fp_test.go @@ -7,7 +7,6 @@ package strconv_test import ( "bufio" "fmt" - "io" "os" "strconv" "strings" @@ -96,31 +95,22 @@ func myatof32(s string) (f float32, ok bool) { } func TestFp(t *testing.T) { - f, err := os.Open("testfp.txt") + f, err := os.Open("testdata/testfp.txt") if err != nil { - t.Fatal("testfp: open testfp.txt:", err) + t.Fatal("testfp: open testdata/testfp.txt:", err) } defer f.Close() - b := bufio.NewReader(f) + s := bufio.NewScanner(f) - lineno := 0 - for { - line, err2 := b.ReadString('\n') - if err2 == io.EOF { - break - } - if err2 != nil { - t.Fatal("testfp: read testfp.txt: " + err2.Error()) - } - line = line[0 : len(line)-1] - lineno++ + for lineno := 1; s.Scan(); lineno++ { + line := s.Text() if len(line) == 0 || line[0] == '#' { continue } a := strings.Split(line, " ") if len(a) != 4 { - t.Error("testfp.txt:", lineno, ": wrong field count") + t.Error("testdata/testfp.txt:", lineno, ": wrong field count") continue } var s string @@ -130,22 +120,25 @@ func TestFp(t *testing.T) { var ok bool v, ok = myatof64(a[2]) if !ok { - t.Error("testfp.txt:", lineno, ": cannot atof64 ", a[2]) + t.Error("testdata/testfp.txt:", lineno, ": cannot atof64 ", a[2]) continue } s = fmt.Sprintf(a[1], v) case "float32": v1, ok := myatof32(a[2]) if !ok { - t.Error("testfp.txt:", lineno, ": cannot atof32 ", a[2]) + t.Error("testdata/testfp.txt:", lineno, ": cannot atof32 ", a[2]) continue } s = fmt.Sprintf(a[1], v1) v = float64(v1) } if s != a[3] { - t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ", + t.Error("testdata/testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ", "want ", a[3], " got ", s) } } + if s.Err() != nil { + t.Fatal("testfp: read testdata/testfp.txt: ", s.Err()) + } } |