aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-01 22:19:30 +0800
committerGitHub <noreply@github.com>2022-08-01 22:19:30 +0800
commit8d1c55e4224fc990d18409905aeb51d54d9d78cb (patch)
treebb4379bde6144ab7a0e2436149730a276c3089d0 /test
parentdb6e93c48df551e2906c9e0f4472f9e54cea3dd9 (diff)
parentd954e8da62faccd468896baf2fe06107196cf952 (diff)
downloadrneovim-8d1c55e4224fc990d18409905aeb51d54d9d78cb.tar.gz
rneovim-8d1c55e4224fc990d18409905aeb51d54d9d78cb.tar.bz2
rneovim-8d1c55e4224fc990d18409905aeb51d54d9d78cb.zip
Merge pull request #19602 from zeertzjq/vim-8.2.0807
vim-patch:8.2.{0807,0809,0812,0815,0832,1773,2804,4831,5106},9.0.0127: first part of mapset()
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/keymap_spec.lua32
-rw-r--r--test/functional/legacy/075_maparg_spec.lua59
-rw-r--r--test/functional/vimscript/map_functions_spec.lua34
3 files changed, 61 insertions, 64 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index 23c0a14d39..712889828e 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -25,6 +25,7 @@ describe('nvim_get_keymap', function()
local foo_bar_string = 'nnoremap foo bar'
local foo_bar_map_table = {
lhs='foo',
+ lhsraw='foo',
script=0,
silent=0,
rhs='bar',
@@ -56,6 +57,7 @@ describe('nvim_get_keymap', function()
command('nnoremap foo_longer bar_longer')
local foolong_bar_map_table = shallowcopy(foo_bar_map_table)
foolong_bar_map_table['lhs'] = 'foo_longer'
+ foolong_bar_map_table['lhsraw'] = 'foo_longer'
foolong_bar_map_table['rhs'] = 'bar_longer'
eq({foolong_bar_map_table, foo_bar_map_table},
@@ -87,6 +89,7 @@ describe('nvim_get_keymap', function()
command('nnoremap foo_longer bar_longer')
local foolong_bar_map_table = shallowcopy(foo_bar_map_table)
foolong_bar_map_table['lhs'] = 'foo_longer'
+ foolong_bar_map_table['lhsraw'] = 'foo_longer'
foolong_bar_map_table['rhs'] = 'bar_longer'
local buffer_table = shallowcopy(foo_bar_map_table)
@@ -283,6 +286,16 @@ describe('nvim_get_keymap', function()
command('onoremap \\<C-a><C-a><LT>C-a>\\ \\<C-b><C-b><LT>C-b>\\')
command('onoremap <special> \\<C-c><C-c><LT>C-c>\\ \\<C-d><C-d><LT>C-d>\\')
+ -- wrapper around get_keymap() that drops "lhsraw" and "lhsrawalt" which are hard to check
+ local function get_keymap_noraw(...)
+ local ret = meths.get_keymap(...)
+ for _, item in ipairs(ret) do
+ item.lhsraw = nil
+ item.lhsrawalt = nil
+ end
+ return ret
+ end
+
for _, cmd in ipairs({
'set cpo-=B',
'set cpo+=B',
@@ -290,22 +303,23 @@ describe('nvim_get_keymap', function()
command(cmd)
eq({cpomap('\\<C-C><C-C><lt>C-c>\\', '\\<C-D><C-D><lt>C-d>\\', 'n'),
cpomap('\\<C-A><C-A><lt>C-a>\\', '\\<C-B><C-B><lt>C-b>\\', 'n')},
- meths.get_keymap('n'))
+ get_keymap_noraw('n'))
eq({cpomap('\\<C-C><C-C><lt>C-c>\\', '\\<C-D><C-D><lt>C-d>\\', 'x'),
cpomap('\\<C-A><C-A><lt>C-a>\\', '\\<C-B><C-B><lt>C-b>\\', 'x')},
- meths.get_keymap('x'))
+ get_keymap_noraw('x'))
eq({cpomap('<lt>C-c><C-C><lt>C-c> ', '<lt>C-d><C-D><lt>C-d>', 's'),
cpomap('<lt>C-a><C-A><lt>C-a> ', '<lt>C-b><C-B><lt>C-b>', 's')},
- meths.get_keymap('s'))
+ get_keymap_noraw('s'))
eq({cpomap('<lt>C-c><C-C><lt>C-c> ', '<lt>C-d><C-D><lt>C-d>', 'o'),
cpomap('<lt>C-a><C-A><lt>C-a> ', '<lt>C-b><C-B><lt>C-b>', 'o')},
- meths.get_keymap('o'))
+ get_keymap_noraw('o'))
end
end)
it('always uses space for space and bar for bar', function()
local space_table = {
lhs='| |',
+ lhsraw='| |',
rhs='| |',
mode='n',
script=0,
@@ -340,6 +354,7 @@ describe('nvim_get_keymap', function()
mapargs[1].callback = nil
eq({
lhs='asdf',
+ lhsraw='asdf',
script=0,
silent=0,
expr=0,
@@ -356,6 +371,7 @@ describe('nvim_get_keymap', function()
meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"})
eq({
lhs='lhs',
+ lhsraw='lhs',
rhs='rhs',
script=0,
silent=0,
@@ -413,7 +429,11 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Gets a maparg() dict from Nvim, if one exists.
local function get_mapargs(mode, lhs)
- return funcs.maparg(lhs, normalize_mapmode(mode), false, true)
+ local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), false, true)
+ -- drop "lhsraw" and "lhsrawalt" which are hard to check
+ mapargs.lhsraw = nil
+ mapargs.lhsrawalt = nil
+ return mapargs
end
it('error on empty LHS', function()
@@ -817,6 +837,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
local mapargs = funcs.maparg('asdf', 'n', false, true)
assert(type(mapargs.callback) == 'number', 'callback is not luaref number')
mapargs.callback = nil
+ mapargs.lhsraw = nil
+ mapargs.lhsrawalt = nil
eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs)
end)
diff --git a/test/functional/legacy/075_maparg_spec.lua b/test/functional/legacy/075_maparg_spec.lua
deleted file mode 100644
index ad6c190104..0000000000
--- a/test/functional/legacy/075_maparg_spec.lua
+++ /dev/null
@@ -1,59 +0,0 @@
--- Tests for maparg().
--- Also test utf8 map with a 0x80 byte.
-
-local helpers = require('test.functional.helpers')(after_each)
-local clear, feed = helpers.clear, helpers.feed
-local command, expect = helpers.command, helpers.expect
-local poke_eventloop = helpers.poke_eventloop
-
-describe('maparg()', function()
- setup(clear)
-
- it('is working', function()
- command('set cpo-=<')
-
- -- Test maparg() with a string result
- command('map foo<C-V> is<F4>foo')
- command('vnoremap <script> <buffer> <expr> <silent> bar isbar')
- command([[call append('$', maparg('foo<C-V>'))]])
- command([[call append('$', string(maparg('foo<C-V>', '', 0, 1)))]])
- command([[call append('$', string(maparg('bar', '', 0, 1)))]])
- command('map <buffer> <nowait> foo bar')
- command([[call append('$', string(maparg('foo', '', 0, 1)))]])
- command('map abc x<char-114>x')
- command([[call append('$', maparg('abc'))]])
- command('map abc y<S-char-114>y')
- command([[call append('$', maparg('abc'))]])
- feed('Go<esc>:<cr>')
- poke_eventloop()
-
- -- Outside of the range, minimum
- command('inoremap <Char-0x1040> a')
- command([[execute "normal a\u1040\<Esc>"]])
-
- -- Inside of the range, minimum
- command('inoremap <Char-0x103f> b')
- command([[execute "normal a\u103f\<Esc>"]])
-
- -- Inside of the range, maximum
- command('inoremap <Char-0xf03f> c')
- command([[execute "normal a\uf03f\<Esc>"]])
-
- -- Outside of the range, maximum
- command('inoremap <Char-0xf040> d')
- command([[execute "normal a\uf040\<Esc>"]])
-
- -- Remove empty line
- command('1d')
-
- -- Assert buffer contents.
- expect([[
- is<F4>foo
- {'lnum': 0, 'script': 0, 'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': 0, 'rhs': 'is<F4>foo', 'buffer': 0}
- {'lnum': 0, 'script': 1, 'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', 'nowait': 0, 'expr': 1, 'sid': 0, 'rhs': 'isbar', 'buffer': 1}
- {'lnum': 0, 'script': 0, 'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', 'nowait': 1, 'expr': 0, 'sid': 0, 'rhs': 'bar', 'buffer': 1}
- xrx
- yRy
- abcd]])
- end)
-end)
diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua
index 275c72d212..aa64006de0 100644
--- a/test/functional/vimscript/map_functions_spec.lua
+++ b/test/functional/vimscript/map_functions_spec.lua
@@ -3,7 +3,10 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
+local expect = helpers.expect
+local feed = helpers.feed
local funcs = helpers.funcs
+local meths = helpers.meths
local nvim = helpers.nvim
local source = helpers.source
local command = helpers.command
@@ -13,6 +16,7 @@ describe('maparg()', function()
local foo_bar_map_table = {
lhs='foo',
+ lhsraw='foo',
script=0,
silent=0,
rhs='bar',
@@ -141,6 +145,7 @@ describe('maparg()', function()
local function acmap(lhs, rhs)
return {
lhs = ac(lhs),
+ lhsraw = ac(lhs),
rhs = ac(rhs),
buffer = 0,
@@ -161,3 +166,32 @@ describe('maparg()', function()
eq(acmap('e`', 'f`'), funcs.maparg(ac('e`'), 'n', 0, 1))
end)
end)
+
+describe('mapset()', function()
+ before_each(clear)
+
+ it('can restore mapping description from the dict returned by maparg()', function()
+ meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'})
+ eq('\nn lhs rhs\n map description',
+ helpers.exec_capture("nmap lhs"))
+ local mapargs = funcs.maparg('lhs', 'n', false, true)
+ meths.del_keymap('n', 'lhs')
+ eq('\nNo mapping found', helpers.exec_capture("nmap lhs"))
+ funcs.mapset('n', false, mapargs)
+ eq('\nn lhs rhs\n map description',
+ helpers.exec_capture("nmap lhs"))
+ end)
+
+ it('can restore "replace_keycodes" from the dict returned by maparg()', function()
+ meths.set_keymap('i', 'foo', [['<l' .. 't>']], {expr = true, replace_keycodes = true})
+ feed('Afoo')
+ expect('<')
+ local mapargs = funcs.maparg('foo', 'i', false, true)
+ meths.set_keymap('i', 'foo', [['<l' .. 't>']], {expr = true})
+ feed('foo')
+ expect('<<lt>')
+ funcs.mapset('i', false, mapargs)
+ feed('foo')
+ expect('<<lt><')
+ end)
+end)