forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_suggestion.lua
More file actions
133 lines (118 loc) · 3.72 KB
/
Copy pathtest_suggestion.lua
File metadata and controls
133 lines (118 loc) · 3.72 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
-- local eq = MiniTest.expect.equality
-- local neq = MiniTest.expect.no_equality
local reference_screenshot = MiniTest.expect.reference_screenshot
local child = MiniTest.new_child_neovim()
-- local u = require("tests.utils")
local T = MiniTest.new_set({
hooks = {
pre_once = function()
if vim.fn.filereadable("./tests/logs/test_suggestion.log") == 1 then
vim.fn.delete("./tests/logs/test_suggestion.log")
end
end,
pre_case = function()
child.restart({ "-u", "tests/scripts/minimal_init.lua" })
child.bo.readonly = false
child.lua("M = require('copilot')")
child.lua("cmd = require('copilot.command')")
-- child.lua([[require("osv").launch({ port = 8086 })]])
end,
post_once = child.stop,
},
})
T["suggestion()"] = MiniTest.new_set()
-- TODO: Need means of watching for the suggestion to popup and not randomly wait x ms
-- Should be able to use the screenshot to parsse for the suggesetion, u.get_lines does not work
-- Also, this test can fail if the LSP is taking more time than usual and re-running it passes
T["suggestion()"]["suggestion works"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[M.setup({
suggestion = {
auto_trigger = true,
},
logger = {
file_log_level = vim.log.levels.TRACE,
file = "./tests/logs/test_suggestion.log",
},
filetypes = {
["*"] = true,
},
})]])
-- look for a synchronous way to wait for engine to be up
vim.loop.sleep(500)
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7")
vim.loop.sleep(3000)
child.lua("vim.wait(0)")
reference_screenshot(child.get_screenshot())
end
T["suggestion()"]["auto_trigger is false, will not show ghost test"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[M.setup({
suggestion = {
auto_trigger = false,
},
logger = {
file_log_level = vim.log.levels.TRACE,
file = "./tests/logs/test_suggestion.log",
},
filetypes = {
["*"] = true,
},
})]])
-- look for a synchronous way to wait for engine to be up
vim.loop.sleep(500)
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7")
vim.loop.sleep(3000)
child.lua("vim.wait(0)")
reference_screenshot(child.get_screenshot())
end
T["suggestion()"]["accept keymap to trigger sugestion"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[M.setup({
suggestion = {
auto_trigger = false,
keymap = {
accept = "<Tab>",
},
},
logger = {
file_log_level = vim.log.levels.TRACE,
file = "./tests/logs/test_suggestion.log",
},
filetypes = {
["*"] = true,
},
})]])
-- look for a synchronous way to wait for engine to be up
vim.loop.sleep(500)
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7", "<Tab>")
vim.loop.sleep(3000)
child.lua("vim.wait(0)")
reference_screenshot(child.get_screenshot())
end
T["suggestion()"]["accept keymap, no suggestion, execute normal keystroke"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[M.setup({
suggestion = {
auto_trigger = false,
trigger_on_accept = false,
keymap = {
accept = "<Tab>",
},
},
logger = {
file_log_level = vim.log.levels.TRACE,
file = "./tests/logs/test_suggestion.log",
},
filetypes = {
["*"] = true,
},
})]])
-- look for a synchronous way to wait for engine to be up
vim.loop.sleep(500)
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7", "<Tab>")
vim.loop.sleep(3000)
child.lua("vim.wait(0)")
reference_screenshot(child.get_screenshot())
end
return T