forked from i-love-flamingo/dingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binding_test.go
50 lines (37 loc) · 1.05 KB
/
binding_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
package dingo
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBinding_To(t *testing.T) {
b := &Binding{typeof: reflect.TypeOf(new(string)).Elem()}
b.To(new(string))
assert.Equal(t, b.to, b.typeof)
assert.Panics(t, func() {
b.To(new(int))
})
}
func TestBinding_ToInstance(t *testing.T) {
b := &Binding{typeof: reflect.TypeOf(new(string)).Elem()}
b.ToInstance("test")
assert.Equal(t, b.instance.itype, b.typeof)
assert.Panics(t, func() {
b.ToInstance(123)
})
}
func TestBinding_ToProvider(t *testing.T) {
b := &Binding{typeof: reflect.TypeOf(new(string)).Elem()}
b.ToProvider(func() string { return "test" })
assert.Equal(t, b.provider.fnctype, b.typeof)
assert.Panics(t, func() {
b.ToProvider(b.ToProvider(func() int { return 123 }))
})
}
func TestBinding_equal(t *testing.T) {
b := &Binding{typeof: reflect.TypeOf(new(string)).Elem()}
b2 := &Binding{typeof: reflect.TypeOf(new(string)).Elem()}
b3 := &Binding{typeof: reflect.TypeOf(new(int)).Elem()}
assert.True(t, b.equal(b2))
assert.False(t, b.equal(b3))
}