2024-04-20 08:44:13 -07:00
|
|
|
|
local t = require('test.testutil')
|
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-04-19 04:01:41 -07:00
|
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
|
local eval = n.eval
|
|
|
|
|
local feed = n.feed
|
|
|
|
|
local clear = n.clear
|
|
|
|
|
local expect = n.expect
|
|
|
|
|
local command = n.command
|
|
|
|
|
local fn = n.fn
|
|
|
|
|
local api = n.api
|
|
|
|
|
local insert = n.insert
|
2017-04-19 04:01:41 -07:00
|
|
|
|
|
2024-04-11 18:16:13 -07:00
|
|
|
|
describe('macros with default mappings', function()
|
2023-12-26 16:26:18 -07:00
|
|
|
|
before_each(function()
|
2024-01-02 18:09:18 -07:00
|
|
|
|
clear({ args_rm = { '--cmd' } })
|
2023-12-26 16:26:18 -07:00
|
|
|
|
end)
|
2024-04-11 18:16:13 -07:00
|
|
|
|
|
2017-04-19 04:01:41 -07:00
|
|
|
|
it('can be recorded and replayed', function()
|
|
|
|
|
feed('qiahello<esc>q')
|
|
|
|
|
expect('hello')
|
2022-04-25 20:35:05 -07:00
|
|
|
|
eq('ahello', eval('@i'))
|
2017-04-19 04:01:41 -07:00
|
|
|
|
feed('@i')
|
|
|
|
|
expect('hellohello')
|
2022-04-25 20:35:05 -07:00
|
|
|
|
eq('ahello', eval('@i'))
|
2017-04-19 04:01:41 -07:00
|
|
|
|
end)
|
2024-04-11 18:16:13 -07:00
|
|
|
|
|
2017-04-19 04:01:41 -07:00
|
|
|
|
it('applies maps', function()
|
|
|
|
|
command('imap x l')
|
|
|
|
|
command('nmap l a')
|
|
|
|
|
feed('qilxxx<esc>q')
|
|
|
|
|
expect('lll')
|
2022-04-25 20:35:05 -07:00
|
|
|
|
eq('lxxx', eval('@i'))
|
2017-04-19 04:01:41 -07:00
|
|
|
|
feed('@i')
|
|
|
|
|
expect('llllll')
|
2022-04-25 20:35:05 -07:00
|
|
|
|
eq('lxxx', eval('@i'))
|
2017-04-19 04:01:41 -07:00
|
|
|
|
end)
|
2021-08-17 06:56:37 -07:00
|
|
|
|
|
|
|
|
|
it('can be replayed with Q', function()
|
2024-04-11 18:16:13 -07:00
|
|
|
|
insert [[
|
|
|
|
|
hello
|
2021-08-17 06:56:37 -07:00
|
|
|
|
hello
|
|
|
|
|
hello]]
|
|
|
|
|
feed [[gg]]
|
|
|
|
|
|
|
|
|
|
feed [[qqAFOO<esc>q]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOO
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2021-08-17 06:56:37 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[Q]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOOFOO
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2021-08-17 06:56:37 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[G3Q]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOOFOO
|
|
|
|
|
hello
|
|
|
|
|
helloFOOFOOFOO]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[ggV3jQ]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOOFOOFOO
|
|
|
|
|
helloFOO
|
|
|
|
|
helloFOOFOOFOOFOO]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2024-04-11 18:16:13 -07:00
|
|
|
|
it('can be replayed with Q and @@', function()
|
|
|
|
|
insert [[
|
|
|
|
|
hello
|
2023-12-26 16:26:18 -07:00
|
|
|
|
hello
|
|
|
|
|
hello]]
|
|
|
|
|
feed [[gg]]
|
|
|
|
|
|
|
|
|
|
feed [[qqAFOO<esc>q]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOO
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[Q]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOOFOO
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[G3@@]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOOFOO
|
|
|
|
|
hello
|
|
|
|
|
helloFOOFOOFOO]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[ggV2j@@]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOOFOOFOO
|
|
|
|
|
helloFOO
|
|
|
|
|
helloFOOFOOFOOFOO]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2024-04-11 18:16:13 -07:00
|
|
|
|
it('can be replayed with @ in linewise Visual mode', function()
|
|
|
|
|
insert [[
|
|
|
|
|
hello
|
2023-12-26 16:26:18 -07:00
|
|
|
|
hello
|
|
|
|
|
hello]]
|
|
|
|
|
feed [[gg]]
|
|
|
|
|
|
|
|
|
|
feed [[qqAFOO<esc>qu]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
hello
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
|
|
|
|
feed [[qwA123<esc>qu]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
hello
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed [[V3j@q]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
expect [[
|
|
|
|
|
helloFOO
|
|
|
|
|
helloFOO
|
|
|
|
|
helloFOO]]
|
|
|
|
|
|
|
|
|
|
feed [[ggVj@w]]
|
|
|
|
|
expect [[
|
|
|
|
|
helloFOO123
|
|
|
|
|
helloFOO123
|
|
|
|
|
helloFOO]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2024-04-11 18:16:13 -07:00
|
|
|
|
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)
|
2023-12-26 16:26:18 -07:00
|
|
|
|
|
2024-04-11 18:16:13 -07:00
|
|
|
|
it('can be replayed with @ in blockwise Visual mode', function()
|
|
|
|
|
insert [[
|
|
|
|
|
hello
|
|
|
|
|
hello
|
|
|
|
|
hello]]
|
2023-12-26 16:26:18 -07:00
|
|
|
|
feed [[gg]]
|
2024-04-11 18:16:13 -07:00
|
|
|
|
|
|
|
|
|
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]]
|
2021-08-17 06:56:37 -07:00
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
|
2022-04-07 06:13:09 -07:00
|
|
|
|
describe('immediately after a macro has finished executing,', function()
|
|
|
|
|
before_each(function()
|
2023-12-26 16:26:18 -07:00
|
|
|
|
clear()
|
2022-04-07 06:13:09 -07:00
|
|
|
|
command([[let @a = 'gg0']])
|
|
|
|
|
end)
|
|
|
|
|
|
2022-04-06 23:27:47 -07:00
|
|
|
|
describe('reg_executing() from RPC returns an empty string', function()
|
|
|
|
|
it('if the macro does not end with a <Nop> mapping', function()
|
|
|
|
|
feed('@a')
|
2024-01-12 10:59:57 -07:00
|
|
|
|
eq('', fn.reg_executing())
|
2022-04-06 23:27:47 -07:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('if the macro ends with a <Nop> mapping', function()
|
|
|
|
|
command('nnoremap 0 <Nop>')
|
|
|
|
|
feed('@a')
|
2024-01-12 10:59:57 -07:00
|
|
|
|
eq('', fn.reg_executing())
|
2022-04-06 23:27:47 -07:00
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
|
2022-04-07 06:13:09 -07:00
|
|
|
|
describe('characters from a mapping are not treated as a part of the macro #18015', function()
|
|
|
|
|
before_each(function()
|
|
|
|
|
command('nnoremap s qa')
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('if the macro does not end with a <Nop> mapping', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
|
2024-01-12 10:59:57 -07:00
|
|
|
|
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
|
2022-04-07 06:13:09 -07:00
|
|
|
|
expect('')
|
|
|
|
|
eq('', eval('@a'))
|
|
|
|
|
end)
|
2021-08-17 06:56:37 -07:00
|
|
|
|
|
2022-04-07 06:13:09 -07:00
|
|
|
|
it('if the macro ends with a <Nop> mapping', function()
|
|
|
|
|
command('nnoremap 0 <Nop>')
|
2024-01-02 18:09:18 -07:00
|
|
|
|
feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
|
2024-01-12 10:59:57 -07:00
|
|
|
|
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
|
2022-04-07 06:13:09 -07:00
|
|
|
|
expect('')
|
|
|
|
|
eq('', eval('@a'))
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
describe('reg_recorded()', function()
|
2023-12-26 16:26:18 -07:00
|
|
|
|
before_each(clear)
|
2021-08-17 06:56:37 -07:00
|
|
|
|
it('returns the correct value', function()
|
|
|
|
|
feed [[qqyyq]]
|
|
|
|
|
eq('q', eval('reg_recorded()'))
|
|
|
|
|
end)
|
2017-04-19 04:01:41 -07:00
|
|
|
|
end)
|