func (x *Xs) Scan(state ScanState, verb int) os.Error { var tok string var c int var err os.Error wid, present := state.Width() if !present { tok, err = state.Token() } else { for i := 0; i < wid; i++ { c, err = state.GetRune() if err != nil { break } tok += string(c) } } if err != nil { return err } if !testing.MustCompile("^" + string(verb) + "+$").MatchString(tok) { return os.ErrorString("syntax error for xs") } *x = Xs(tok) return nil }
func TestScanOverflow(t *testing.T) { // different machines and different types report errors with different strings. re := testing.MustCompile("overflow|too large|out of range|not representable") for _, test := range overflowTests { _, err := Sscan(test.text, test.in) if err == nil { t.Errorf("expected overflow scanning %q", test.text) continue } if !re.MatchString(err.String()) { t.Errorf("expected overflow error scanning %q: %s", test.text, err) } } }