-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetcallback_test.go
More file actions
43 lines (39 loc) · 864 Bytes
/
setcallback_test.go
File metadata and controls
43 lines (39 loc) · 864 Bytes
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
package nject
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSetCallbackInvokeOnly(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var cb func(s1, s2) s3
setCallback := func(h func(s1, s2) s3) {
cb = h
}
require.NoError(t,
Sequence("SCBT",
func(x s2, y s1) s3 {
return s3(y) + s3(x)
},
).SetCallback(setCallback))
assert.Equal(t, s3("foobar"), cb("foo", "bar"))
})
}
func TestSetCallbackWithInit(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var cb func(s2) s3
var cbInit func(s1)
setCallback := func(h func(s2) s3, i func(s1)) {
cb = h
cbInit = i
}
require.NoError(t,
Sequence("SCBT",
func(x s2, y s1) s3 {
return s3(y) + s3(x)
},
).SetCallback(setCallback))
cbInit("foo")
assert.Equal(t, s3("foobar"), cb("bar"))
})
}