|
| 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 lighlighting correctly |
| 15 | +// accounts for multi-name result parameters. |
| 16 | +// In golang/go#60589, it did not. |
| 17 | + |
| 18 | +func _() (foo int, bar, baz string) { //@ loc(func, "func"), loc(foo, "foo"), loc(fooint, "foo int"), loc(int, "int"), loc(bar, "bar"), loc(beforebaz, " baz"), loc(baz, "baz"), loc(barbazstring, "bar, baz string"), loc(beforestring, re`() string`), loc(string, "string") |
| 19 | + return 0, "1", "2" //@ loc(return, `return 0, "1", "2"`), loc(l0, "0"), loc(l1, `"1"`), loc(l2, `"2"`) |
| 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(x1, re`\((x)`), loc(x2, re`(x) int`), diag(x1, re"redeclared"), diag(x2, re"redeclared") |
| 42 | + return 1, 2 //@ loc(one, "1"), loc(two, "2") |
| 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) //@highlight("int", "int"), highlight("func", "func") |
| 57 | + |
| 58 | +-- issue65952.go -- |
| 59 | +package p |
| 60 | + |
| 61 | +// This test checks that gopls doesn't crash while highlighting |
| 62 | +// return values in functions with no results. |
| 63 | + |
| 64 | +func _() { |
| 65 | + return 0 //@highlight("0", "0"), diag("0", re"too many return") |
| 66 | +} |
| 67 | + |
| 68 | +func _() () { |
| 69 | + // TODO(golang/go#65966): fix the triplicate diagnostics here. |
| 70 | + return 0 //@highlight("0", "0"), diag("0", re"too many return"), diag("0", re"too many return"), diag("0", re"too many return") |
| 71 | +} |
0 commit comments