1 package describe // @describe pkgdecl "describe"
3 // Tests of 'describe' query.
4 // See go.tools/guru/guru_test.go for explanation.
5 // See describe.golden for expected query results.
7 // TODO(adonovan): more coverage of the (extensive) logic.
11 "nosuchpkg" // @describe badimport1 "nosuchpkg"
12 nosuchpkg2 "nosuchpkg" // @describe badimport2 "nosuchpkg2"
13 _ "unsafe" // @describe unsafe "unsafe"
19 type cake float64 // @describe type-ref-builtin "float64"
21 const c = iota // @describe const-ref-iota "iota"
23 const pi = 3.141 // @describe const-def-pi "pi"
24 const pie = cake(pi) // @describe const-def-pie "pie"
25 const _ = pi // @describe const-ref-pi "pi"
27 var global = new(string) // NB: ssa.Global is indirect, i.e. **string
29 func main() { // @describe func-def-main "main"
31 _ = main // @describe func-ref-main "main"
32 _ = (*C).f // @describe func-ref-*C.f "..C..f"
33 _ = D.f // @describe func-ref-D.f "D.f"
34 _ = I.f // @describe func-ref-I.f "I.f"
35 var d D // @describe type-D "D"
36 var i I // @describe type-I "I"
37 _ = d.f // @describe func-ref-d.f "d.f"
38 _ = i.f // @describe func-ref-i.f "i.f"
39 var slice []D // @describe slice-of-D "slice"
41 var dptr *D // @describe ptr-with-nonptr-methods "dptr"
46 _ = d // @describe ref-lexical-d "d"
48 _ = anon // @describe ref-anon "anon"
49 _ = global // @describe ref-global "global"
51 // SSA affords some local flow sensitivity.
53 var x = &a // @describe var-def-x-1 "x"
54 _ = x // @describe var-ref-x-1 "x"
55 x = &b // @describe var-def-x-2 "x"
56 _ = x // @describe var-ref-x-2 "x"
58 i = new(C) // @describe var-ref-i-C "i"
60 i = D{} // @describe var-ref-i-D "i"
62 print(i) // @describe var-ref-i "\\bi\\b"
65 const localpi = 3.141 // @describe const-local-pi "localpi"
66 const localpie = cake(pi) // @describe const-local-pie "localpie"
67 const _ = localpi // @describe const-ref-localpi "localpi"
70 type T int // @describe type-def-T "T"
71 var three T = 3 // @describe type-ref-T "T"
74 print(1 + 2*3) // @describe const-expr " 2.3"
75 print(real(1+2i) - 3) // @describe const-expr2 "real.*3"
77 m := map[string]*int{"a": &a}
78 mapval, _ := m["a"] // @describe map-lookup,ok "m..a.."
79 _ = mapval // @describe mapval "mapval"
80 _ = m // @describe m "m"
82 defer main() // @describe defer-stmt "defer"
83 go main() // @describe go-stmt "go"
85 panic(3) // @describe builtin-ref-panic "panic"
87 var a2 int // @describe var-decl-stmt "var a2 int"
89 var _ int // @describe var-decl-stmt2 "var _ int"
90 var _ int // @describe var-def-blank "_"
92 var _ lib.Outer // @describe lib-outer "Outer"
94 var mmm map[C]D // @describe var-map-of-C-D "mmm"
96 d := newD().ThirdField // @describe field-access "ThirdField"
99 unknown() // @describe call-unknown "\\("
102 type I interface { // @describe def-iface-I "I"
103 f() // @describe def-imethod-I.f "f"
116 func newD() D { return D{} }