-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54b10f3
commit 1198d8b
Showing
5 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package easyerrors | ||
|
||
import "testing" | ||
import "github.com/stretchr/testify/require" | ||
|
||
//goland:noinspection GoPrintFunctions | ||
func TestAs(t *testing.T) { | ||
type fooable interface { | ||
Foo() | ||
} | ||
|
||
err := Errorf("bar: %w", errFoo{}) | ||
|
||
var errHello fooable | ||
require.True(t, As(err, &errHello)) | ||
require.False(t, As(New("bar"), &errHello)) | ||
} | ||
|
||
//goland:noinspection GoDfaNilDereference,GoPrintFunctions | ||
func TestErrorf(t *testing.T) { | ||
err := New("foo") | ||
err = Errorf("bar: %w", err) | ||
require.Equal(t, "bar: foo", err.Error()) | ||
} | ||
|
||
//goland:noinspection GoPrintFunctions | ||
func TestIs(t *testing.T) { | ||
var errFoo = New("foo") | ||
err := Errorf("bar: %w", errFoo) | ||
require.True(t, Is(err, errFoo)) | ||
require.False(t, Is(New("baz"), errFoo)) | ||
} | ||
|
||
func TestJoin(t *testing.T) { | ||
require.Equal(t, "foo\nbar", Join(New("foo"), New("bar")).Error()) | ||
} | ||
|
||
func TestNew(t *testing.T) { | ||
require.Equal(t, "foo", New("foo").Error()) | ||
} | ||
|
||
//goland:noinspection GoPrintFunctions | ||
func TestUnwrap(t *testing.T) { | ||
err = Errorf("bar: %w", New("foo")) | ||
err = Unwrap(err) | ||
err = Unwrap(err) | ||
require.Equal(t, "foo", err.Error()) | ||
} | ||
|
||
type errFoo struct{} | ||
|
||
func (e errFoo) Foo() {} | ||
|
||
func (e errFoo) Error() string { return "foo" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= | ||
github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |