Debian Codegraph @

gopls/internal/test/marker/testdata/highlight/controlflow.txt

raw
1 This test verifies document highlighting for control flow.
2
3 -- go.mod --
4 module mod.com
5
6 go 1.18
7
8 -- p.go --
9 package p
10
11 -- issue60589.go --
12 package p
13
14 // This test verifies that control flow highlighting correctly
15 // accounts for multi-name result parameters.
16 // In golang/go#60589, it did not.
17
18 func _() (foo int, bar, baz string) { //@ hiloc(func, "func", text), hiloc(foo, "foo", text), hiloc(fooint, "foo int", text), hiloc(int, "int", text), hiloc(bar, "bar", text), hiloc(beforebaz, " baz", text), hiloc(baz, "baz", text), hiloc(barbazstring, "bar, baz string", text), hiloc(beforestring, re`() string`, text), hiloc(string, "string", text)
19 return 0, "1", "2" //@ hiloc(return, `return 0, "1", "2"`, text), hiloc(l0, "0", text), hiloc(l1, `"1"`, text), hiloc(l2, `"2"`, text)
20 }
21
22 // Assertions, expressed here to avoid clutter above.
23 // Note that when the cursor is over the field type, there is some
24 // (likely harmless) redundancy.
25
26 //@ highlight(func, func, return)
27 //@ highlight(foo, foo, l0)
28 //@ highlight(int, fooint, int, l0)
29 //@ highlight(bar, bar, l1)
30 //@ highlight(beforebaz)
31 //@ highlight(baz, baz, l2)
32 //@ highlight(beforestring, baz, l2)
33 //@ highlight(string, barbazstring, string, l1, l2)
34 //@ highlight(l0, foo, l0)
35 //@ highlight(l1, bar, l1)
36 //@ highlight(l2, baz, l2)
37
38 // Check that duplicate result names do not cause
39 // inaccurate highlighting.
40
41 func _() (x, x int32) { //@ loc(locx1, re`\((x)`), loc(locx2, re`(x) int`), hiloc(x1, re`\((x)`, text), hiloc(x2, re`(x) int`, text), diag(locx1, re"redeclared"), diag(locx2, re"redeclared")
42 return 1, 2 //@ hiloc(one, "1", text), hiloc(two, "2", text)
43 }
44
45 //@ highlight(one, one, x1)
46 //@ highlight(two, two, x2)
47 //@ highlight(x1, x1, one)
48 //@ highlight(x2, x2, two)
49
50 -- issue65516.go --
51 package p
52
53 // This test checks that gopls doesn't crash while highlighting
54 // functions with no body (golang/go#65516).
55
56 func Foo() (int, string) //@hiloc(noBodyInt, "int", text), hiloc(noBodyFunc, "func", text)
57 //@highlight(noBodyInt, noBodyInt), highlight(noBodyFunc, noBodyFunc)
58
59 -- issue65952.go --
60 package p
61
62 // This test checks that gopls doesn't crash while highlighting
63 // return values in functions with no results.
64
65 func _() {
66 return 0 //@hiloc(ret1, "0", text), diag("0", re"too many return")
67 //@highlight(ret1, ret1)
68 }
69
70 func _() () {
71 return 0 //@hiloc(ret2, "0", text), diag("0", re"too many return")
72 //@highlight(ret2, ret2)
73 }