-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimplement_test.go
56 lines (53 loc) · 991 Bytes
/
implement_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
package gospec
import "testing"
// func (s *Spec) Implements(v, t string) bool
func TestImplements01(t *testing.T) {
s := NewSpec(`
type T interface {
m()
}
type V struct{}
func (v V) m() {}
var x V
`)
if _, ok := ToInterface(s.GetType("T")); ok {
if s.Implements("x", "T") {
} else {
t.Errorf("test failed")
}
} else {
t.Errorf("test failed")
}
}
// Implements(v, t types.Type) bool
// or
// Implements(v, t types.Object) bool
// or
// Implements((code, v, t string) bool
func TestImplements02(t *testing.T) {
code := `
type T interface {
m()
}
type V struct{}
func (v V) m() {}
var x V
`
s := NewSpec(code)
if _, ok := ToInterface(s.GetType("T")); ok {
if Implements(s.GetType("x"), s.GetType("T")) {
} else {
t.Errorf("test failed")
}
if Implements(s.GetTypeObject("x"), s.GetTypeObject("T")) {
} else {
t.Errorf("test failed")
}
if Implements(code, "x", "T") {
} else {
t.Errorf("test failed")
}
} else {
t.Errorf("test failed")
}
}