forked from samber/mo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_test.go
100 lines (80 loc) · 2.09 KB
/
task_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
package mo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTask(t *testing.T) {
is := assert.New(t)
task := NewTask(func() *Future[int] {
return NewFuture(func(resolve func(int), reject func(error)) {
resolve(42)
})
})
result := task.Run().Result().MustGet()
is.Equal(42, result)
}
func TestTask1(t *testing.T) {
is := assert.New(t)
task := NewTask1(func(a string) *Future[int] {
return NewFuture(func(resolve func(int), reject func(error)) {
is.Equal("foo", a)
resolve(42)
})
})
result := task.Run("foo").Result().MustGet()
is.Equal(42, result)
}
func TestTask2(t *testing.T) {
is := assert.New(t)
task := NewTask2(func(a string, b string) *Future[int] {
return NewFuture(func(resolve func(int), reject func(error)) {
is.Equal("foo", a)
is.Equal("bar", b)
resolve(42)
})
})
result := task.Run("foo", "bar").Result().MustGet()
is.Equal(42, result)
}
func TestTask3(t *testing.T) {
is := assert.New(t)
task := NewTask3(func(a string, b string, c string) *Future[int] {
return NewFuture(func(resolve func(int), reject func(error)) {
is.Equal("foo", a)
is.Equal("bar", b)
is.Equal("hello", c)
resolve(42)
})
})
result := task.Run("foo", "bar", "hello").Result().MustGet()
is.Equal(42, result)
}
func TestTask4(t *testing.T) {
is := assert.New(t)
task := NewTask4(func(a string, b string, c string, d string) *Future[int] {
return NewFuture(func(resolve func(int), reject func(error)) {
is.Equal("foo", a)
is.Equal("bar", b)
is.Equal("hello", c)
is.Equal("world", d)
resolve(42)
})
})
result := task.Run("foo", "bar", "hello", "world").Result().MustGet()
is.Equal(42, result)
}
func TestTask5(t *testing.T) {
is := assert.New(t)
task := NewTask5(func(a string, b string, c string, d string, e bool) *Future[int] {
return NewFuture(func(resolve func(int), reject func(error)) {
is.Equal("foo", a)
is.Equal("bar", b)
is.Equal("hello", c)
is.Equal("world", d)
is.True(e)
resolve(42)
})
})
result := task.Run("foo", "bar", "hello", "world", true).Result().MustGet()
is.Equal(42, result)
}