Skip to content

Commit

Permalink
gopls/internal: move builtin completion test to a regtest
Browse files Browse the repository at this point in the history
This test is more naturally expressed as a regtest. By moving it, we
eliminate the last place where the old marker test summary differs at a
go version.

For golang/go#54845

Change-Id: I7a99e2fba3bbec01ddf1aa93fb69cfb1c56e9882
Reviewed-on: https://go-review.googlesource.com/c/tools/+/528735
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 Sep 15, 2023
1 parent dca7c82 commit afa68c9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 101 deletions.
8 changes: 0 additions & 8 deletions gopls/internal/lsp/testdata/builtins/builtin_go117.go

This file was deleted.

8 changes: 0 additions & 8 deletions gopls/internal/lsp/testdata/builtins/builtin_go118.go

This file was deleted.

8 changes: 0 additions & 8 deletions gopls/internal/lsp/testdata/builtins/builtin_go121.go

This file was deleted.

8 changes: 0 additions & 8 deletions gopls/internal/lsp/testdata/builtins/builtin_go122.go

This file was deleted.

39 changes: 1 addition & 38 deletions gopls/internal/lsp/testdata/builtins/builtins.go
@@ -1,50 +1,13 @@
package builtins

// Definitions of builtin completion items.
// Definitions of builtin completion items that are still used in tests.

/* any */ //@item(any, "any", "", "interface")
/* Create markers for builtin types. Only for use by this test.
/* append(slice []Type, elems ...Type) []Type */ //@item(append, "append", "func(slice []Type, elems ...Type) []Type", "func")
/* bool */ //@item(bool, "bool", "", "type")
/* byte */ //@item(byte, "byte", "", "type")
/* cap(v Type) int */ //@item(cap, "cap", "func(v Type) int", "func")
/* clear[T interface{ ~[]Type | ~map[Type]Type1 }](t T) */ //@item(clear, "clear", "func(t T)", "func")
/* close(c chan<- Type) */ //@item(close, "close", "func(c chan<- Type)", "func")
/* comparable */ //@item(comparable, "comparable", "", "interface")
/* complex(r float64, i float64) */ //@item(complex, "complex", "func(r float64, i float64) complex128", "func")
/* complex128 */ //@item(complex128, "complex128", "", "type")
/* complex64 */ //@item(complex64, "complex64", "", "type")
/* copy(dst []Type, src []Type) int */ //@item(copy, "copy", "func(dst []Type, src []Type) int", "func")
/* delete(m map[Type]Type1, key Type) */ //@item(delete, "delete", "func(m map[Type]Type1, key Type)", "func")
/* error */ //@item(error, "error", "", "interface")
/* false */ //@item(_false, "false", "", "const")
/* float32 */ //@item(float32, "float32", "", "type")
/* float64 */ //@item(float64, "float64", "", "type")
/* imag(c complex128) float64 */ //@item(imag, "imag", "func(c complex128) float64", "func")
/* int */ //@item(int, "int", "", "type")
/* int16 */ //@item(int16, "int16", "", "type")
/* int32 */ //@item(int32, "int32", "", "type")
/* int64 */ //@item(int64, "int64", "", "type")
/* int8 */ //@item(int8, "int8", "", "type")
/* iota */ //@item(iota, "iota", "", "const")
/* len(v Type) int */ //@item(len, "len", "func(v Type) int", "func")
/* max(x T, y ...T) T */ //@item(max, "max", "func(x T, y ...T) T", "func")
/* min(y T, y ...T) T */ //@item(min, "min", "func(x T, y ...T) T", "func")
/* make(t Type, size ...int) Type */ //@item(make, "make", "func(t Type, size ...int) Type", "func")
/* new(Type) *Type */ //@item(new, "new", "func(Type) *Type", "func")
/* nil */ //@item(_nil, "nil", "", "var")
/* panic(v interface{}) */ //@item(panic, "panic", "func(v interface{})", "func")
/* print(args ...Type) */ //@item(print, "print", "func(args ...Type)", "func")
/* println(args ...Type) */ //@item(println, "println", "func(args ...Type)", "func")
/* real(c complex128) float64 */ //@item(real, "real", "func(c complex128) float64", "func")
/* recover() interface{} */ //@item(recover, "recover", "func() interface{}", "func")
/* rune */ //@item(rune, "rune", "", "type")
/* string */ //@item(string, "string", "", "type")
/* true */ //@item(_true, "true", "", "const")
/* uint */ //@item(uint, "uint", "", "type")
/* uint16 */ //@item(uint16, "uint16", "", "type")
/* uint32 */ //@item(uint32, "uint32", "", "type")
/* uint64 */ //@item(uint64, "uint64", "", "type")
/* uint8 */ //@item(uint8, "uint8", "", "type")
/* uintptr */ //@item(uintptr, "uintptr", "", "type")
/* zero */ //@item(zero, "zero", "", "var")
2 changes: 1 addition & 1 deletion gopls/internal/lsp/testdata/summary.txt.golden
@@ -1,6 +1,6 @@
-- summary --
CallHierarchyCount = 2
CompletionsCount = 259
CompletionsCount = 258
CompletionSnippetCount = 115
UnimportedCompletionsCount = 5
DeepCompletionsCount = 5
Expand Down
22 changes: 0 additions & 22 deletions gopls/internal/lsp/testdata/summary_go1.21.txt.golden

This file was deleted.

9 changes: 1 addition & 8 deletions gopls/internal/lsp/tests/tests.go
Expand Up @@ -41,6 +41,7 @@ const (
overlayFileSuffix = ".overlay"
goldenFileSuffix = ".golden"
inFileSuffix = ".in"
summaryFile = "summary.txt"

// The module path containing the testdata packages.
//
Expand All @@ -49,14 +50,6 @@ const (
testModule = "golang.org/lsptests"
)

var summaryFile = "summary.txt"

func init() {
if testenv.Go1Point() >= 21 {
summaryFile = "summary_go1.21.txt"
}
}

var UpdateGolden = flag.Bool("golden", false, "Update golden files")

// These type names apparently avoid the need to repeat the
Expand Down
47 changes: 47 additions & 0 deletions gopls/internal/regtest/completion/completion_test.go
Expand Up @@ -6,6 +6,7 @@ package completion

import (
"fmt"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -868,3 +869,49 @@ use ./dir/foobar/
}
})
}

func TestBuiltinCompletion(t *testing.T) {
const files = `
-- go.mod --
module mod.com
go 1.18
-- a.go --
package a
func _() {
// here
}
`

Run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("a.go")
result := env.Completion(env.RegexpSearch("a.go", `// here`))
builtins := []string{
"any", "append", "bool", "byte", "cap", "close",
"comparable", "complex", "complex128", "complex64", "copy", "delete",
"error", "false", "float32", "float64", "imag", "int", "int16", "int32",
"int64", "int8", "len", "make", "new", "panic", "print", "println", "real",
"recover", "rune", "string", "true", "uint", "uint16", "uint32", "uint64",
"uint8", "uintptr", "nil",
}
if testenv.Go1Point() >= 21 {
builtins = append(builtins, "clear", "max", "min")
}
sort.Strings(builtins)
var got []string

for _, item := range result.Items {
// TODO(rfindley): for flexibility, ignore zero while it is being
// implemented. Remove this if/when zero lands.
if item.Label != "zero" {
got = append(got, item.Label)
}
}
sort.Strings(got)

if diff := cmp.Diff(builtins, got); diff != "" {
t.Errorf("Completion: unexpected mismatch:\n%s", diff)
}
})
}

0 comments on commit afa68c9

Please sign in to comment.