1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-17 00:07:49 +02:00
Files
fp-go/errors/conv_test.go

40 lines
589 B
Go
Raw Normal View History

package errors
import (
"fmt"
"testing"
F "github.com/IBM/fp-go/function"
O "github.com/IBM/fp-go/option"
"github.com/stretchr/testify/assert"
)
type MyError struct{}
func (m *MyError) Error() string {
return "boom"
}
func TestAs(t *testing.T) {
root := &MyError{}
err := fmt.Errorf("This is my custom error, %w", root)
errO := F.Pipe1(
err,
As[*MyError](),
)
assert.Equal(t, O.Of(root), errO)
}
func TestNotAs(t *testing.T) {
err := fmt.Errorf("This is my custom error")
errO := F.Pipe1(
err,
As[*MyError](),
)
assert.Equal(t, O.None[*MyError](), errO)
}