Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Delta Between Two Patch Sets: src/pkg/fmt/scan_test.go

Issue 4240056: code review 4240056: fmt: allow recursive calls to Fscan etc. (Closed)
Left Patch Set: diff -r d9ff478c4ed3 https://go.googlecode.com/hg/ Created 14 years ago
Right Patch Set: diff -r d9ff478c4ed3 https://go.googlecode.com/hg/ Created 14 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/fmt/scan.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package fmt_test 5 package fmt_test
6 6
7 import ( 7 import (
8 "bufio" 8 "bufio"
9 . "fmt" 9 . "fmt"
10 "io" 10 "io"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 renamedComplex64Val renamedComplex64 76 renamedComplex64Val renamedComplex64
77 renamedComplex128Val renamedComplex128 77 renamedComplex128Val renamedComplex128
78 ) 78 )
79 79
80 type FloatTest struct { 80 type FloatTest struct {
81 text string 81 text string
82 in float64 82 in float64
83 out float64 83 out float64
84 } 84 }
85 85
86 // IntString accepts an integer followed immediately by a string.
87 type IntString struct {
88 i int
89 s string
90 }
91
92 func (s *IntString) Scan(state ScanState, verb int) os.Error {
93 if _, err := Fscan(state, &s.i); err != nil {
94 return err
95 }
96
97 if _, err := Fscan(state, &s.s); err != nil {
98 return err
99 }
100 return nil
101 }
102
103 var intStringVal IntString
104
105 // Xs accepts any non-empty run of the verb character 86 // Xs accepts any non-empty run of the verb character
106 type Xs string 87 type Xs string
107 88
108 func (x *Xs) Scan(state ScanState, verb int) os.Error { 89 func (x *Xs) Scan(state ScanState, verb int) os.Error {
109 tok, err := state.Token() 90 tok, err := state.Token()
110 if err != nil { 91 if err != nil {
111 return err 92 return err
112 } 93 }
113 if !regexp.MustCompile("^" + string(verb) + "+$").MatchString(tok) { 94 if !regexp.MustCompile("^" + string(verb) + "+$").MatchString(tok) {
114 return os.ErrorString("syntax error for xs") 95 return os.ErrorString("syntax error for xs")
115 } 96 }
116 *x = Xs(tok) 97 *x = Xs(tok)
117 return nil 98 return nil
118 } 99 }
119 100
120 var xVal Xs 101 var xVal Xs
102
103 // IntString accepts an integer followed immediately by a string.
104 // It tests the embedding of a scan within a scan.
105 type IntString struct {
106 i int
107 s string
108 }
109
110 func (s *IntString) Scan(state ScanState, verb int) os.Error {
111 if _, err := Fscan(state, &s.i); err != nil {
112 return err
113 }
114
115 if _, err := Fscan(state, &s.s); err != nil {
116 return err
117 }
118 return nil
119 }
120
121 var intStringVal IntString
121 122
122 // myStringReader implements Read but not ReadRune, allowing us to test our read Rune wrapper 123 // myStringReader implements Read but not ReadRune, allowing us to test our read Rune wrapper
123 // type that creates something that can read runes given only Read(). 124 // type that creates something that can read runes given only Read().
124 type myStringReader struct { 125 type myStringReader struct {
125 r *strings.Reader 126 r *strings.Reader
126 } 127 }
127 128
128 func (s *myStringReader) Read(p []byte) (n int, err os.Error) { 129 func (s *myStringReader) Read(p []byte) (n int, err os.Error) {
129 return s.r.Read(p) 130 return s.r.Read(p)
130 } 131 }
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 n, err = Sscanln(input, &tscanln) 738 n, err = Sscanln(input, &tscanln)
738 if n != 0 { 739 if n != 0 {
739 t.Errorf("Sscanln: expected 0 items; got %d: %q", n, tscanln) 740 t.Errorf("Sscanln: expected 0 items; got %d: %q", n, tscanln)
740 } 741 }
741 if err == nil { 742 if err == nil {
742 t.Error("Sscanln: expected error; got none") 743 t.Error("Sscanln: expected error; got none")
743 } else if err != io.ErrUnexpectedEOF { 744 } else if err != io.ErrUnexpectedEOF {
744 t.Errorf("Sscanln: expected io.ErrUnexpectedEOF (ha!); got %s", err) 745 t.Errorf("Sscanln: expected io.ErrUnexpectedEOF (ha!); got %s", err)
745 } 746 }
746 } 747 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b