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:
parent
b38be35e4c
commit
712f3df884
@ -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}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user