Skip to content

Commit a7d6bd7

Browse files
author
Illia Shkroba
committed
test(repeatable_move): add operator-pending mode test cases
1 parent baf3605 commit a7d6bd7

File tree

1 file changed

+78
-3
lines changed

1 file changed

+78
-3
lines changed

tests/repeatable_move/common.lua

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function M.run_builtin_find_test(file, spec)
2020
for col = 0, num_cols - 1 do
2121
for _, cmd in pairs({ 'f', 'F', 't', 'T' }) do
2222
for _, repeat_cmd in pairs({ ';', ',' }) do
23-
-- Get ground truth using vim's built-in search and repeat
23+
-- Get ground truth using vim's built-in search and repeat (normal mode)
2424
vim.api.nvim_win_set_cursor(0, { spec.row, col })
2525
local gt_cols = {}
2626
vim.cmd([[normal! ]] .. cmd .. spec.char)
@@ -36,7 +36,7 @@ function M.run_builtin_find_test(file, spec)
3636
vim.cmd([[normal! 2]] .. cmd .. spec.char)
3737
gt_cols[#gt_cols + 1] = vim.fn.col('.')
3838

39-
-- test using tstextobj repeatable_move.lua
39+
-- test using tstextobj repeatable_move.lua (normal mode)
4040
vim.api.nvim_win_set_cursor(0, { spec.row, col })
4141
local ts_cols = {}
4242
vim.cmd([[normal ]] .. cmd .. spec.char)
@@ -61,7 +61,82 @@ function M.run_builtin_find_test(file, spec)
6161
assert.are.same(
6262
gt_cols,
6363
ts_cols,
64-
string.format("Command %s works differently than vim's built-in find, col: %d", cmd, col)
64+
string.format(
65+
"Command %s with repeat %s works differently than vim's built-in find, col: %d",
66+
cmd,
67+
repeat_cmd,
68+
col
69+
)
70+
)
71+
72+
-- Get ground truth using vim's built-in search and repeat (operator-pending mode)
73+
vim.api.nvim_win_set_cursor(0, { spec.row, col })
74+
local gt_regs = {}
75+
vim.fn.setreg('0', '')
76+
vim.cmd([[normal! y]] .. cmd .. spec.char)
77+
gt_regs[#gt_regs + 1] = vim.fn.getreg('0')
78+
vim.fn.setreg('0', '')
79+
vim.cmd([[normal! y]] .. repeat_cmd)
80+
gt_regs[#gt_regs + 1] = vim.fn.getreg('0')
81+
vim.fn.setreg('0', '')
82+
vim.cmd([[normal! y2]] .. repeat_cmd)
83+
gt_regs[#gt_regs + 1] = vim.fn.getreg('0')
84+
vim.fn.setreg('0', '')
85+
vim.cmd([[normal! l]] .. repeat_cmd)
86+
vim.fn.setreg('0', '')
87+
vim.cmd([[normal! y2]] .. repeat_cmd)
88+
gt_regs[#gt_regs + 1] = vim.fn.getreg('0')
89+
vim.fn.setreg('0', '')
90+
vim.cmd([[normal! h]] .. repeat_cmd)
91+
vim.fn.setreg('0', '')
92+
vim.cmd([[normal! y2]] .. repeat_cmd)
93+
gt_regs[#gt_regs + 1] = vim.fn.getreg('0')
94+
vim.fn.setreg('0', '')
95+
vim.cmd([[normal! 2y]] .. cmd .. spec.char)
96+
gt_regs[#gt_regs + 1] = vim.fn.getreg('0')
97+
98+
-- test using tstextobj repeatable_move.lua (operator-pending mode)
99+
vim.api.nvim_win_set_cursor(0, { spec.row, col })
100+
local ts_regs = {}
101+
vim.fn.setreg('0', '')
102+
vim.cmd([[normal y]] .. cmd .. spec.char)
103+
ts_regs[#ts_regs + 1] = vim.fn.getreg('0')
104+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
105+
vim.fn.setreg('0', '')
106+
vim.cmd([[normal y]] .. repeat_cmd)
107+
ts_regs[#ts_regs + 1] = vim.fn.getreg('0')
108+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
109+
vim.fn.setreg('0', '')
110+
vim.cmd([[normal y2]] .. repeat_cmd)
111+
ts_regs[#ts_regs + 1] = vim.fn.getreg('0')
112+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
113+
vim.fn.setreg('0', '')
114+
vim.cmd([[normal l]] .. repeat_cmd)
115+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
116+
vim.fn.setreg('0', '')
117+
vim.cmd([[normal y2]] .. repeat_cmd)
118+
ts_regs[#ts_regs + 1] = vim.fn.getreg('0')
119+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
120+
vim.fn.setreg('0', '')
121+
vim.cmd([[normal h]] .. repeat_cmd)
122+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
123+
vim.fn.setreg('0', '')
124+
vim.cmd([[normal y2]] .. repeat_cmd)
125+
ts_regs[#ts_regs + 1] = vim.fn.getreg('0')
126+
assert.are.same(spec.row, vim.fn.line('.'), "Command shouldn't move cursor over rows")
127+
vim.fn.setreg('0', '')
128+
vim.cmd([[normal 2y]] .. cmd .. spec.char)
129+
ts_regs[#ts_regs + 1] = vim.fn.getreg('0')
130+
131+
assert.are.same(
132+
gt_regs,
133+
ts_regs,
134+
string.format(
135+
"Command %s with repeat %s works differently than vim's built-in find, col: %d",
136+
cmd,
137+
repeat_cmd,
138+
col
139+
)
65140
)
66141
end
67142
end

0 commit comments

Comments
 (0)