-
Notifications
You must be signed in to change notification settings - Fork 32
/
example_test.go
100 lines (87 loc) · 2.01 KB
/
example_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 interfaces_test
import (
"flag"
"fmt"
"io"
"net/http"
"github.com/rjeczalik/interfaces"
)
type ExampleFoo int
type ExampleBar struct{}
type ExampleBaz struct {
*ExampleBar
}
func (ExampleBar) A(int) int {
return 0
}
func (*ExampleBar) B(*string, io.Writer, ExampleFoo) (*ExampleFoo, int) {
return nil, 0
}
func (ExampleBar) C(map[string]int, *interfaces.Options, *http.Client) (chan []string, error) {
return nil, nil
}
func (ExampleBaz) D(*map[interface{}]struct{}, interface{}) (chan struct{}, []interface{}) {
return nil, nil
}
func (*ExampleBaz) E(*[]map[*flag.FlagSet]struct{}, [3]string) {}
func ExampleNew() {
i, err := interfaces.New(`github.com/rjeczalik/interfaces.ExampleBaz`)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Interface:")
for _, fn := range i {
fmt.Println(fn)
}
fmt.Println("Dependencies:")
for _, dep := range i.Deps() {
fmt.Println(dep)
}
// Output: Interface:
// A(int) int
// B(*string, io.Writer, interfaces_test.ExampleFoo) (*interfaces_test.ExampleFoo, int)
// C(map[string]int, *interfaces.Options, *http.Client) (chan []string, error)
// D(*map[interface{}]struct{}, interface{}) (chan struct{}, []interface{})
// E(*[]map[*flag.FlagSet]struct{}, [3]string)
// Dependencies:
// flag
// github.com/rjeczalik/interfaces
// github.com/rjeczalik/interfaces_test
// io
// net/http
}
func ExampleNewWithOptions() {
opts := &interfaces.Options{
Query: &interfaces.Query{
Package: "net",
TypeName: "Interface",
},
}
i, err := interfaces.NewWithOptions(opts)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Interface:")
for _, fn := range i {
fmt.Println(fn)
}
fmt.Println("Dependencies:")
for _, dep := range i.Deps() {
fmt.Println(dep)
}
// Output: Interface:
// Addrs() ([]net.Addr, error)
// MulticastAddrs() ([]net.Addr, error)
// Dependencies:
// net
}
func ExampleFunc_String() {
f := interfaces.Func{
Name: "Close",
Outs: []interfaces.Type{{Name: "error"}},
}
fmt.Println(f)
// Output: Close() error
}