aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds/cmd_map_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/ex_cmds/cmd_map_spec.lua')
-rw-r--r--test/functional/ex_cmds/cmd_map_spec.lua333
1 files changed, 98 insertions, 235 deletions
diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua
index 2a2628350d..cb7d7340e2 100644
--- a/test/functional/ex_cmds/cmd_map_spec.lua
+++ b/test/functional/ex_cmds/cmd_map_spec.lua
@@ -4,7 +4,7 @@ local feed = helpers.feed
local eq = helpers.eq
local expect = helpers.expect
local eval = helpers.eval
-local funcs = helpers.funcs
+local fn = helpers.fn
local insert = helpers.insert
local write_file = helpers.write_file
local exc_exec = helpers.exc_exec
@@ -16,24 +16,24 @@ describe('mappings with <Cmd>', function()
local tmpfile = 'X_ex_cmds_cmd_map'
local function cmdmap(lhs, rhs)
- command('noremap '..lhs..' <Cmd>'..rhs..'<cr>')
- command('noremap! '..lhs..' <Cmd>'..rhs..'<cr>')
+ command('noremap ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>')
+ command('noremap! ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>')
end
before_each(function()
clear()
screen = Screen.new(65, 8)
screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
- [3] = {bold = true, foreground = Screen.colors.SeaGreen4},
- [4] = {bold = true},
- [5] = {background = Screen.colors.LightGrey},
- [6] = {foreground = Screen.colors.Blue1},
- [7] = {bold = true, reverse = true},
- [8] = {background = Screen.colors.WebGray},
- [9] = {background = Screen.colors.LightMagenta},
- [10] = {foreground = Screen.colors.Red},
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
+ [3] = { bold = true, foreground = Screen.colors.SeaGreen4 },
+ [4] = { bold = true },
+ [5] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
+ [6] = { foreground = Screen.colors.Blue1 },
+ [7] = { bold = true, reverse = true },
+ [8] = { background = Screen.colors.WebGray },
+ [9] = { background = Screen.colors.LightMagenta },
+ [10] = { foreground = Screen.colors.Red },
})
screen:attach()
@@ -57,7 +57,7 @@ describe('mappings with <Cmd>', function()
feed('gg')
cmdmap('<F8>', 'startinsert')
cmdmap('<F9>', 'stopinsert')
- command("abbr foo <Cmd>let g:y = 17<cr>bar")
+ command('abbr foo <Cmd>let g:y = 17<cr>bar')
end)
after_each(function()
@@ -69,11 +69,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
^some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{6:<F3>} {6:*} {6:<Cmd>}let m = mode(1){6:<CR>} |
]])
end)
@@ -85,11 +81,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
^some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{2:E1136: <Cmd> mapping must end with <CR> before second <Cmd>} |
]])
@@ -98,11 +90,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
^some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{2:E1255: <Cmd> mapping must end with <CR>} |
]])
eq(0, eval('x'))
@@ -114,11 +102,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
^of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
|
]])
@@ -127,11 +111,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of ^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
|
]])
end)
@@ -141,7 +121,7 @@ describe('mappings with <Cmd>', function()
feed('<F3>')
eq('foo…bar', eval('g:str'))
local str = eval([["foo\<D-…>bar"]])
- command([[noremap <F3> <Cmd>let g:str = ']]..str..[['<CR>]])
+ command([[noremap <F3> <Cmd>let g:str = ']] .. str .. [['<CR>]])
feed('<F3>')
eq(str, eval('g:str'))
command([[noremap <F3> <Cmd>let g:str = 'foo<D-…>bar'<CR>]])
@@ -180,7 +160,7 @@ describe('mappings with <Cmd>', function()
eq('n', eval('mode(1)'))
-- operator-pending mode
- feed("d<F3>")
+ feed('d<F3>')
eq('no', eval('m'))
-- did leave operator-pending mode
eq('n', eval('mode(1)'))
@@ -191,21 +171,21 @@ describe('mappings with <Cmd>', function()
eq('i', eval('mode(1)'))
-- replace mode
- feed("<Ins><F3>")
+ feed('<Ins><F3>')
eq('R', eval('m'))
eq('R', eval('mode(1)'))
feed('<esc>')
eq('n', eval('mode(1)'))
-- virtual replace mode
- feed("gR<F3>")
+ feed('gR<F3>')
eq('Rv', eval('m'))
eq('Rv', eval('mode(1)'))
feed('<esc>')
eq('n', eval('mode(1)'))
-- langmap works, but is not distinguished in mode(1)
- feed(":set iminsert=1<cr>i<F3>")
+ feed(':set iminsert=1<cr>i<F3>')
eq('i', eval('m'))
eq('i', eval('mode(1)'))
feed('<esc>')
@@ -232,26 +212,22 @@ describe('mappings with <Cmd>', function()
-- check v:count and v:register works
feed('<F2>')
- eq({'n', 0, '"'}, eval('s'))
+ eq({ 'n', 0, '"' }, eval('s'))
feed('7<F2>')
- eq({'n', 7, '"'}, eval('s'))
+ eq({ 'n', 7, '"' }, eval('s'))
feed('"e<F2>')
- eq({'n', 0, 'e'}, eval('s'))
+ eq({ 'n', 0, 'e' }, eval('s'))
feed('5"k<F2>')
- eq({'n', 5, 'k'}, eval('s'))
+ eq({ 'n', 5, 'k' }, eval('s'))
feed('"+2<F2>')
- eq({'n', 2, '+'}, eval('s'))
+ eq({ 'n', 2, '+' }, eval('s'))
-- text object enters visual mode
feed('<F7>')
screen:expect([[
so{5:me short lines} |
{5:of }^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- VISUAL --} |
]])
feed('<esc>')
@@ -269,15 +245,11 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of alpha^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT --} |
]])
-- feedkeys were not executed immediately
- eq({'n', 'of test text'}, eval('[m,a]'))
+ eq({ 'n', 'of test text' }, eval('[m,a]'))
eq('i', eval('mode(1)'))
feed('<esc>')
@@ -285,15 +257,11 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of alphabet^atest text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
|
]])
-- feedkeys(..., 'x') was executed immediately, but insert mode gets aborted
- eq({'n', 'of alphabetatest text'}, eval('[m,b]'))
+ eq({ 'n', 'of alphabetatest text' }, eval('[m,b]'))
eq('n', eval('mode(1)'))
end)
@@ -302,45 +270,39 @@ describe('mappings with <Cmd>', function()
command('noremap ,f <Cmd>nosuchcommand<cr>')
command('noremap ,e <Cmd>throw "very error"\\| call append(1, "yy")<cr>')
command('noremap ,m <Cmd>echoerr "The message."\\| call append(1, "zz")<cr>')
- command('noremap ,w <Cmd>for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor<cr>')
+ command(
+ 'noremap ,w <Cmd>for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor<cr>'
+ )
- feed(":normal ,x<cr>")
+ feed(':normal ,x<cr>')
screen:expect([[
^some short lines |
aa |
xx |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*3
:normal ,x |
]])
- eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec("normal ,f"))
- eq('very error', exc_exec("normal ,e"))
- eq('Vim(echoerr):The message.', exc_exec("normal ,m"))
+ eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec('normal ,f'))
+ eq('very error', exc_exec('normal ,e'))
+ eq('Vim(echoerr):The message.', exc_exec('normal ,m'))
feed('w')
screen:expect([[
some ^short lines |
aa |
xx |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*3
:normal ,x |
]])
command(':%d')
- eq('Vim(echoerr):Err', exc_exec("normal ,w"))
+ eq('Vim(echoerr):Err', exc_exec('normal ,w'))
screen:expect([[
^ |
0 |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
--No lines in buffer-- |
]])
@@ -364,27 +326,22 @@ describe('mappings with <Cmd>', function()
screen:expect([[
{5:some short }^lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- VISUAL --} |
]])
- eq('v', funcs.mode(1))
+ eq('v', fn.mode(1))
-- can invoke operator, ending visual mode
feed('<F5>')
- eq('n', funcs.mode(1))
- eq({'some short l'}, funcs.getreg('a',1,1))
+ eq('n', fn.mode(1))
+ eq({ 'some short l' }, fn.getreg('a', 1, 1))
-- error doesn't interrupt visual mode
feed('ggvw<F6>')
screen:expect([[
{5:some }short lines |
of test text |
- {1:~ }|
- {1:~ }|
+ {1:~ }|*2
{7: }|
{2:Error detected while processing :} |
{2:E605: Exception not caught: very error} |
@@ -396,37 +353,25 @@ describe('mappings with <Cmd>', function()
screen:expect([[
{5:some }^short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- VISUAL --} |
]])
- eq('v', funcs.mode(1))
+ eq('v', fn.mode(1))
feed('<F7>')
screen:expect([[
so{5:me short lines} |
{5:of }^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- VISUAL --} |
]])
- eq('v', funcs.mode(1))
+ eq('v', fn.mode(1))
-- startinsert gives "-- (insert) VISUAL --" mode
feed('<F8>')
screen:expect([[
so{5:me short lines} |
{5:of }^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- (insert) VISUAL --} |
]])
eq('v', eval('mode(1)'))
@@ -442,32 +387,27 @@ describe('mappings with <Cmd>', function()
screen:expect([[
{5:some short }^lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- SELECT --} |
]])
- eq('s', funcs.mode(1))
+ eq('s', fn.mode(1))
-- visual mapping in select mode restart select mode after operator
feed('<F5>')
- eq('s', funcs.mode(1))
- eq({'some short l'}, funcs.getreg('a',1,1))
+ eq('s', fn.mode(1))
+ eq({ 'some short l' }, fn.getreg('a', 1, 1))
-- select mode mapping works, and does not restart select mode
feed('<F2>')
- eq('n', funcs.mode(1))
- eq({'some short l'}, funcs.getreg('b',1,1))
+ eq('n', fn.mode(1))
+ eq({ 'some short l' }, fn.getreg('b', 1, 1))
-- error doesn't interrupt temporary visual mode
feed('<esc>ggvw<c-g><F6>')
screen:expect([[
{5:some }short lines |
of test text |
- {1:~ }|
- {1:~ }|
+ {1:~ }|*2
{7: }|
{2:Error detected while processing :} |
{2:E605: Exception not caught: very error} |
@@ -479,23 +419,18 @@ describe('mappings with <Cmd>', function()
screen:expect([[
{5:some }^short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- VISUAL --} |
]])
-- quirk: restoration of select mode is not performed
- eq('v', funcs.mode(1))
+ eq('v', fn.mode(1))
-- error doesn't interrupt select mode
feed('<esc>ggvw<c-g><F1>')
screen:expect([[
{5:some }short lines |
of test text |
- {1:~ }|
- {1:~ }|
+ {1:~ }|*2
{7: }|
{2:Error detected while processing :} |
{2:E605: Exception not caught: very error} |
@@ -507,39 +442,27 @@ describe('mappings with <Cmd>', function()
screen:expect([[
{5:some }^short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- SELECT --} |
]])
-- quirk: restoration of select mode is not performed
- eq('s', funcs.mode(1))
+ eq('s', fn.mode(1))
feed('<F7>')
screen:expect([[
so{5:me short lines} |
{5:of }^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- SELECT --} |
]])
- eq('s', funcs.mode(1))
+ eq('s', fn.mode(1))
-- startinsert gives "-- SELECT (insert) --" mode
feed('<F8>')
screen:expect([[
so{5:me short lines} |
{5:of }^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- (insert) SELECT --} |
]])
eq('s', eval('mode(1)'))
@@ -547,17 +470,16 @@ describe('mappings with <Cmd>', function()
eq('i', eval('mode(1)'))
end)
-
it('works in operator-pending mode', function()
feed('d<F4>')
expect([[
lines
of test text]])
- eq({'some short '}, funcs.getreg('"',1,1))
+ eq({ 'some short ' }, fn.getreg('"', 1, 1))
feed('.')
expect([[
test text]])
- eq({'lines', 'of '}, funcs.getreg('"',1,1))
+ eq({ 'lines', 'of ' }, fn.getreg('"', 1, 1))
feed('uu')
expect([[
some short lines
@@ -568,8 +490,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of test text |
- {1:~ }|
- {1:~ }|
+ {1:~ }|*2
{7: }|
{2:Error detected while processing :} |
{2:E605: Exception not caught: very error} |
@@ -584,7 +505,7 @@ describe('mappings with <Cmd>', function()
feed('"bd<F7>')
expect([[
soest text]])
- eq(funcs.getreg('b',1,1), {'me short lines', 'of t'})
+ eq(fn.getreg('b', 1, 1), { 'me short lines', 'of t' })
-- startinsert aborts operator
feed('d<F8>')
@@ -594,17 +515,12 @@ describe('mappings with <Cmd>', function()
end)
it('works in insert mode', function()
-
-- works the same as <c-o>w<c-o>w
feed('iindeed <F4>little ')
screen:expect([[
indeed some short little ^lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT --} |
]])
@@ -612,26 +528,20 @@ describe('mappings with <Cmd>', function()
screen:expect([[
indeed some short little lines |
of test text |
- {1:~ }|
- {1:~ }|
+ {1:~ }|*2
{7: }|
{2:Error detected while processing :} |
{2:E605: Exception not caught: very error} |
{3:Press ENTER or type command to continue}^ |
]])
-
feed('<cr>')
eq('E605: Exception not caught: very error', eval('v:errmsg'))
-- still in insert
screen:expect([[
indeed some short little ^lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT --} |
]])
eq('i', eval('mode(1)'))
@@ -643,11 +553,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
in{5:deed some short little lines} |
{5:of stuff }^test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT VISUAL --} |
]])
expect([[
@@ -655,17 +561,13 @@ describe('mappings with <Cmd>', function()
of stuff test text]])
feed('<F5>')
- eq(funcs.getreg('a',1,1), {'deed some short little lines', 'of stuff t'})
+ eq(fn.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' })
-- still in insert
screen:expect([[
in^deed some short little lines |
of stuff test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT --} |
]])
eq('i', eval('mode(1)'))
@@ -675,11 +577,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
in bar ^deed some short little lines |
of stuff test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT --} |
]])
eq(17, eval('g:y'))
@@ -700,9 +598,7 @@ describe('mappings with <Cmd>', function()
some^ |
{8:some } |
{9:short }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*3
{4:-- Keyword Local completion (^N^P) }{3:match 1 of 2} |
]])
@@ -717,9 +613,7 @@ describe('mappings with <Cmd>', function()
some^ |
{9:some } |
{9:short }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*3
{4:-- Keyword Local completion (^N^P) }{10:Back at original} |
]])
end)
@@ -734,11 +628,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
^some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{2:E492: Not an editor command: text} |
]])
@@ -773,11 +663,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
^some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
|
]])
eq('n', eval('mode(1)'))
@@ -786,11 +672,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
:let g:x = 3^ |
]])
feed('+2<cr>')
@@ -798,11 +680,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short ^lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
:let g:x = 3+2 |
]])
eq(5, eval('g:x'))
@@ -811,11 +689,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
:let g:y = 7^ |
]])
eq('c', eval('mode(1)'))
@@ -824,16 +698,11 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short ^lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
{4:-- INSERT --} |
]])
eq('i', eval('mode(1)'))
eq(9, eval('g:y'))
-
end)
it("doesn't crash when invoking cmdline mode recursively #8859", function()
@@ -842,11 +711,7 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
:bar^ |
]])
@@ -854,27 +719,25 @@ describe('mappings with <Cmd>', function()
screen:expect([[
some short lines |
of test text |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
+ {1:~ }|*5
:barx^ |
]])
end)
- it("works with <SID> mappings", function()
+ it('works with <SID> mappings', function()
command('new!')
- write_file(tmpfile, [[
+ write_file(
+ tmpfile,
+ [[
map <f2> <Cmd>call <SID>do_it()<Cr>
function! s:do_it()
let g:x = 10
endfunction
- ]])
- command('source '..tmpfile)
+ ]]
+ )
+ command('source ' .. tmpfile)
feed('<f2>')
eq('', eval('v:errmsg'))
eq(10, eval('g:x'))
end)
end)
-