diff options
Diffstat (limited to 'libgo/go/strconv/atoi_test.go')
-rw-r--r-- | libgo/go/strconv/atoi_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libgo/go/strconv/atoi_test.go b/libgo/go/strconv/atoi_test.go index d0e7b61..9407573 100644 --- a/libgo/go/strconv/atoi_test.go +++ b/libgo/go/strconv/atoi_test.go @@ -5,6 +5,7 @@ package strconv_test import ( + "errors" "reflect" . "strconv" "testing" @@ -146,6 +147,16 @@ var atoi32tests = []atoi32Test{ {"-2147483649", -1 << 31, ErrRange}, } +type numErrorTest struct { + num, want string +} + +var numErrorTests = []numErrorTest{ + {"0", `strconv.ParseFloat: parsing "0": failed`}, + {"`", "strconv.ParseFloat: parsing \"`\": failed"}, + {"1\x00.2", `strconv.ParseFloat: parsing "1\x00.2": failed`}, +} + func init() { // The atoi routines return NumErrors wrapping // the error and the string. Convert the tables above. @@ -277,6 +288,19 @@ func TestParseInt(t *testing.T) { } } +func TestNumError(t *testing.T) { + for _, test := range numErrorTests { + err := &NumError{ + Func: "ParseFloat", + Num: test.num, + Err: errors.New("failed"), + } + if got := err.Error(); got != test.want { + t.Errorf(`(&NumError{"ParseFloat", %q, "failed"}).Error() = %v, want %v`, test.num, got, test.want) + } + } +} + func BenchmarkAtoi(b *testing.B) { for i := 0; i < b.N; i++ { ParseInt("12345678", 10, 0) |