test: macros in Visual mode without default mappings (#28288)

This commit is contained in:
zeertzjq 2024-04-12 09:16:13 +08:00 committed by GitHub
parent 18ee9f9e7d
commit 8cca787155
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 133 additions and 33 deletions

View File

@ -93,6 +93,7 @@ do
"':normal! @'.getcharstr().'<CR>'", "':normal! @'.getcharstr().'<CR>'",
{ silent = true, expr = true, desc = ':help v_@-default' } { silent = true, expr = true, desc = ':help v_@-default' }
) )
--- Map |gx| to call |vim.ui.open| on the identifier under the cursor --- Map |gx| to call |vim.ui.open| on the identifier under the cursor
do do
local function do_open(uri) local function do_open(uri)

View File

@ -10,10 +10,11 @@ local fn = t.fn
local api = t.api local api = t.api
local insert = t.insert local insert = t.insert
describe('macros', function() describe('macros with default mappings', function()
before_each(function() before_each(function()
clear({ args_rm = { '--cmd' } }) clear({ args_rm = { '--cmd' } })
end) end)
it('can be recorded and replayed', function() it('can be recorded and replayed', function()
feed('qiahello<esc>q') feed('qiahello<esc>q')
expect('hello') expect('hello')
@ -22,6 +23,7 @@ describe('macros', function()
expect('hellohello') expect('hellohello')
eq('ahello', eval('@i')) eq('ahello', eval('@i'))
end) end)
it('applies maps', function() it('applies maps', function()
command('imap x l') command('imap x l')
command('nmap l a') command('nmap l a')
@ -34,87 +36,184 @@ describe('macros', function()
end) end)
it('can be replayed with Q', function() it('can be replayed with Q', function()
insert [[hello insert [[
hello
hello hello
hello]] hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>q]] feed [[qqAFOO<esc>q]]
eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOO
hello
hello]]
feed [[Q]] feed [[Q]]
eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOOFOO
hello
hello]]
feed [[G3Q]] feed [[G3Q]]
eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOOFOO
hello
helloFOOFOOFOO]]
feed [[ggV3jQ]] feed [[ggV3jQ]]
eq( expect [[
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, helloFOOFOOFOO
api.nvim_buf_get_lines(0, 0, -1, false) helloFOO
) helloFOOFOOFOOFOO]]
end) end)
it('can be replayed with @', function() it('can be replayed with Q and @@', function()
insert [[hello insert [[
hello
hello hello
hello]] hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>q]] feed [[qqAFOO<esc>q]]
eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOO
hello
hello]]
feed [[Q]] feed [[Q]]
eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOOFOO
hello
hello]]
feed [[G3@@]] feed [[G3@@]]
eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOOFOO
hello
helloFOOFOOFOO]]
feed [[ggV2j@@]] feed [[ggV2j@@]]
eq( expect [[
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, helloFOOFOOFOO
api.nvim_buf_get_lines(0, 0, -1, false) helloFOO
) helloFOOFOOFOOFOO]]
end) end)
it('can be replayed with @q and @w', function() it('can be replayed with @ in linewise Visual mode', function()
insert [[hello insert [[
hello
hello hello
hello]] hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>qu]] feed [[qqAFOO<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
hello
hello
hello]]
feed [[qwA123<esc>qu]] feed [[qwA123<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
hello
hello
hello]]
feed [[V3j@q]] feed [[V3j@q]]
eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOO
helloFOO
helloFOO]]
feed [[gg]] feed [[ggVj@w]]
feed [[Vj@w]] expect [[
eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) helloFOO123
helloFOO123
helloFOO]]
end) end)
it('can be replayed with @q and @w visual-block', function() -- XXX: does this really make sense?
insert [[hello it('can be replayed with @ in blockwise Visual mode', function()
insert [[
hello
hello hello
hello]] hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>qu]] feed [[qqAFOO<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
hello
hello
hello]]
feed [[qwA123<esc>qu]] feed [[qwA123<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
hello
hello
hello]]
feed [[<C-v>3j@q]] feed [[<C-v>3j@q]]
eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) expect [[
helloFOO
helloFOO
helloFOO]]
feed [[gg<C-v>j@w]]
expect [[
helloFOO123
helloFOO123
helloFOO]]
end)
end)
describe('macros without default mappings', function()
before_each(clear)
it('can be recorded and replayed in Visual mode', function()
insert('foo BAR BAR foo BAR foo BAR BAR BAR foo BAR BAR')
feed('0vqifofRq')
eq({ 0, 1, 7, 0 }, fn.getpos('.'))
eq({ 0, 1, 1, 0 }, fn.getpos('v'))
feed('Q')
eq({ 0, 1, 19, 0 }, fn.getpos('.'))
eq({ 0, 1, 1, 0 }, fn.getpos('v'))
feed('Q')
eq({ 0, 1, 27, 0 }, fn.getpos('.'))
eq({ 0, 1, 1, 0 }, fn.getpos('v'))
feed('@i')
eq({ 0, 1, 43, 0 }, fn.getpos('.'))
eq({ 0, 1, 1, 0 }, fn.getpos('v'))
end)
it('can be replayed with @ in blockwise Visual mode', function()
insert [[
hello
hello
hello]]
feed [[gg]] feed [[gg]]
feed [[<C-v>j@w]]
eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[qqAFOO<esc>qu]]
expect [[
hello
hello
hello]]
feed [[qwA123<esc>qu]]
expect [[
hello
hello
hello]]
feed [[0<C-v>3jl@q]]
expect [[
heFOOllo
heFOOllo
heFOOllo]]
feed [[gg0<C-v>j@w]]
expect [[
h123eFOOllo
h123eFOOllo
heFOOllo]]
end) end)
end) end)