-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/regtest/marker: port statements completion tests
For golang/go#54845 Change-Id: I2257cac9ac7d08bffd4ba90eec4dcb5b750fcc44 Reviewed-on: https://go-review.googlesource.com/c/tools/+/537738 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
- Loading branch information
Showing
6 changed files
with
123 additions
and
103 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
gopls/internal/lsp/testdata/statements/if_err_check_return.go
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
gopls/internal/lsp/testdata/statements/if_err_check_return_2.go
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
gopls/internal/lsp/testdata/statements/if_err_check_test.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
gopls/internal/regtest/marker/testdata/completion/statements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
This test exercises completion around various statements. | ||
|
||
-- flags -- | ||
-ignore_extra_diags | ||
|
||
-- settings.json -- | ||
{ | ||
"usePlaceholders": true | ||
} | ||
|
||
-- go.mod -- | ||
module golang.org/lsptests/statements | ||
|
||
-- append.go -- | ||
package statements | ||
|
||
func _() { | ||
type mySlice []int | ||
|
||
var ( | ||
abc []int //@item(stmtABC, "abc", "[]int", "var") | ||
abcdef mySlice //@item(stmtABCDEF, "abcdef", "mySlice", "var") | ||
) | ||
|
||
/* abcdef = append(abcdef, ) */ //@item(stmtABCDEFAssignAppend, "abcdef = append(abcdef, )", "", "func") | ||
|
||
// don't offer "abc = append(abc, )" because "abc" isn't necessarily | ||
// better than "abcdef". | ||
abc //@complete(" //", stmtABC, stmtABCDEF) | ||
|
||
abcdef //@complete(" //", stmtABCDEF, stmtABCDEFAssignAppend) | ||
|
||
/* append(abc, ) */ //@item(stmtABCAppend, "append(abc, )", "", "func") | ||
|
||
abc = app //@snippet(" //", stmtABCAppend, "append(abc, ${1:})") | ||
} | ||
|
||
func _() { | ||
var s struct{ xyz []int } | ||
|
||
/* xyz = append(s.xyz, ) */ //@item(stmtXYZAppend, "xyz = append(s.xyz, )", "", "func") | ||
|
||
s.x //@snippet(" //", stmtXYZAppend, "xyz = append(s.xyz, ${1:})") | ||
|
||
/* s.xyz = append(s.xyz, ) */ //@item(stmtDeepXYZAppend, "s.xyz = append(s.xyz, )", "", "func") | ||
|
||
sx //@snippet(" //", stmtDeepXYZAppend, "s.xyz = append(s.xyz, ${1:})") | ||
} | ||
|
||
func _() { | ||
var foo [][]int | ||
|
||
/* append(foo[0], ) */ //@item(stmtFooAppend, "append(foo[0], )", "", "func") | ||
|
||
foo[0] = app //@complete(" //", stmtFooAppend),snippet(" //", stmtFooAppend, "append(foo[0], ${1:})") | ||
} | ||
|
||
-- if_err_check_return.go -- | ||
package statements | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
) | ||
|
||
func one() (int, float32, io.Writer, *int, []int, bytes.Buffer, error) { | ||
/* if err != nil { return err } */ //@item(stmtOneIfErrReturn, "if err != nil { return err }", "", "") | ||
/* err != nil { return err } */ //@item(stmtOneErrReturn, "err != nil { return err }", "", "") | ||
|
||
_, err := os.Open("foo") | ||
//@snippet("", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}") | ||
|
||
_, err = os.Open("foo") | ||
i //@snippet(" //", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}") | ||
|
||
_, err = os.Open("foo") | ||
if er //@snippet(" //", stmtOneErrReturn, "err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}") | ||
|
||
_, err = os.Open("foo") | ||
if //@snippet(" //", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}") | ||
|
||
_, err = os.Open("foo") | ||
if //@snippet("//", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}") | ||
} | ||
|
||
-- if_err_check_return2.go -- | ||
package statements | ||
|
||
import "os" | ||
|
||
func two() error { | ||
var s struct{ err error } | ||
|
||
/* if s.err != nil { return s.err } */ //@item(stmtTwoIfErrReturn, "if s.err != nil { return s.err }", "", "") | ||
|
||
_, s.err = os.Open("foo") | ||
//@snippet("", stmtTwoIfErrReturn, "if s.err != nil {\n\treturn ${1:s.err}\n\\}") | ||
} | ||
|
||
-- if_err_check_test.go -- | ||
package statements | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestErr(t *testing.T) { | ||
/* if err != nil { t.Fatal(err) } */ //@item(stmtOneIfErrTFatal, "if err != nil { t.Fatal(err) }", "", "") | ||
|
||
_, err := os.Open("foo") | ||
//@snippet("", stmtOneIfErrTFatal, "if err != nil {\n\tt.Fatal(err)\n\\}") | ||
} | ||
|
||
func BenchmarkErr(b *testing.B) { | ||
/* if err != nil { b.Fatal(err) } */ //@item(stmtOneIfErrBFatal, "if err != nil { b.Fatal(err) }", "", "") | ||
|
||
_, err := os.Open("foo") | ||
//@snippet("", stmtOneIfErrBFatal, "if err != nil {\n\tb.Fatal(err)\n\\}") | ||
} |