42 lines
1 KiB
Go
42 lines
1 KiB
Go
package scopes_test
|
|
|
|
import (
|
|
"fmt"
|
|
tbase "testing"
|
|
|
|
"git.sr.ht/~cco/go-scopes/lib/funky"
|
|
"git.sr.ht/~cco/go-scopes/testing"
|
|
)
|
|
|
|
func TestFunky(tb *tbase.T) {
|
|
t := testing.SetUp(tb)
|
|
t.Run("maybe", MaybeTest)
|
|
t.Run("either", EitherTest)
|
|
t.Run("iterator", IteratorTest)
|
|
}
|
|
|
|
func MaybeTest(t *testing.T) {
|
|
var i0 funky.Maybe[int] = funky.Nothing[int]()
|
|
t.AssertEqual(i0.IsNothing(), true)
|
|
var i1 funky.Maybe[int] = funky.Just(3)
|
|
t.AssertEqual(i1.IsNothing(), false)
|
|
t.AssertEqual(i1.Value(), 3)
|
|
}
|
|
|
|
func EitherTest(t *testing.T) {
|
|
var e0 funky.Either[int] = funky.Value[int](7)
|
|
t.AssertEqual(e0.Ok(), true)
|
|
t.AssertEqual(e0.IsNothing(), false)
|
|
t.AssertEqual(e0.Value(), 7)
|
|
var e1 funky.Either[int] = funky.Error[int](fmt.Errorf("Some Error"))
|
|
t.AssertEqual(e1.Ok(), false)
|
|
t.AssertEqual(fmt.Sprint(e1.Error()), "Some Error")
|
|
}
|
|
|
|
func IteratorTest(t *testing.T) {
|
|
sl := []int{3, 4, 5}
|
|
var it funky.Iterator[int] = funky.SliceIterator[int](sl)
|
|
s2 := funky.Slice(it)
|
|
t.AssertEqual(len(s2), 3)
|
|
t.AssertEqual(s2[1], 4)
|
|
}
|