1 | package main |
---|---|
2 | |
3 | // Tests of 'freevars' query. |
4 | // See go.tools/guru/guru_test.go for explanation. |
5 | // See freevars.golden for expected query results. |
6 | |
7 | // TODO(adonovan): it's hard to test this query in a single line of gofmt'd code. |
8 | |
9 | type T struct { |
10 | a, b int |
11 | } |
12 | |
13 | type S struct { |
14 | x int |
15 | t T |
16 | } |
17 | |
18 | func f(int) {} |
19 | |
20 | func main() { |
21 | type C int |
22 | x := 1 |
23 | const exp = 6 |
24 | if y := 2; x+y+int(C(3)) != exp { // @freevars fv1 "if.*{" |
25 | panic("expected 6") |
26 | } |
27 | |
28 | var s S |
29 | |
30 | for x, y := range "foo" { |
31 | println(s.x + s.t.a + s.t.b + x + int(y)) // @freevars fv2 "print.*y." |
32 | } |
33 | |
34 | f(x) // @freevars fv3 "f.x." |
35 | |
36 | loop: // @freevars fv-def-label "loop:" |
37 | for { |
38 | break loop // @freevars fv-ref-label "break loop" |
39 | } |
40 | } |
41 |