2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2020-09-02 09:51:59 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2017-11-29 16:01:49 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local exec = n.exec
|
|
|
|
local exec_capture = n.exec_capture
|
|
|
|
local feed = n.feed
|
|
|
|
local api = n.api
|
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
|
|
|
local expect = n.expect
|
|
|
|
local insert = n.insert
|
|
|
|
local eval = n.eval
|
2017-11-29 16:01:49 -07:00
|
|
|
|
|
|
|
describe(':*map', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('are not affected by &isident', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('counter', 0)
|
2017-11-29 16:01:49 -07:00
|
|
|
command('nnoremap <C-x> :let counter+=1<CR>')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('isident', ('%u'):format(('>'):byte()), {})
|
2017-11-29 16:01:49 -07:00
|
|
|
command('nnoremap <C-y> :let counter+=1<CR>')
|
|
|
|
-- &isident used to disable keycode parsing here as well
|
|
|
|
feed('\24\25<C-x><C-y>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, api.nvim_get_var('counter'))
|
2017-11-29 16:01:49 -07:00
|
|
|
end)
|
2017-10-18 15:27:31 -07:00
|
|
|
|
|
|
|
it(':imap <M-">', function()
|
|
|
|
command('imap <M-"> foo')
|
|
|
|
feed('i-<M-">-')
|
|
|
|
expect('-foo-')
|
|
|
|
end)
|
2022-01-07 04:28:14 -07:00
|
|
|
|
2022-12-25 20:20:37 -07:00
|
|
|
it('shows <Nop> as mapping rhs', function()
|
2022-03-01 17:14:39 -07:00
|
|
|
command('nmap asdf <Nop>')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
[[
|
2022-03-01 17:14:39 -07:00
|
|
|
|
|
|
|
n asdf <Nop>]],
|
2024-01-02 18:09:18 -07:00
|
|
|
exec_capture('nmap asdf')
|
|
|
|
)
|
2022-03-01 17:14:39 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('mappings with description can be filtered', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' })
|
|
|
|
api.nvim_set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' })
|
|
|
|
api.nvim_set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' })
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
[[
|
2022-03-01 17:14:39 -07:00
|
|
|
|
|
|
|
n asdf3 qwert
|
|
|
|
do the other thing
|
|
|
|
n asdf1 qwert
|
|
|
|
do the one thing]],
|
2024-01-02 18:09:18 -07:00
|
|
|
exec_capture('filter the nmap')
|
|
|
|
)
|
2022-03-01 17:14:39 -07:00
|
|
|
end)
|
|
|
|
|
2022-02-28 18:27:36 -07:00
|
|
|
it('<Plug> mappings ignore nore', function()
|
2022-01-07 04:28:14 -07:00
|
|
|
command('let x = 0')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_eval('x'))
|
2022-01-07 04:28:14 -07:00
|
|
|
command [[
|
|
|
|
nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
|
|
|
|
nmap increase_x_remap <Plug>(Increase_x)
|
|
|
|
nnoremap increase_x_noremap <Plug>(Increase_x)
|
|
|
|
]]
|
|
|
|
feed('increase_x_remap')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_eval('x'))
|
2022-01-07 04:28:14 -07:00
|
|
|
feed('increase_x_noremap')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, api.nvim_eval('x'))
|
2022-01-07 04:28:14 -07:00
|
|
|
end)
|
2022-02-28 18:27:36 -07:00
|
|
|
|
|
|
|
it("Doesn't auto ignore nore for keys before or after <Plug> mapping", function()
|
2022-01-07 04:28:14 -07:00
|
|
|
command('let x = 0')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_eval('x'))
|
2022-01-07 04:28:14 -07:00
|
|
|
command [[
|
|
|
|
nnoremap x <nop>
|
|
|
|
nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
|
|
|
|
nmap increase_x_remap x<Plug>(Increase_x)x
|
|
|
|
nnoremap increase_x_noremap x<Plug>(Increase_x)x
|
|
|
|
]]
|
2024-01-02 18:09:18 -07:00
|
|
|
insert('Some text')
|
2022-01-07 04:28:14 -07:00
|
|
|
eq('Some text', eval("getline('.')"))
|
|
|
|
|
|
|
|
feed('increase_x_remap')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_eval('x'))
|
2022-01-07 04:28:14 -07:00
|
|
|
eq('Some text', eval("getline('.')"))
|
|
|
|
feed('increase_x_noremap')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, api.nvim_eval('x'))
|
2022-01-07 04:28:14 -07:00
|
|
|
eq('Some te', eval("getline('.')"))
|
|
|
|
end)
|
2022-12-25 20:20:37 -07:00
|
|
|
|
|
|
|
it(':unmap with rhs works when lhs is in another bucket #21530', function()
|
|
|
|
command('map F <Plug>Foo')
|
|
|
|
command('unmap <Plug>Foo')
|
|
|
|
eq('\nNo mapping found', exec_capture('map F'))
|
|
|
|
end)
|
2017-11-29 16:01:49 -07:00
|
|
|
end)
|
2020-09-02 09:51:59 -07:00
|
|
|
|
2022-06-22 15:04:03 -07:00
|
|
|
describe('Screen', function()
|
2020-09-02 09:51:59 -07:00
|
|
|
local screen
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(20, 5)
|
|
|
|
end)
|
|
|
|
|
2022-02-16 17:37:33 -07:00
|
|
|
it('cursor is restored after :map <expr> which calls input()', function()
|
|
|
|
command('map <expr> x input("> ")')
|
2020-09-02 09:51:59 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2020-09-02 09:51:59 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
feed('x')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2020-09-02 09:51:59 -07:00
|
|
|
> ^ |
|
|
|
|
]])
|
|
|
|
feed('\n')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2020-09-02 09:51:59 -07:00
|
|
|
> |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2022-02-16 17:37:33 -07:00
|
|
|
it('cursor is restored after :imap <expr> which calls input()', function()
|
|
|
|
command('imap <expr> x input("> ")')
|
2020-09-02 09:51:59 -07:00
|
|
|
feed('i')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2020-09-02 09:51:59 -07:00
|
|
|
]])
|
|
|
|
feed('x')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2020-09-02 09:51:59 -07:00
|
|
|
> ^ |
|
|
|
|
]])
|
|
|
|
feed('\n')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2020-09-02 09:51:59 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2022-06-22 15:04:03 -07:00
|
|
|
it('cursor position does not move after empty-string :cmap <expr> #19046', function()
|
|
|
|
command([[cnoremap <expr> <F2> '']])
|
|
|
|
feed(':<F2>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2022-06-22 15:04:03 -07:00
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2022-11-11 18:57:29 -07:00
|
|
|
-- oldtest: Test_expr_map_restore_cursor()
|
2022-02-16 17:37:33 -07:00
|
|
|
it('cursor is restored after :map <expr> which redraws statusline vim-patch:8.1.2336', function()
|
|
|
|
exec([[
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
2
|
|
|
|
set ls=2
|
|
|
|
hi! link StatusLine ErrorMsg
|
|
|
|
noremap <expr> <C-B> Func()
|
|
|
|
func Func()
|
2022-06-22 15:04:03 -07:00
|
|
|
let g:on = !get(g:, 'on', 0)
|
|
|
|
redraws
|
|
|
|
return ''
|
2022-02-16 17:37:33 -07:00
|
|
|
endfunc
|
|
|
|
func Status()
|
2022-06-22 15:04:03 -07:00
|
|
|
return get(g:, 'on', 0) ? '[on]' : ''
|
2022-02-16 17:37:33 -07:00
|
|
|
endfunc
|
|
|
|
set stl=%{Status()}
|
|
|
|
]])
|
|
|
|
feed('<C-B>')
|
|
|
|
screen:expect([[
|
|
|
|
one |
|
|
|
|
^two |
|
|
|
|
three |
|
2024-03-22 03:02:52 -07:00
|
|
|
{9:[on] }|
|
2022-02-16 17:37:33 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('error in :nmap <expr> does not mess up display vim-patch:4.2.4338', function()
|
2020-09-02 09:51:59 -07:00
|
|
|
screen:try_resize(40, 5)
|
2022-02-16 17:37:33 -07:00
|
|
|
command('nmap <expr> <F2> execute("throw 42")')
|
|
|
|
feed('<F2>')
|
|
|
|
screen:expect([[
|
2024-03-22 03:02:52 -07:00
|
|
|
|
|
|
|
|
{3: }|
|
|
|
|
{9:Error detected while processing :} |
|
|
|
|
{9:E605: Exception not caught: 42} |
|
|
|
|
{6:Press ENTER or type command to continue}^ |
|
2022-02-16 17:37:33 -07:00
|
|
|
]])
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2022-02-16 17:37:33 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('error in :cmap <expr> handled correctly vim-patch:4.2.4338', function()
|
|
|
|
screen:try_resize(40, 5)
|
|
|
|
command('cmap <expr> <F2> execute("throw 42")')
|
2020-09-02 09:51:59 -07:00
|
|
|
feed(':echo "foo')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2020-09-02 09:51:59 -07:00
|
|
|
:echo "foo^ |
|
|
|
|
]])
|
2022-02-16 17:37:33 -07:00
|
|
|
feed('<F2>')
|
2020-09-02 09:51:59 -07:00
|
|
|
screen:expect([[
|
2024-03-22 03:02:52 -07:00
|
|
|
{3: }|
|
2020-09-02 09:51:59 -07:00
|
|
|
:echo "foo |
|
2024-03-22 03:02:52 -07:00
|
|
|
{9:Error detected while processing :} |
|
|
|
|
{9:E605: Exception not caught: 42} |
|
2020-09-02 09:51:59 -07:00
|
|
|
:echo "foo^ |
|
|
|
|
]])
|
|
|
|
feed('"')
|
|
|
|
screen:expect([[
|
2024-03-22 03:02:52 -07:00
|
|
|
{3: }|
|
2020-09-02 09:51:59 -07:00
|
|
|
:echo "foo |
|
2024-03-22 03:02:52 -07:00
|
|
|
{9:Error detected while processing :} |
|
|
|
|
{9:E605: Exception not caught: 42} |
|
2020-09-02 09:51:59 -07:00
|
|
|
:echo "foo"^ |
|
|
|
|
]])
|
|
|
|
feed('\n')
|
|
|
|
screen:expect([[
|
|
|
|
:echo "foo |
|
2024-03-22 03:02:52 -07:00
|
|
|
{9:Error detected while processing :} |
|
|
|
|
{9:E605: Exception not caught: 42} |
|
2020-09-02 09:51:59 -07:00
|
|
|
foo |
|
2024-03-22 03:02:52 -07:00
|
|
|
{6:Press ENTER or type command to continue}^ |
|
2020-09-02 09:51:59 -07:00
|
|
|
]])
|
|
|
|
end)
|
2022-02-16 17:37:33 -07:00
|
|
|
|
2022-11-11 18:57:29 -07:00
|
|
|
-- oldtest: Test_map_listing()
|
2022-02-16 17:37:33 -07:00
|
|
|
it('listing mappings clears command line vim-patch:8.2.4401', function()
|
|
|
|
screen:try_resize(40, 5)
|
|
|
|
command('nmap a b')
|
|
|
|
feed(': nmap a<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2022-02-16 17:37:33 -07:00
|
|
|
n a b |
|
|
|
|
]])
|
|
|
|
end)
|
2020-09-02 09:51:59 -07:00
|
|
|
end)
|