aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-12 09:16:13 +0800
committerGitHub <noreply@github.com>2024-04-12 09:16:13 +0800
commit8cca7871555e15f53de3dc4325c8d0203a78622a (patch)
tree9711632ec66454d39dc5a8306dd39d9c89c31366
parent18ee9f9e7dbbc9709ee9c1572870b4ad31443569 (diff)
downloadrneovim-8cca7871555e15f53de3dc4325c8d0203a78622a.tar.gz
rneovim-8cca7871555e15f53de3dc4325c8d0203a78622a.tar.bz2
rneovim-8cca7871555e15f53de3dc4325c8d0203a78622a.zip
test: macros in Visual mode without default mappings (#28288)
-rw-r--r--runtime/lua/vim/_defaults.lua1
-rw-r--r--test/functional/editor/macro_spec.lua165
2 files changed, 133 insertions, 33 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 90d05f67a5..2f02c2b389 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -93,6 +93,7 @@ do
"':normal! @'.getcharstr().'<CR>'",
{ silent = true, expr = true, desc = ':help v_@-default' }
)
+
--- Map |gx| to call |vim.ui.open| on the identifier under the cursor
do
local function do_open(uri)
diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua
index 3ccf1ea770..a2a165ab0f 100644
--- a/test/functional/editor/macro_spec.lua
+++ b/test/functional/editor/macro_spec.lua
@@ -10,10 +10,11 @@ local fn = t.fn
local api = t.api
local insert = t.insert
-describe('macros', function()
+describe('macros with default mappings', function()
before_each(function()
clear({ args_rm = { '--cmd' } })
end)
+
it('can be recorded and replayed', function()
feed('qiahello<esc>q')
expect('hello')
@@ -22,6 +23,7 @@ describe('macros', function()
expect('hellohello')
eq('ahello', eval('@i'))
end)
+
it('applies maps', function()
command('imap x l')
command('nmap l a')
@@ -34,87 +36,184 @@ describe('macros', function()
end)
it('can be replayed with Q', function()
- insert [[hello
+ insert [[
+hello
hello
hello]]
feed [[gg]]
feed [[qqAFOO<esc>q]]
- eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOO
+hello
+hello]]
feed [[Q]]
- eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOOFOO
+hello
+hello]]
feed [[G3Q]]
- eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOOFOO
+hello
+helloFOOFOOFOO]]
feed [[ggV3jQ]]
- eq(
- { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
- api.nvim_buf_get_lines(0, 0, -1, false)
- )
+ expect [[
+helloFOOFOOFOO
+helloFOO
+helloFOOFOOFOOFOO]]
end)
- it('can be replayed with @', function()
- insert [[hello
+ it('can be replayed with Q and @@', function()
+ insert [[
+hello
hello
hello]]
feed [[gg]]
feed [[qqAFOO<esc>q]]
- eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOO
+hello
+hello]]
feed [[Q]]
- eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOOFOO
+hello
+hello]]
feed [[G3@@]]
- eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOOFOO
+hello
+helloFOOFOOFOO]]
feed [[ggV2j@@]]
- eq(
- { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
- api.nvim_buf_get_lines(0, 0, -1, false)
- )
+ expect [[
+helloFOOFOOFOO
+helloFOO
+helloFOOFOOFOOFOO]]
end)
- it('can be replayed with @q and @w', function()
- insert [[hello
+ it('can be replayed with @ in linewise Visual mode', function()
+ insert [[
+hello
hello
hello]]
feed [[gg]]
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]]
- eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+hello
+hello
+hello]]
feed [[V3j@q]]
- eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+helloFOO
+helloFOO
+helloFOO]]
- feed [[gg]]
- feed [[Vj@w]]
- eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ feed [[ggVj@w]]
+ expect [[
+helloFOO123
+helloFOO123
+helloFOO]]
end)
- it('can be replayed with @q and @w visual-block', function()
- insert [[hello
+ -- XXX: does this really make sense?
+ it('can be replayed with @ in blockwise Visual mode', function()
+ insert [[
+hello
hello
hello]]
feed [[gg]]
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]]
- eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ expect [[
+hello
+hello
+hello]]
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 [[<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)