forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.lua
More file actions
211 lines (164 loc) · 6.25 KB
/
test_client.lua
File metadata and controls
211 lines (164 loc) · 6.25 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
local reference_screenshot = MiniTest.expect.reference_screenshot
local child_helper = require("tests.child_helper")
local child = child_helper.new_child_neovim("test_client")
local u = require("tests.utils")
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function()
child.run_pre_case()
child.lua("s = require('copilot.status')")
child.lua("c = require('copilot.client')")
end,
post_once = child.stop,
},
})
T["client.config()"] = MiniTest.new_set()
T["client.config()"]["config, github-enterprise populated"] = function()
child.lua([[M.setup({
auth_provider_url = "https://someurl.com",
})]])
local settings = child.lua("return vim.inspect(c.config.settings)")
u.expect_match(settings, "{.*github%-enterprise.*{.*uri.*https://someurl%.com.*}.*}")
end
T["client()"] = MiniTest.new_set()
T["client()"]["status info"] = function()
child.configure_copilot()
child.cmd("Copilot status")
local messages = child.lua([[
local messages = ""
local function has_passed()
messages = vim.api.nvim_exec("messages", { output = true }) or ""
if messages:find(".*Online.*Enabled.*") then
return true
end
end
vim.wait(5000, function()
return has_passed()
end, 50)
return messages
]])
u.expect_match(messages, ".*Online.*Enabled.*")
end
T["client()"] = MiniTest.new_set()
T["client()"]["suggestions work when multiple files open with should_attach logic"] = function()
child.config.should_attach = [[function(bufnr, bufname)
local buffername = bufname:match("([^/\\]+)$") or ""
if not _G.bufnames then
_G.bufnames = ''
end
_G.bufnames = _G.bufnames .. ' ; ' .. buffername.. ' (' .. tostring(bufnr) .. ')'
if buffername == "file2.txt" then
return true
end
return false
end]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.cmd("e tests/files/file1.txt")
child.cmd("e tests/files/file2.txt")
child.type_keys("i")
child.type_keys("123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["client()"]["suggestions off when previous file only should_attach"] = function()
child.config.should_attach = [[function(bufnr, bufname)
local buffername = bufname:match("([^/\\]+)$") or ""
if buffername == "file1.txt" then
return true
end
return false
end]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.cmd("e tests/files/file1.txt")
child.cmd("e tests/files/file2.txt")
child.type_keys("i")
child.type_keys("123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["client()"]["suggestions off when previous file only should_attach - 2"] = function()
child.config.should_attach = [[function(bufnr, bufname)
local buffername = bufname:match("([^/\\]+)$") or ""
if buffername == "file2.txt" then
return true
end
return false
end]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.cmd("e tests/files/file1.txt")
child.cmd("e tests/files/file2.txt")
child.type_keys("i")
child.cmd("e tests/files/file3.txt")
child.type_keys("123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["client()"]["suggestions work when already in insert mode and opening file - 3"] = function()
child.config.should_attach = [[function(bufnr, bufname)
local buffername = bufname:match("([^/\\]+)$") or ""
if buffername == "file3.txt" then
return true
end
return false
end]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.cmd("e tests/files/file1.txt")
child.cmd("e tests/files/file2.txt")
child.type_keys("i")
child.cmd("e tests/files/file3.txt")
child.type_keys("123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["client()"]["suggestions work when attaching to second buffer in a row"] = function()
child.config.should_attach = [[function(bufnr, bufname)
local buffername = bufname:match("([^/\\]+)$") or ""
if buffername == "file3.txt" then
return true
end
return false
end]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.cmd("e tests/files/file1.txt")
child.cmd("e tests/files/file2.txt")
child.type_keys("i123", "<Esc>")
child.cmd("e tests/files/file3.txt")
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["client()"]["suggestions work when lazy is set to false"] = function()
child.config.should_attach = [[function(bufnr, bufname)
local buffername = bufname:match("([^/\\]+)$") or ""
if buffername == "file3.txt" then
return true
end
return false
end]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.cmd("e tests/files/file1.txt")
child.cmd("e tests/files/file2.txt")
child.type_keys("i123", "<Esc>")
child.cmd("e tests/files/file3.txt")
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["client()"]["will not attach to buffer due to filetype exclusion"] = function()
child.config.filetypes = [[
["*"] = false,
]]
child.config.suggestion = child.config.suggestion .. "auto_trigger = true,"
child.configure_copilot()
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7")
child.wait_for_suggestion()
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
return T