Skip to content

Commit

Permalink
gopls/internal/regtest/marker: port statements completion tests
Browse files Browse the repository at this point in the history
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
findleyr committed Oct 26, 2023
1 parent d187d99 commit b90ce15
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 103 deletions.
42 changes: 0 additions & 42 deletions gopls/internal/lsp/testdata/statements/append.go

This file was deleted.

27 changes: 0 additions & 27 deletions gopls/internal/lsp/testdata/statements/if_err_check_return.go

This file was deleted.

12 changes: 0 additions & 12 deletions gopls/internal/lsp/testdata/statements/if_err_check_return_2.go

This file was deleted.

20 changes: 0 additions & 20 deletions gopls/internal/lsp/testdata/statements/if_err_check_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions gopls/internal/lsp/testdata/summary.txt.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- summary --
CallHierarchyCount = 2
CompletionsCount = 181
CompletionSnippetCount = 53
CompletionsCount = 178
CompletionSnippetCount = 41
DeepCompletionsCount = 5
FuzzyCompletionsCount = 8
RankedCompletionsCount = 163
Expand Down
121 changes: 121 additions & 0 deletions gopls/internal/regtest/marker/testdata/completion/statements.txt
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\\}")
}

0 comments on commit b90ce15

Please sign in to comment.