1
0
mirror of https://github.com/golang/go synced 2024-11-23 10:50:09 -07:00

Add Unwrap to NumError

This commit is contained in:
Pantelis Sampaziotis 2019-09-10 14:21:07 +03:00
parent b38be35e4c
commit 712f3df884
2 changed files with 9 additions and 0 deletions

View File

@ -31,6 +31,8 @@ func (e *NumError) Error() string {
return "strconv." + e.Func + ": " + "parsing " + Quote(e.Num) + ": " + e.Err.Error()
}
func (e *NumError) Unwrap() error { return e.Err }
func syntaxError(fn, str string) *NumError {
return &NumError{fn, str, ErrSyntax}
}

View File

@ -592,6 +592,13 @@ func TestNumError(t *testing.T) {
}
}
func TestNumErrorUnwrap(t *testing.T) {
err := &NumError{Err: ErrSyntax}
if !errors.Is(err, ErrSyntax) {
t.Error("errors.Is failed, wanted success")
}
}
func BenchmarkParseInt(b *testing.B) {
b.Run("Pos", func(b *testing.B) {
benchmarkParseInt(b, 1)