github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/oracle/testdata/src/describe/main.go (about) 1 package describe // @describe pkgdecl "describe" 2 3 // Tests of 'describe' query. 4 // See go.tools/oracle/oracle_test.go for explanation. 5 // See describe.golden for expected query results. 6 7 // TODO(adonovan): more coverage of the (extensive) logic. 8 9 import ( 10 "nosuchpkg" // @describe badimport1 "nosuchpkg" 11 nosuchpkg2 "nosuchpkg" // @describe badimport2 "nosuchpkg2" 12 ) 13 14 var _ nosuchpkg.T 15 var _ nosuchpkg2.T 16 17 type cake float64 // @describe type-ref-builtin "float64" 18 19 const c = iota // @describe const-ref-iota "iota" 20 21 const pi = 3.141 // @describe const-def-pi "pi" 22 const pie = cake(pi) // @describe const-def-pie "pie" 23 const _ = pi // @describe const-ref-pi "pi" 24 25 var global = new(string) // NB: ssa.Global is indirect, i.e. **string 26 27 func main() { // @describe func-def-main "main" 28 // func objects 29 _ = main // @describe func-ref-main "main" 30 _ = (*C).f // @describe func-ref-*C.f "..C..f" 31 _ = D.f // @describe func-ref-D.f "D.f" 32 _ = I.f // @describe func-ref-I.f "I.f" 33 var d D // @describe type-D "D" 34 var i I // @describe type-I "I" 35 _ = d.f // @describe func-ref-d.f "d.f" 36 _ = i.f // @describe func-ref-i.f "i.f" 37 38 // var objects 39 anon := func() { 40 _ = d // @describe ref-lexical-d "d" 41 } 42 _ = anon // @describe ref-anon "anon" 43 _ = global // @describe ref-global "global" 44 45 // SSA affords some local flow sensitivity. 46 var a, b int 47 var x = &a // @describe var-def-x-1 "x" 48 _ = x // @describe var-ref-x-1 "x" 49 x = &b // @describe var-def-x-2 "x" 50 _ = x // @describe var-ref-x-2 "x" 51 52 i = new(C) // @describe var-ref-i-C "i" 53 if i != nil { 54 i = D{} // @describe var-ref-i-D "i" 55 } 56 print(i) // @describe var-ref-i "\\bi\\b" 57 58 // const objects 59 const localpi = 3.141 // @describe const-local-pi "localpi" 60 const localpie = cake(pi) // @describe const-local-pie "localpie" 61 const _ = localpi // @describe const-ref-localpi "localpi" 62 63 // type objects 64 type T int // @describe type-def-T "T" 65 var three T = 3 // @describe type-ref-T "T" 66 _ = three 67 68 print(1 + 2*3) // @describe const-expr " 2.3" 69 print(real(1+2i) - 3) // @describe const-expr2 "real.*3" 70 71 m := map[string]*int{"a": &a} 72 mapval, _ := m["a"] // @describe map-lookup,ok "m..a.." 73 _ = mapval // @describe mapval "mapval" 74 _ = m // @describe m "m" 75 76 defer main() // @describe defer-stmt "defer" 77 go main() // @describe go-stmt "go" 78 79 panic(3) // @describe builtin-ref-panic "panic" 80 81 var a2 int // @describe var-decl-stmt "var a2 int" 82 _ = a2 83 var _ int // @describe var-decl-stmt2 "var _ int" 84 var _ int // @describe var-def-blank "_" 85 } 86 87 type I interface { // @describe def-iface-I "I" 88 f() // @describe def-imethod-I.f "f" 89 } 90 91 type C int 92 type D struct{} 93 94 func (c *C) f() {} 95 func (d D) f() {}