forked from x-motemen/gore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete_test.go
119 lines (97 loc) · 3.22 KB
/
complete_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
package gore
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/confetti-framework/baker/gocode"
)
func TestSession_completeWord(t *testing.T) {
if gocode.Available() == false {
t.Skipf("gocode unavailable")
}
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
s, err := NewSession(stdout, stderr)
defer s.Clear()
require.NoError(t, err)
pre, cands, post := s.completeWord("", 0)
assert.Equal(t, "", pre)
assert.Equal(t, []string{" "}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(" x", 4)
assert.Equal(t, "", pre)
assert.Equal(t, []string{" "}, cands)
assert.Equal(t, post, "x")
pre, cands, post = s.completeWord(" : :", 4)
assert.Equal(t, "", pre)
assert.Equal(t, []string{
" : :import ",
" : :type ",
" : :print",
" : :write ",
" : :clear",
" : :doc ",
" : :help",
" : :quit",
}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(" : : i", 6)
assert.Equal(t, "", pre)
assert.Equal(t, []string{" : : import "}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord("::i t", 5)
assert.Equal(t, "::i ", pre)
assert.Equal(t, []string{"testing", "text", "time"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord("::i gor", 7)
assert.Equal(t, "::i ", pre)
assert.Equal(t, []string{"github.com/confetti-framework/baker"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":i gore", 7)
assert.Equal(t, ":i ", pre)
assert.Equal(t, []string{"github.com/confetti-framework/baker"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":i to", 5)
assert.Equal(t, ":i ", pre)
assert.Equal(t, []string{"golang.org/x/tools"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":i qu", 5)
assert.Equal(t, ":i ", pre)
assert.Equal(t, []string{"github.com/motemen/go-quickfix"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":i go-qu", 8)
assert.Equal(t, ":i ", pre)
assert.Equal(t, []string{"github.com/motemen/go-quickfix"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":i go-", 6)
assert.Equal(t, ":i ", pre)
assert.Equal(t, []string{
"github.com/davecgh/go-spew", "github.com/mattn/go-runewidth",
"github.com/motemen/go-quickfix", "github.com/pmezard/go-difflib",
}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":i mot", 6)
assert.Equal(t, ":i ", pre)
assert.Equal(t, []string{
"github.com/confetti-framework/baker", "github.com/motemen/go-quickfix",
}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(":c", 2)
assert.Equal(t, "", pre)
assert.Equal(t, []string{":clear"}, cands)
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(" : : q", 6)
assert.Equal(t, "", pre)
assert.Equal(t, []string{" : : quit"}, cands)
assert.Equal(t, post, "")
err = actionImport(s, "fmt")
require.NoError(t, err)
pre, cands, post = s.completeWord("fmt.p", 5)
assert.Equal(t, "fmt.", pre)
assert.Contains(t, cands, "Println(")
assert.Equal(t, post, "")
pre, cands, post = s.completeWord(" ::: doc f", 11)
assert.Equal(t, " ::: doc ", pre)
assert.Equal(t, []string{" fmt"}, cands)
assert.Equal(t, post, "")
}