aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/keymap_spec.lua2
-rw-r--r--test/functional/editor/langmap_spec.lua8
-rw-r--r--test/functional/editor/mode_cmdline_spec.lua105
-rw-r--r--test/functional/editor/mode_insert_spec.lua5
-rw-r--r--test/functional/legacy/eval_spec.lua2
-rw-r--r--test/functional/options/pastetoggle_spec.lua86
-rw-r--r--test/functional/ui/input_spec.lua127
-rw-r--r--test/unit/keymap_spec.lua23
8 files changed, 259 insertions, 99 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index c0edcde476..a11b5306f4 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -582,7 +582,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can set mappings containing literal keycodes', function()
meths.set_keymap('n', '\n\r\n', 'rhs', {})
local expected = generate_mapargs('n', '<NL><CR><NL>', 'rhs')
- eq(expected, get_mapargs('n', '<C-j><CR><C-j>'))
+ eq(expected, get_mapargs('n', '<NL><CR><NL>'))
end)
it('can set mappings whose RHS is a <Nop>', function()
diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua
index af19f97a68..b1070ecddc 100644
--- a/test/functional/editor/langmap_spec.lua
+++ b/test/functional/editor/langmap_spec.lua
@@ -213,11 +213,11 @@ describe("'langmap'", function()
iii]])
end)
- local function testrecording(command_string, expect_string, setup_function)
+ local function testrecording(command_string, expect_string, setup_function, expect_macro)
if setup_function then setup_function() end
feed('qa' .. command_string .. 'q')
expect(expect_string)
- eq(helpers.funcs.nvim_replace_termcodes(command_string, true, true, true),
+ eq(expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true),
eval('@a'))
if setup_function then setup_function() end
-- n.b. may need nvim_replace_termcodes() here.
@@ -273,8 +273,8 @@ describe("'langmap'", function()
it('treats control modified keys as characters', function()
command('nnoremap <C-w> iw<esc>')
command('nnoremap <C-i> ii<esc>')
- testrecording('<C-w>', 'whello', local_setup)
- testrecording('<C-i>', 'ihello', local_setup)
+ testrecording('<C-w>', 'whello', local_setup, eval([["\<*C-w>"]]))
+ testrecording('<C-i>', 'ihello', local_setup, eval([["\<*C-i>"]]))
end)
end)
diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua
index 0f7d821bb5..50cc5e17ee 100644
--- a/test/functional/editor/mode_cmdline_spec.lua
+++ b/test/functional/editor/mode_cmdline_spec.lua
@@ -3,67 +3,74 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, insert, funcs, eq, feed =
helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed
+local eval = helpers.eval
local meths = helpers.meths
-describe('cmdline CTRL-R', function()
+describe('cmdline', function()
before_each(clear)
- it('pasting non-special register inserts <CR> *between* lines', function()
- insert([[
- line1abc
- line2somemoretext
- ]])
- -- Yank 2 lines linewise, then paste to cmdline.
- feed([[<C-\><C-N>gg0yj:<C-R>0]])
- -- <CR> inserted between lines, NOT after the final line.
- eq('line1abc\rline2somemoretext', funcs.getcmdline())
+ describe('Ctrl-R', function()
+ it('pasting non-special register inserts <CR> *between* lines', function()
+ insert([[
+ line1abc
+ line2somemoretext
+ ]])
+ -- Yank 2 lines linewise, then paste to cmdline.
+ feed([[<C-\><C-N>gg0yj:<C-R>0]])
+ -- <CR> inserted between lines, NOT after the final line.
+ eq('line1abc\rline2somemoretext', funcs.getcmdline())
- -- Yank 2 lines charwise, then paste to cmdline.
- feed([[<C-\><C-N>gg05lyvj:<C-R>0]])
- -- <CR> inserted between lines, NOT after the final line.
- eq('abc\rline2', funcs.getcmdline())
+ -- Yank 2 lines charwise, then paste to cmdline.
+ feed([[<C-\><C-N>gg05lyvj:<C-R>0]])
+ -- <CR> inserted between lines, NOT after the final line.
+ eq('abc\rline2', funcs.getcmdline())
- -- Yank 1 line linewise, then paste to cmdline.
- feed([[<C-\><C-N>ggyy:<C-R>0]])
- -- No <CR> inserted.
- eq('line1abc', funcs.getcmdline())
- end)
+ -- Yank 1 line linewise, then paste to cmdline.
+ feed([[<C-\><C-N>ggyy:<C-R>0]])
+ -- No <CR> inserted.
+ eq('line1abc', funcs.getcmdline())
+ end)
- it('pasting special register inserts <CR>, <NL>', function()
- feed([[:<C-R>="foo\nbar\rbaz"<CR>]])
- eq('foo\nbar\rbaz', funcs.getcmdline())
+ it('pasting special register inserts <CR>, <NL>', function()
+ feed([[:<C-R>="foo\nbar\rbaz"<CR>]])
+ eq('foo\nbar\rbaz', funcs.getcmdline())
+ end)
end)
-end)
-describe('cmdline history', function()
- before_each(clear)
+ it('Ctrl-Shift-V supports entering unsimplified key notations', function()
+ feed(':"<C-S-V><C-J><C-S-V><C-@><C-S-V><C-[><C-S-V><C-S-M><C-S-V><M-C-I><C-S-V><C-D-J><CR>')
- it('correctly clears start of the history', function()
- -- Regression test: check absence of the memory leak when clearing start of
- -- the history using ex_getln.c/clr_history().
- eq(1, funcs.histadd(':', 'foo'))
- eq(1, funcs.histdel(':'))
- eq('', funcs.histget(':', -1))
+ eq('"<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>', eval('@:'))
end)
- it('correctly clears end of the history', function()
- -- Regression test: check absence of the memory leak when clearing end of
- -- the history using ex_getln.c/clr_history().
- meths.set_option('history', 1)
- eq(1, funcs.histadd(':', 'foo'))
- eq(1, funcs.histdel(':'))
- eq('', funcs.histget(':', -1))
- end)
+ describe('history', function()
+ it('correctly clears start of the history', function()
+ -- Regression test: check absence of the memory leak when clearing start of
+ -- the history using ex_getln.c/clr_history().
+ eq(1, funcs.histadd(':', 'foo'))
+ eq(1, funcs.histdel(':'))
+ eq('', funcs.histget(':', -1))
+ end)
+
+ it('correctly clears end of the history', function()
+ -- Regression test: check absence of the memory leak when clearing end of
+ -- the history using ex_getln.c/clr_history().
+ meths.set_option('history', 1)
+ eq(1, funcs.histadd(':', 'foo'))
+ eq(1, funcs.histdel(':'))
+ eq('', funcs.histget(':', -1))
+ end)
- it('correctly removes item from history', function()
- -- Regression test: check that ex_getln.c/del_history_idx() correctly clears
- -- history index after removing history entry. If it does not then deleting
- -- history will result in a double free.
- eq(1, funcs.histadd(':', 'foo'))
- eq(1, funcs.histadd(':', 'bar'))
- eq(1, funcs.histadd(':', 'baz'))
- eq(1, funcs.histdel(':', -2))
- eq(1, funcs.histdel(':'))
- eq('', funcs.histget(':', -1))
+ it('correctly removes item from history', function()
+ -- Regression test: check that ex_getln.c/del_history_idx() correctly clears
+ -- history index after removing history entry. If it does not then deleting
+ -- history will result in a double free.
+ eq(1, funcs.histadd(':', 'foo'))
+ eq(1, funcs.histadd(':', 'bar'))
+ eq(1, funcs.histadd(':', 'baz'))
+ eq(1, funcs.histdel(':', -2))
+ eq(1, funcs.histdel(':'))
+ eq('', funcs.histget(':', -1))
+ end)
end)
end)
diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua
index c38acbe96a..684dee69db 100644
--- a/test/functional/editor/mode_insert_spec.lua
+++ b/test/functional/editor/mode_insert_spec.lua
@@ -131,6 +131,11 @@ describe('insert-mode', function()
end)
end)
+ it('Ctrl-Shift-V supports entering unsimplified key notations', function()
+ feed('i<C-S-V><C-J><C-S-V><C-@><C-S-V><C-[><C-S-V><C-S-M><C-S-V><M-C-I><C-S-V><C-D-J><Esc>')
+ expect('<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>')
+ end)
+
describe([[With 'insertmode', Insert mode is not re-entered immediately after <C-L>]], function()
before_each(function()
command('set insertmode')
diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua
index d3c0b4b938..05d853622e 100644
--- a/test/functional/legacy/eval_spec.lua
+++ b/test/functional/legacy/eval_spec.lua
@@ -46,7 +46,7 @@ describe('eval', function()
command('AR "')
command([[let @" = "abc\n"]])
source('AR "')
- command([[let @" = "abc\r"]])
+ command([[let @" = "abc\<C-m>"]])
command('AR "')
command([[let @= = '"abc"']])
command('AR =')
diff --git a/test/functional/options/pastetoggle_spec.lua b/test/functional/options/pastetoggle_spec.lua
index a1f86f73ff..40c14fa187 100644
--- a/test/functional/options/pastetoggle_spec.lua
+++ b/test/functional/options/pastetoggle_spec.lua
@@ -4,16 +4,14 @@ local clear = helpers.clear
local feed = helpers.feed
local command = helpers.command
local eq = helpers.eq
+local expect = helpers.expect
local eval = helpers.eval
+local insert = helpers.insert
+local meths = helpers.meths
local sleep = helpers.sleep
-local expect = helpers.expect
describe("'pastetoggle' option", function()
- before_each(function()
- clear()
- command('set nopaste')
- end)
-
+ before_each(clear)
it("toggles 'paste'", function()
command('set pastetoggle=a')
eq(0, eval('&paste'))
@@ -22,19 +20,71 @@ describe("'pastetoggle' option", function()
feed('j')
eq(1, eval('&paste'))
end)
+ describe("multiple key 'pastetoggle'", function()
+ before_each(function()
+ eq(0, eval('&paste'))
+ command('set timeoutlen=1 ttimeoutlen=10000')
+ end)
+ it('is waited for when chars are typed', function()
+ local pastetoggle = 'lllll'
+ command('set pastetoggle=' .. pastetoggle)
+ feed(pastetoggle:sub(0, 2))
+ -- sleep() for long enough that vgetorpeek() is gotten into, but short
+ -- enough that ttimeoutlen is not reached.
+ sleep(200)
+ feed(pastetoggle:sub(3, -1))
+ -- Need another key so that the vgetorpeek() function returns.
+ feed('j')
+ eq(1, eval('&paste'))
+ end)
+ it('is not waited for when there are no typed chars after mapped chars', function()
+ command('set pastetoggle=abc')
+ command('imap d a')
+ meths.feedkeys('id', 't', true)
+ -- sleep() for long enough that vgetorpeek() is gotten into, but short
+ -- enough that ttimeoutlen is not reached.
+ sleep(200)
+ feed('bc')
+ -- Need another key so that the vgetorpeek() function returns.
+ feed('j')
+ -- 'ttimeoutlen' should NOT apply
+ eq(0, eval('&paste'))
+ end)
- it('does not wait for timeout', function()
- command('set pastetoggle=abc')
- command('set ttimeoutlen=9999999')
- eq(0, eval('&paste'))
- -- n.b. need <esc> to return from vgetorpeek()
- feed('abc<esc>')
- eq(1, eval('&paste'))
- feed('ab')
- sleep(10)
- feed('c<esc>')
- expect('bc')
- eq(1, eval('&paste'))
+ it('is waited for when there are typed chars after mapped chars', function()
+ command('set pastetoggle=abc')
+ command('imap d a')
+ meths.feedkeys('idb', 't', true)
+ -- sleep() for long enough that vgetorpeek() is gotten into, but short
+ -- enough that ttimeoutlen is not reached.
+ sleep(200)
+ feed('c')
+ -- Need another key so that the vgetorpeek() function returns.
+ feed('j')
+ -- 'ttimeoutlen' should apply
+ eq(1, eval('&paste'))
+ end)
+
+ it('is waited for when there are typed chars after noremapped chars', function()
+ command('set pastetoggle=abc')
+ command('inoremap d a')
+ meths.feedkeys('idb', 't', true)
+ -- sleep() for long enough that vgetorpeek() is gotten into, but short
+ -- enough that ttimeoutlen is not reached.
+ sleep(200)
+ feed('c')
+ -- Need another key so that the vgetorpeek() function returns.
+ feed('j')
+ -- 'ttimeoutlen' should apply
+ eq(1, eval('&paste'))
+ end)
+ end)
+ it('does not interfere with character-find', function()
+ insert('foo,bar')
+ feed('0')
+ command('set pastetoggle=,sp')
+ feed('dt,')
+ expect(',bar')
end)
end)
diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua
index 8925dda730..0f4e97088c 100644
--- a/test/functional/ui/input_spec.lua
+++ b/test/functional/ui/input_spec.lua
@@ -8,6 +8,7 @@ local meths = helpers.meths
local exec_lua = helpers.exec_lua
local write_file = helpers.write_file
local funcs = helpers.funcs
+local eval = helpers.eval
local Screen = require('test.functional.ui.screen')
before_each(clear)
@@ -172,11 +173,20 @@ describe('input pairs', function()
eq('\t\t', curbuf_contents())
end)
- it('can be mapped', function()
- command('inoremap <tab> TAB!')
- command('inoremap <c-i> CTRL-I!')
- feed('i<tab><c-i><esc>')
- eq('TAB!CTRL-I!', curbuf_contents())
+ describe('can be mapped separately', function()
+ it('if <tab> is mapped after <c-i>', function()
+ command('inoremap <c-i> CTRL-I!')
+ command('inoremap <tab> TAB!')
+ feed('i<tab><c-i><esc>')
+ eq('TAB!CTRL-I!', curbuf_contents())
+ end)
+
+ it('if <tab> is mapped before <c-i>', function()
+ command('inoremap <tab> TAB!')
+ command('inoremap <c-i> CTRL-I!')
+ feed('i<tab><c-i><esc>')
+ eq('TAB!CTRL-I!', curbuf_contents())
+ end)
end)
end)
@@ -186,11 +196,20 @@ describe('input pairs', function()
eq('unos\ndos\ntres', curbuf_contents())
end)
- it('can be mapped', function()
- command('inoremap <c-m> SNIPPET!')
- command('inoremap <cr> , and then<cr>')
- feed('iunos<c-m>dos<cr>tres<esc>')
- eq('unosSNIPPET!dos, and then\ntres', curbuf_contents())
+ describe('can be mapped separately', function()
+ it('if <cr> is mapped after <c-m>', function()
+ command('inoremap <c-m> SNIPPET!')
+ command('inoremap <cr> , and then<cr>')
+ feed('iunos<c-m>dos<cr>tres<esc>')
+ eq('unosSNIPPET!dos, and then\ntres', curbuf_contents())
+ end)
+
+ it('if <cr> is mapped before <c-m>', function()
+ command('inoremap <cr> , and then<cr>')
+ command('inoremap <c-m> SNIPPET!')
+ feed('iunos<c-m>dos<cr>tres<esc>')
+ eq('unosSNIPPET!dos, and then\ntres', curbuf_contents())
+ end)
end)
end)
@@ -200,11 +219,20 @@ describe('input pairs', function()
eq('doubledoublesingle', curbuf_contents())
end)
- it('can be mapped', function()
- command('inoremap <c-[> HALLOJ!')
- command('inoremap <esc> ,<esc>')
- feed('2adubbel<c-[>upp<esc>')
- eq('dubbelHALLOJ!upp,dubbelHALLOJ!upp,', curbuf_contents())
+ describe('can be mapped separately', function()
+ it('if <esc> is mapped after <c-[>', function()
+ command('inoremap <c-[> HALLOJ!')
+ command('inoremap <esc> ,<esc>')
+ feed('2adubbel<c-[>upp<esc>')
+ eq('dubbelHALLOJ!upp,dubbelHALLOJ!upp,', curbuf_contents())
+ end)
+
+ it('if <esc> is mapped before <c-[>', function()
+ command('inoremap <esc> ,<esc>')
+ command('inoremap <c-[> HALLOJ!')
+ feed('2adubbel<c-[>upp<esc>')
+ eq('dubbelHALLOJ!upp,dubbelHALLOJ!upp,', curbuf_contents())
+ end)
end)
end)
end)
@@ -216,6 +244,75 @@ it('Ctrl-6 is Ctrl-^ vim-patch:8.1.2333', function()
eq('aaa', funcs.bufname())
end)
+it('c_CTRL-R_CTRL-R, i_CTRL-R_CTRL-R, i_CTRL-G_CTRL-K work properly vim-patch:8.1.2346', function()
+ command('set timeoutlen=10')
+
+ command([[let @a = 'aaa']])
+ feed([[:let x = '<C-R><C-R>a'<CR>]])
+ eq([[let x = 'aaa']], eval('@:'))
+
+ feed('a<C-R><C-R>a<Esc>')
+ expect('aaa')
+ command('bwipe!')
+
+ feed('axx<CR>yy<C-G><C-K>a<Esc>')
+ expect([[
+ axx
+ yy]])
+end)
+
+it('typing a simplifiable key at hit-enter prompt triggers mapping vim-patch:8.2.0839', function()
+ local screen = Screen.new(60,8)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [2] = {bold = true, reverse = true}, -- MsgSeparator
+ [3] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
+ })
+ screen:attach()
+ command([[nnoremap <C-6> <Cmd>echo 'hit ctrl-6'<CR>]])
+ feed_command('ls')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2: }|
+ :ls |
+ 1 %a "[No Name]" line 1 |
+ {3:Press ENTER or type command to continue}^ |
+ ]])
+ feed('<C-6>')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ hit ctrl-6 |
+ ]])
+end)
+
+it('mixing simplified and unsimplified keys can trigger mapping vim-patch:8.2.0916', function()
+ command('set timeoutlen=10')
+ command([[imap ' <C-W>]])
+ command('imap <C-W><C-A> c-a')
+ feed([[a'<C-A>]])
+ expect('c-a')
+end)
+
+it('unsimplified mapping works when there was a partial match vim-patch:8.2.4504', function()
+ command('set timeoutlen=10')
+ command('nnoremap <C-J> a')
+ command('nnoremap <NL> x')
+ command('nnoremap <C-J>x <Nop>')
+ funcs.setline(1, 'x')
+ -- CTRL-J b should have trigger the <C-J> mapping and then insert "b"
+ feed('<C-J>b<Esc>')
+ expect('xb')
+end)
+
describe('input non-printable chars', function()
after_each(function()
os.remove('Xtest-overwrite')
diff --git a/test/unit/keymap_spec.lua b/test/unit/keymap_spec.lua
index 595a19eb17..1f1f32bb9e 100644
--- a/test/unit/keymap_spec.lua
+++ b/test/unit/keymap_spec.lua
@@ -5,7 +5,8 @@ local ffi = helpers.ffi
local eq = helpers.eq
local neq = helpers.neq
-local keymap = helpers.cimport("./src/nvim/keymap.h")
+local keymap = helpers.cimport('./src/nvim/keymap.h')
+local NULL = helpers.NULL
describe('keymap.c', function()
@@ -15,12 +16,12 @@ describe('keymap.c', function()
itp('no keycode', function()
srcp[0] = 'abc'
- eq(0, keymap.find_special_key(srcp, 3, modp, false, false, false))
+ eq(0, keymap.find_special_key(srcp, 3, modp, 0, NULL))
end)
itp('keycode with multiple modifiers', function()
srcp[0] = '<C-M-S-A>'
- neq(0, keymap.find_special_key(srcp, 9, modp, false, false, false))
+ neq(0, keymap.find_special_key(srcp, 9, modp, 0, NULL))
neq(0, modp[0])
end)
@@ -28,22 +29,22 @@ describe('keymap.c', function()
-- Compare other capitalizations to this.
srcp[0] = '<C-A>'
local all_caps_key =
- keymap.find_special_key(srcp, 5, modp, false, false, false)
+ keymap.find_special_key(srcp, 5, modp, 0, NULL)
local all_caps_mod = modp[0]
srcp[0] = '<C-a>'
eq(all_caps_key,
- keymap.find_special_key(srcp, 5, modp, false, false, false))
+ keymap.find_special_key(srcp, 5, modp, 0, NULL))
eq(all_caps_mod, modp[0])
srcp[0] = '<c-A>'
eq(all_caps_key,
- keymap.find_special_key(srcp, 5, modp, false, false, false))
+ keymap.find_special_key(srcp, 5, modp, 0, NULL))
eq(all_caps_mod, modp[0])
srcp[0] = '<c-a>'
eq(all_caps_key,
- keymap.find_special_key(srcp, 5, modp, false, false, false))
+ keymap.find_special_key(srcp, 5, modp, 0, NULL))
eq(all_caps_mod, modp[0])
end)
@@ -51,20 +52,20 @@ describe('keymap.c', function()
-- Unescaped with in_string=false
srcp[0] = '<C-">'
eq(string.byte('"'),
- keymap.find_special_key(srcp, 5, modp, false, false, false))
+ keymap.find_special_key(srcp, 5, modp, 0, NULL))
-- Unescaped with in_string=true
- eq(0, keymap.find_special_key(srcp, 5, modp, false, false, true))
+ eq(0, keymap.find_special_key(srcp, 5, modp, keymap.FSK_IN_STRING, NULL))
-- Escaped with in_string=false
srcp[0] = '<C-\\">'
-- Should fail because the key is invalid
-- (more than 1 non-modifier character).
- eq(0, keymap.find_special_key(srcp, 6, modp, false, false, false))
+ eq(0, keymap.find_special_key(srcp, 6, modp, 0, NULL))
-- Escaped with in_string=true
eq(string.byte('"'),
- keymap.find_special_key(srcp, 6, modp, false, false, true))
+ keymap.find_special_key(srcp, 6, modp, keymap.FSK_IN_STRING, NULL))
end)
end)