Skip to content

Commit

Permalink
Add Unwrap to NumError
Browse files Browse the repository at this point in the history
  • Loading branch information
psampaz committed Sep 10, 2019
1 parent b38be35 commit 712f3df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/strconv/atoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
7 changes: 7 additions & 0 deletions src/strconv/atoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 712f3df

Please sign in to comment.