Skip to content

Commit

Permalink
internal/lsp: use a marker test for struct field ranking test
Browse files Browse the repository at this point in the history
Change-Id: I70faef2c789a3cc7b4dee8c7dd5dcac0e06d7568
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270880
Trust: Rebecca Stambler <[email protected]>
Run-TryBot: Rebecca Stambler <[email protected]>
gopls-CI: kokoro <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
stamblerre committed Nov 18, 2020
1 parent 74a3905 commit bd56c0a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 49 deletions.
48 changes: 0 additions & 48 deletions gopls/internal/regtest/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,54 +193,6 @@ package ma
})
}

// Test the order of completion suggestions
func TestStructLiteralCompletion(t *testing.T) {
const files = `
-- go.mod --
module mod.com
-- foo.go --
package foo
type Foo struct {
c int
b int
a int
}
func f() {
foo := Foo{
}
}
`

want := []string{"c", "b", "a"}

run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("foo.go")
completions := env.Completion("foo.go", fake.Pos{
Line: 10,
Column: 0,
})

diff := compareCompletionResultsOnlyHead(want, completions.Items)
if diff != "" {
t.Fatal(diff)
return
}
})
}

func compareCompletionResultsOnlyHead(want []string, gotItems []protocol.CompletionItem) string {
for i := range want {
if want[i] != gotItems[i].Label {
return fmt.Sprintf("completion results are not the same: got %v, want %v", gotItems[i].Label, want[i])
}
}
return ""
}

func compareCompletionResults(want []string, gotItems []protocol.CompletionItem) string {
if len(gotItems) != len(want) {
return fmt.Sprintf("got %v completion(s), want %v", len(gotItems), len(want))
Expand Down
11 changes: 11 additions & 0 deletions internal/lsp/testdata/rank/struct/struct_rank.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package struct_rank

type foo struct {
c int //@item(c_rank, "c", "int", "field")
b int //@item(b_rank, "b", "int", "field")
a int //@item(a_rank, "a", "int", "field")
}

func f() {
foo := foo{} //@rank("}", c_rank, b_rank, a_rank)
}
2 changes: 1 addition & 1 deletion internal/lsp/testdata/summary.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CompletionSnippetCount = 85
UnimportedCompletionsCount = 5
DeepCompletionsCount = 5
FuzzyCompletionsCount = 8
RankedCompletionsCount = 157
RankedCompletionsCount = 158
CaseSensitiveCompletionsCount = 4
DiagnosticsCount = 43
FoldingRangesCount = 2
Expand Down

0 comments on commit bd56c0a

Please sign in to comment.