mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 17:51:33 +02:00
fn: add operations to Result API
This commit is contained in:
@@ -2,7 +2,9 @@ package fn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -17,3 +19,29 @@ func TestOkToSome(t *testing.T) {
|
||||
t, Err[uint8](errors.New("err")).OkToSome(), None[uint8](),
|
||||
)
|
||||
}
|
||||
|
||||
func TestMapOk(t *testing.T) {
|
||||
inc := func(i int) int {
|
||||
return i + 1
|
||||
}
|
||||
f := func(i int) bool {
|
||||
ok := Ok(i)
|
||||
return MapOk(inc)(ok) == Ok(inc(i))
|
||||
}
|
||||
|
||||
require.NoError(t, quick.Check(f, nil))
|
||||
}
|
||||
|
||||
func TestFlattenResult(t *testing.T) {
|
||||
f := func(i int) bool {
|
||||
e := fmt.Errorf("error")
|
||||
|
||||
x := FlattenResult(Ok(Ok(i))) == Ok(i)
|
||||
y := FlattenResult(Ok(Err[int](e))) == Err[int](e)
|
||||
z := FlattenResult(Err[Result[int]](e)) == Err[int](e)
|
||||
|
||||
return x && y && z
|
||||
}
|
||||
|
||||
require.NoError(t, quick.Check(f, nil))
|
||||
}
|
||||
|
Reference in New Issue
Block a user