import (
"bufio"
"fmt"
- "io"
"os"
"strconv"
"strings"
}
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 testdata/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
}
"want ", a[3], " got ", s)
}
}
+ if s.Err() != nil {
+ t.Fatal("testfp: read testdata/testfp.txt: ", s.Err())
+ }
}