1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-21 00:19:34 +02:00
Files
fp-go/errors/conv_test.go
Dr. Carsten Leue c07df5c771 initial checkin
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-07 22:31:06 +02:00

40 lines
589 B
Go

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)
}