-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_nes.lua
More file actions
79 lines (71 loc) · 2.04 KB
/
Copy pathtest_nes.lua
File metadata and controls
79 lines (71 loc) · 2.04 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
local eq = MiniTest.expect.equality
local child_helper = require("tests.child_helper")
local child = child_helper.new_child_neovim("test_nes")
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function()
child.run_pre_case(true)
end,
post_once = child.stop,
},
})
T["nes()"] = MiniTest.new_set()
T["nes()"]["setup does nothing when nes is disabled"] = function()
child.configure_copilot()
local result = child.lua([[
local config = require("copilot.config")
config.nes.enabled = false
local nes = require("copilot.nes")
nes.initialized = false
nes.setup({})
return nes.initialized
]])
eq(result, false)
end
T["nes()"]["set_keymap does nothing when nes is disabled"] = function()
child.configure_copilot()
child.lua([[
local config = require("copilot.config")
config.nes.enabled = false
local nes = require("copilot.nes")
nes.set_keymap(vim.api.nvim_get_current_buf())
]])
end
T["nes()"]["unset_keymap does nothing when nes is disabled"] = function()
child.configure_copilot()
child.lua([[
local config = require("copilot.config")
config.nes.enabled = false
local nes = require("copilot.nes")
nes.unset_keymap(vim.api.nvim_get_current_buf())
]])
end
T["nes()"]["teardown does nothing when not initialized"] = function()
child.configure_copilot()
child.lua([[
local nes = require("copilot.nes")
nes.initialized = false
nes.teardown()
]])
end
T["nes()"]["setup catches copilot-lsp errors gracefully"] = function()
child.configure_copilot()
local result = child.lua([[
local config = require("copilot.config")
config.nes.enabled = true
-- Mock nes_api to throw an error
package.loaded["copilot.nes.api"] = {
nes_lsp_on_init = function()
error("copilot-lsp not found")
end,
}
-- Reload nes module to pick up mocked api
package.loaded["copilot.nes"] = nil
local nes = require("copilot.nes")
local ok = pcall(nes.setup, {})
return ok
]])
eq(result, true)
end
return T