diff options
Diffstat (limited to 'libgo/go/fmt/scan_test.go')
-rw-r--r-- | libgo/go/fmt/scan_test.go | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/libgo/go/fmt/scan_test.go b/libgo/go/fmt/scan_test.go index fbc28c1b2bb..7dd0015b270 100644 --- a/libgo/go/fmt/scan_test.go +++ b/libgo/go/fmt/scan_test.go @@ -7,10 +7,10 @@ package fmt_test import ( "bufio" "bytes" + "errors" . "fmt" "io" "math" - "os" "reflect" "regexp" "strings" @@ -87,14 +87,14 @@ type FloatTest struct { // Xs accepts any non-empty run of the verb character type Xs string -func (x *Xs) Scan(state ScanState, verb rune) os.Error { +func (x *Xs) Scan(state ScanState, verb rune) error { tok, err := state.Token(true, func(r rune) bool { return r == verb }) if err != nil { return err } s := string(tok) if !regexp.MustCompile("^" + string(verb) + "+$").MatchString(s) { - return os.NewError("syntax error for xs") + return errors.New("syntax error for xs") } *x = Xs(s) return nil @@ -109,7 +109,7 @@ type IntString struct { s string } -func (s *IntString) Scan(state ScanState, verb rune) os.Error { +func (s *IntString) Scan(state ScanState, verb rune) error { if _, err := Fscan(state, &s.i); err != nil { return err } @@ -130,7 +130,7 @@ type myStringReader struct { r *strings.Reader } -func (s *myStringReader) Read(p []byte) (n int, err os.Error) { +func (s *myStringReader) Read(p []byte) (n int, err error) { return s.r.Read(p) } @@ -350,7 +350,7 @@ var multiTests = []ScanfMultiTest{ {"%c%c%c", "\xc2X\xc2", args(&i, &j, &k), args(utf8.RuneError, 'X', utf8.RuneError), ""}, } -func testScan(name string, t *testing.T, scan func(r io.Reader, a ...interface{}) (int, os.Error)) { +func testScan(name string, t *testing.T, scan func(r io.Reader, a ...interface{}) (int, error)) { for _, test := range scanTests { var r io.Reader if name == "StringReader" { @@ -431,7 +431,7 @@ func TestScanOverflow(t *testing.T) { t.Errorf("expected overflow scanning %q", test.text) continue } - if !re.MatchString(err.String()) { + if !re.MatchString(err.Error()) { t.Errorf("expected overflow error scanning %q: %s", test.text, err) } } @@ -500,7 +500,7 @@ func testScanfMulti(name string, t *testing.T) { if err != nil { if test.err == "" { t.Errorf("got error scanning (%q, %q): %q", test.format, test.text, err) - } else if strings.Index(err.String(), test.err) < 0 { + } else if strings.Index(err.Error(), test.err) < 0 { t.Errorf("got wrong error scanning (%q, %q): %q; expected %q", test.format, test.text, err, test.err) } continue @@ -594,7 +594,7 @@ func TestScanNotPointer(t *testing.T) { _, err := Fscan(r, a) if err == nil { t.Error("expected error scanning non-pointer") - } else if strings.Index(err.String(), "pointer") < 0 { + } else if strings.Index(err.Error(), "pointer") < 0 { t.Errorf("expected pointer error scanning non-pointer, got: %s", err) } } @@ -604,7 +604,7 @@ func TestScanlnNoNewline(t *testing.T) { _, err := Sscanln("1 x\n", &a) if err == nil { t.Error("expected error scanning string missing newline") - } else if strings.Index(err.String(), "newline") < 0 { + } else if strings.Index(err.Error(), "newline") < 0 { t.Errorf("expected newline error scanning string missing newline, got: %s", err) } } @@ -615,7 +615,7 @@ func TestScanlnWithMiddleNewline(t *testing.T) { _, err := Fscanln(r, &a, &b) if err == nil { t.Error("expected error scanning string with extra newline") - } else if strings.Index(err.String(), "newline") < 0 { + } else if strings.Index(err.Error(), "newline") < 0 { t.Errorf("expected newline error scanning string with extra newline, got: %s", err) } } @@ -626,7 +626,7 @@ type eofCounter struct { eofCount int } -func (ec *eofCounter) Read(b []byte) (n int, err os.Error) { +func (ec *eofCounter) Read(b []byte) (n int, err error) { n, err = ec.reader.Read(b) if n == 0 { ec.eofCount++ @@ -670,14 +670,14 @@ func TestEOFAtEndOfInput(t *testing.T) { if n != 1 || i != 23 { t.Errorf("Sscanf expected one value of 23; got %d %d", n, i) } - if err != os.EOF { + if err != io.EOF { t.Errorf("Sscanf expected EOF; got %q", err) } n, err = Sscan("234", &i, &j) if n != 1 || i != 234 { t.Errorf("Sscan expected one value of 234; got %d %d", n, i) } - if err != os.EOF { + if err != io.EOF { t.Errorf("Sscan expected EOF; got %q", err) } // Trailing space is tougher. @@ -685,7 +685,7 @@ func TestEOFAtEndOfInput(t *testing.T) { if n != 1 || i != 234 { t.Errorf("Sscan expected one value of 234; got %d %d", n, i) } - if err != os.EOF { + if err != io.EOF { t.Errorf("Sscan expected EOF; got %q", err) } } @@ -715,10 +715,10 @@ var eofTests = []struct { func TestEOFAllTypes(t *testing.T) { for i, test := range eofTests { - if _, err := Sscanf("", test.format, test.v); err != os.EOF { + if _, err := Sscanf("", test.format, test.v); err != io.EOF { t.Errorf("#%d: %s %T not eof on empty string: %s", i, test.format, test.v, err) } - if _, err := Sscanf(" ", test.format, test.v); err != os.EOF { + if _, err := Sscanf(" ", test.format, test.v); err != io.EOF { t.Errorf("#%d: %s %T not eof on trailing blanks: %s", i, test.format, test.v, err) } } @@ -749,7 +749,7 @@ type TwoLines string // Attempt to read two lines into the object. Scanln should prevent this // because it stops at newline; Scan and Scanf should be fine. -func (t *TwoLines) Scan(state ScanState, verb rune) os.Error { +func (t *TwoLines) Scan(state ScanState, verb rune) error { chars := make([]rune, 0, 100) for nlCount := 0; nlCount < 2; { c, _, err := state.ReadRune() @@ -812,7 +812,7 @@ type RecursiveInt struct { next *RecursiveInt } -func (r *RecursiveInt) Scan(state ScanState, verb rune) (err os.Error) { +func (r *RecursiveInt) Scan(state ScanState, verb rune) (err error) { _, err = Fscan(state, &r.i) if err != nil { return @@ -820,7 +820,7 @@ func (r *RecursiveInt) Scan(state ScanState, verb rune) (err os.Error) { next := new(RecursiveInt) _, err = Fscanf(state, ".%v", next) if err != nil { - if err == os.NewError("input does not match format") || err == io.ErrUnexpectedEOF { + if err == errors.New("input does not match format") || err == io.ErrUnexpectedEOF { err = nil } return @@ -832,7 +832,7 @@ func (r *RecursiveInt) Scan(state ScanState, verb rune) (err os.Error) { // Perform the same scanning task as RecursiveInt.Scan // but without recurring through scanner, so we can compare // performance more directly. -func scanInts(r *RecursiveInt, b *bytes.Buffer) (err os.Error) { +func scanInts(r *RecursiveInt, b *bytes.Buffer) (err error) { r.next = nil _, err = Fscan(b, &r.i) if err != nil { @@ -840,7 +840,7 @@ func scanInts(r *RecursiveInt, b *bytes.Buffer) (err os.Error) { } c, _, err := b.ReadRune() if err != nil { - if err == os.EOF { + if err == io.EOF { err = nil } return @@ -867,7 +867,7 @@ func makeInts(n int) []byte { func TestScanInts(t *testing.T) { testScanInts(t, scanInts) - testScanInts(t, func(r *RecursiveInt, b *bytes.Buffer) (err os.Error) { + testScanInts(t, func(r *RecursiveInt, b *bytes.Buffer) (err error) { _, err = Fscan(b, r) return }) @@ -877,7 +877,7 @@ func TestScanInts(t *testing.T) { // platform that does not support split stack. const intCount = 800 -func testScanInts(t *testing.T, scan func(*RecursiveInt, *bytes.Buffer) os.Error) { +func testScanInts(t *testing.T, scan func(*RecursiveInt, *bytes.Buffer) error) { r := new(RecursiveInt) ints := makeInts(intCount) buf := bytes.NewBuffer(ints) |