summaryrefslogtreecommitdiff
path: root/internal/lsp/prefix_table_test.go
blob: d3629279431b772f5a1245835def9076a1542a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package lsp

import "testing"

func TestPrefixStripping_Table(t *testing.T) {
	cases := []struct{ name, prefix, sugg, want string }{
		{"assign_walrus", "name := ", "name := compute()", "compute()"},
		{"assign_equals", "x = ", "x = y+1", "y+1"},
		{"general_db", "db.", "db.Query()", "Query()"},
		{"general_func", "func New ", "func New() *T", "() *T"},
	}
	for _, c := range cases {
		var got string
		if c.name == "assign_walrus" || c.name == "assign_equals" {
			got = stripDuplicateAssignmentPrefix(c.prefix, c.sugg)
		} else {
			got = stripDuplicateGeneralPrefix(c.prefix, c.sugg)
		}
		if got != c.want {
			t.Fatalf("%s: got %q want %q", c.name, got, c.want)
		}
	}
}