-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_test.go
64 lines (52 loc) · 1.16 KB
/
basic_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
package provide_test
import (
"github.com/MatthewValentine/provide"
"runtime"
"strconv"
"testing"
)
func assert(t *testing.T, condition bool, args ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
t.Fatal(append([]interface{}{file + ":" + strconv.Itoa(line) + ":"}, args...)...)
}
}
func TestProvideBasic(t *testing.T) {
p, err := provide.NewProvider(
func() KrabbyPatty {
return "jabberwocky"
},
func(spongebob Spongebob) InPineapple {
return spongebob
},
func(patrick Patrick) UnderSea {
return patrick
},
)
assert(t, err == nil, err)
var ip InPineapple
var us UnderSea
err = p.Provide(&ip, &us)
assert(t, err == nil, err)
assert(t, ip == Spongebob{Patty: "jabberwocky"}, ip)
assert(t, us == Patrick{Patty: "jabberwocky"}, us)
}
type InPineapple interface {
inPineapple()
}
type UnderSea interface {
underSea()
}
type Spongebob struct {
Patty KrabbyPatty `provide:""`
}
func (Spongebob) inPineapple() {}
func (Spongebob) underSea() {}
type Patrick struct {
Patty KrabbyPatty
}
func (Patrick) underSea() {}
func (star *Patrick) PleaseProvide(kp KrabbyPatty) {
star.Patty = kp
}
type KrabbyPatty string