-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
io_either_test.go
106 lines (86 loc) · 2.17 KB
/
io_either_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package mo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIOEither(t *testing.T) {
is := assert.New(t)
ioEither := NewIOEither(func() (int, error) {
return 42, nil
})
result := ioEither.Run()
is.False(result.isLeft)
is.Nil(result.Left())
is.True(result.IsRight())
is.Equal(42, result.MustRight())
}
func TestIOEither1(t *testing.T) {
is := assert.New(t)
ioEither := NewIOEither1(func(a string) (int, error) {
is.Equal("foo", a)
return 42, nil
})
result := ioEither.Run("foo")
is.False(result.isLeft)
is.Nil(result.Left())
is.True(result.IsRight())
is.Equal(42, result.MustRight())
}
func TestIOEither2(t *testing.T) {
is := assert.New(t)
ioEither := NewIOEither2(func(a string, b string) (int, error) {
is.Equal("foo", a)
is.Equal("bar", b)
return 42, nil
})
result := ioEither.Run("foo", "bar")
is.False(result.isLeft)
is.Nil(result.Left())
is.True(result.IsRight())
is.Equal(42, result.MustRight())
}
func TestIOEither3(t *testing.T) {
is := assert.New(t)
ioEither := NewIOEither3(func(a string, b string, c string) (int, error) {
is.Equal("foo", a)
is.Equal("bar", b)
is.Equal("hello", c)
return 42, nil
})
result := ioEither.Run("foo", "bar", "hello")
is.False(result.isLeft)
is.Nil(result.Left())
is.True(result.IsRight())
is.Equal(42, result.MustRight())
}
func TestIOEither4(t *testing.T) {
is := assert.New(t)
ioEither := NewIOEither4(func(a string, b string, c string, d string) (int, error) {
is.Equal("foo", a)
is.Equal("bar", b)
is.Equal("hello", c)
is.Equal("world", d)
return 42, nil
})
result := ioEither.Run("foo", "bar", "hello", "world")
is.False(result.isLeft)
is.Nil(result.Left())
is.True(result.IsRight())
is.Equal(42, result.MustRight())
}
func TestIOEither5(t *testing.T) {
is := assert.New(t)
ioEither := NewIOEither5(func(a string, b string, c string, d string, e bool) (int, error) {
is.Equal("foo", a)
is.Equal("bar", b)
is.Equal("hello", c)
is.Equal("world", d)
is.True(e)
return 42, nil
})
result := ioEither.Run("foo", "bar", "hello", "world", true)
is.False(result.isLeft)
is.Nil(result.Left())
is.True(result.IsRight())
is.Equal(42, result.MustRight())
}