-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_keymaps.lua
More file actions
103 lines (88 loc) · 3.81 KB
/
Copy pathtest_keymaps.lua
File metadata and controls
103 lines (88 loc) · 3.81 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
local reference_screenshot = MiniTest.expect.reference_screenshot
local child_helper = require("tests.child_helper")
local child = child_helper.new_child_neovim("test_keymaps")
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function()
child.run_pre_case(true)
child.bo.readonly = false
end,
post_once = child.stop,
},
})
T["keymaps()"] = MiniTest.new_set()
T["keymaps()"]["passthrough Esc - base test setting highlight"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[vim.keymap.set("n", "<Esc>", "<cmd>noh<CR>", { desc = "general clear highlights" })]])
child.lua([[
require("copilot.keymaps").register_keymap_with_passthrough("n", "<Esc>", function()
return true
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
]])
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
child.type_keys("/123", "<CR>")
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["keymaps()"]["passthrough Esc with func - return false, will remove hl"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua(
[[vim.keymap.set("n", "<Esc>", function() vim.cmd.nohlsearch() end, { desc = "general clear highlights" })]]
)
child.lua([[
require("copilot.keymaps").register_keymap_with_passthrough("n", "<esc>", function()
return false
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
]])
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
child.type_keys("/123", "<CR>")
child.type_keys("<Esc>")
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["keymaps()"]["passthrough Esc - return false, will remove hl"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[vim.keymap.set("n", "<Esc>", "<cmd>noh<CR>", { desc = "general clear highlights" })]])
child.lua([[
require("copilot.keymaps").register_keymap_with_passthrough("n", "<esc>", function()
return false
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
]])
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
child.type_keys("/123", "<CR>")
child.type_keys("<Esc>")
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["keymaps()"]["passthrough Esc - return true, will not remove hl"] = function()
child.o.lines, child.o.columns = 10, 15
child.lua([[vim.keymap.set("n", "<Esc>", "<cmd>noh<CR>", { desc = "general clear highlights" })]])
child.lua([[
require("copilot.keymaps").register_keymap_with_passthrough("n", "<Esc>", function()
return true
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
]])
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
child.type_keys("/123", "<CR>")
child.type_keys("<Esc>")
reference_screenshot(child.get_screenshot(), nil, { ignore_text = { 9, 10 }, ignore_attr = { 9, 10 } })
end
T["keymaps()"]["passthrough Tab - return false inserts tab character"] = function()
child.lua([[
require("copilot.keymaps").register_keymap_with_passthrough("i", "<Tab>", function()
return false
end, "Passthrough Tab", vim.api.nvim_get_current_buf())
]])
child.type_keys("i", "hello", "<Tab>", "world", "<Esc>")
local line = child.lua("return vim.api.nvim_get_current_line()")
MiniTest.expect.equality(line, "hello\tworld")
end
T["keymaps()"]["passthrough Right - return false moves cursor right"] = function()
child.lua([[
require("copilot.keymaps").register_keymap_with_passthrough("i", "<Right>", function()
return false
end, "Passthrough Right", vim.api.nvim_get_current_buf())
]])
child.type_keys("i", "abcd", "<Esc>", "0i", "<Right>", "X", "<Esc>")
local line = child.lua("return vim.api.nvim_get_current_line()")
MiniTest.expect.equality(line, "aXbcd")
end
return T