summaryrefslogtreecommitdiff
path: root/src/pkg/fmt/scan_test.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-06-14 17:16:35 -0700
committerRob Pike <r@golang.org>2010-06-14 17:16:35 -0700
commitdcabff01961349b411c3f17f7afb82255578ca30 (patch)
treeeccd648cb983eb5bfb908be42e4a23364f30d2b9 /src/pkg/fmt/scan_test.go
parent5ea315adf5f636ef12759f80406a0af5572ac2a3 (diff)
downloadgolang-dcabff01961349b411c3f17f7afb82255578ca30.tar.gz
fmt.Print*: reimplement to switch on type first.
This shortens, simplifies and regularizes the code significantly. (Improvements to reflect could make another step.) Passes all.bash. One semantic change occurs: The String() method changes behavior. It used to run only for string formats such as %s and %q. Instead, it now runs whenever the item has the method and the result is then processed by the format as a string. Besides the regularization, this has three effects: 1) width is honored for String() items 2) %x works for String() items 3) implementations of String that merely recur will recur forever Regarding point 3, example from the updated documentation: type X int func (x X) String() string { return Sprintf("%d", x) } should cast the value before recurring: func (x X) String() string { return Sprintf("%d", int(x)) } R=rsc CC=golang-dev http://codereview.appspot.com/1613045
Diffstat (limited to 'src/pkg/fmt/scan_test.go')
-rw-r--r--src/pkg/fmt/scan_test.go25
1 files changed, 1 insertions, 24 deletions
diff --git a/src/pkg/fmt/scan_test.go b/src/pkg/fmt/scan_test.go
index 0ed53e886..d876adc9f 100644
--- a/src/pkg/fmt/scan_test.go
+++ b/src/pkg/fmt/scan_test.go
@@ -34,29 +34,6 @@ type ScanfMultiTest struct {
err string
}
-type (
- renamedBool bool
- renamedInt int
- renamedInt8 int8
- renamedInt16 int16
- renamedInt32 int32
- renamedInt64 int64
- renamedUint uint
- renamedUint8 uint8
- renamedUint16 uint16
- renamedUint32 uint32
- renamedUint64 uint64
- renamedUintptr uintptr
- renamedString string
- renamedBytes []byte
- renamedFloat float
- renamedFloat32 float32
- renamedFloat64 float64
- renamedComplex complex
- renamedComplex64 complex64
- renamedComplex128 complex128
-)
-
var (
boolVal bool
intVal int
@@ -122,7 +99,7 @@ func (x *Xs) Scan(state ScanState, verb int) os.Error {
if err != nil {
return err
}
- if !testing.MustCompile(string(verb) + "+").MatchString(tok) {
+ if !testing.MustCompile("^" + string(verb) + "+$").MatchString(tok) {
return os.ErrorString("syntax error for xs")
}
*x = Xs(tok)