1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-06 13:42:28 +08:00
Files
lancet/xerror/xerror_test.go
donutloop 2878d389c8 error: Add unwrap (#24)
Add a unwrap func helper

* Unwrap if err is nil then it returns a valid value otherwise it panics
2022-01-22 21:25:31 +08:00

25 lines
465 B
Go

package xerror
import (
"github.com/duke-git/lancet/internal"
"strconv"
"testing"
)
func TestUnwrap(t *testing.T) {
assert := internal.NewAssert(t, "TestUnwrap")
assert.Equal(42, Unwrap(strconv.Atoi("42")))
}
func TestUnwrapFail(t *testing.T) {
assert := internal.NewAssert(t, "TestUnwrapFail")
_, err := strconv.Atoi("4o2")
defer func() {
v := recover()
assert.Equal(err.Error(), v.(*strconv.NumError).Error())
}()
Unwrap(strconv.Atoi("4o2"))
}