summaryrefslogtreecommitdiff
path: root/internal/lsp/compute_textedit_table_test.go
blob: b53f9a13e6e650b54af276a40068f1e00e0d10be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package lsp

import "testing"

func TestComputeTextEditAndFilter_Table(t *testing.T) {
	cases := []struct {
		name     string
		inParams bool
		current  string
		pos      Position
		cleaned  string
	}{
		{"ident_replace", false, "ab cd", Position{Line: 1, Character: 4}, "X"},
		{"params_inside", true, "func add(a int, b string)", Position{Line: 0, Character: 15}, "c bool"},
		{"params_at_close", true, "func add(a int)", Position{Line: 0, Character: len("func add(a int)")}, "b string"},
	}
	for _, c := range cases {
		te, _ := computeTextEditAndFilter(c.cleaned, c.inParams, c.current, CompletionParams{Position: c.pos})
		if te == nil {
			t.Fatalf("%s: expected edit", c.name)
		}
		if c.inParams && te.Range.Start.Character == 0 {
			t.Fatalf("%s: expected param range (non-zero start)", c.name)
		}

		if te.NewText != c.cleaned {
			t.Fatalf("%s: newText got %q want %q", c.name, te.NewText, c.cleaned)
		}
	}
}