MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / TestIntuitiveMethodSet

Function TestIntuitiveMethodSet

types/ui_test.go:16–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestIntuitiveMethodSet(t *testing.T) {
17 const source = `
18package P
19type A int
20func (A) f()
21func (*A) g()
22`
23
24 f, err := ParseString("hello.go", source)
25 if err != nil {
26 t.Fatal(err)
27 }
28
29 var conf Config
30 pkg, err := conf.Check("P", []*File{f}, nil)
31 if err != nil {
32 t.Fatal(err)
33 }
34 qual := RelativeTo(pkg)
35
36 for _, test := range []struct {
37 expr string // type expression
38 want string // intuitive method set
39 }{
40 {"A", "(A).f (*A).g"},
41 {"*A", "(*A).f (*A).g"},
42 {"error", "(error).Error"},
43 {"*error", ""},
44 {"struct{A}", "(struct{A}).f (*struct{A}).g"},
45 {"*struct{A}", "(*struct{A}).f (*struct{A}).g"},
46 } {
47 tv, err := Eval(pkg, NoPos, test.expr)
48 if err != nil {
49 t.Errorf("Eval(%s) failed: %v", test.expr, err)
50 }
51 var names []string
52 for _, m := range IntuitiveMethodSet(tv.Type, nil) {
53 name := fmt.Sprintf("(%s).%s", TypeString(m.Recv(), qual), m.Obj().Name())
54 names = append(names, name)
55 }
56 got := strings.Join(names, " ")
57 if got != test.want {
58 t.Errorf("IntuitiveMethodSet(%s) = %q, want %q", test.expr, got, test.want)
59 }
60 }
61}

Callers

nothing calls this directly

Calls 10

CheckMethod · 0.95
ParseStringFunction · 0.85
RelativeToFunction · 0.85
EvalFunction · 0.85
IntuitiveMethodSetFunction · 0.85
TypeStringFunction · 0.85
NameMethod · 0.65
appendFunction · 0.50
RecvMethod · 0.45
ObjMethod · 0.45

Tested by

no test coverage detected