-
Notifications
You must be signed in to change notification settings - Fork 0
/
completer_test.go
123 lines (115 loc) · 2.05 KB
/
completer_test.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewCompleter(t *testing.T) {
c := newWordCompleter()
type completion struct {
head string
completions []string
tail string
}
tests := []struct {
title string
line string
pos int
expected completion
}{
{
"empty",
"",
0,
completion{
head: "",
completions: []string{},
tail: "",
},
},
{
"only partials",
"low",
3,
completion{
head: "",
completions: []string{"lower"},
tail: "",
},
},
{
"cursor is not at the end",
"low",
1,
completion{
head: "",
completions: []string{"lower"},
tail: "",
},
},
{
"two tokens",
"if low",
6,
completion{
head: "if ",
completions: []string{"lower"},
tail: "",
},
},
{
"two tokens and cursor in the middle",
"if low",
3,
completion{
head: "if ",
completions: []string{"lower"},
tail: "",
},
},
{
"cursor points non-function",
"if low",
0,
completion{
head: "",
completions: []string{},
tail: " low",
},
},
{
"many tokens (cursor at the end)",
"1 | add int6",
12,
completion{
head: "1 | add ",
completions: []string{"int64"},
tail: "",
},
},
{
"many tokens (cursor in the middle)",
"1 | ad int64",
4,
completion{
head: "1 | ",
completions: []string{"add", "add1f", "add1", "addf", "adler32sum"},
tail: " int64",
},
},
}
for _, tt := range tests {
t.Run(tt.title, func(t *testing.T) {
head, completions, tail := c(tt.line, tt.pos)
assert.Equal(t, tt.expected.head, head, "wrong head")
assert.ElementsMatch(t, tt.expected.completions, completions, "wrong completions")
assert.Equal(t, tt.expected.tail, tail, "wrong tail")
})
}
}
func allFuncNames() []string {
names := []string{}
for name := range funcMap() {
names = append(names, name)
}
return names
}