aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/highlight_spec.lua11
-rw-r--r--test/functional/api/keymap_spec.lua80
-rw-r--r--test/functional/api/vim_spec.lua6
3 files changed, 82 insertions, 15 deletions
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index 933103046c..c4197f0b3e 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -34,6 +34,7 @@ describe('API: highlight',function()
underdotted = true,
underdashed = true,
strikethrough = true,
+ nocombine = true,
}
before_each(function()
@@ -55,7 +56,7 @@ describe('API: highlight',function()
eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*'))
-- Test all highlight properties.
- command('hi NewHighlight gui=underline,bold,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough')
+ command('hi NewHighlight gui=underline,bold,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough,nocombine')
eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true))
-- Test nil argument.
@@ -136,10 +137,10 @@ describe('API: highlight',function()
-- Test cterm & Normal values. #18024 (tail) & #18980
-- Ensure Normal, and groups that match Normal return their fg & bg cterm values
meths.set_hl(0, 'Normal', {ctermfg = 17, ctermbg = 213})
- meths.set_hl(0, 'NotNormal', {ctermfg = 17, ctermbg = 213})
+ meths.set_hl(0, 'NotNormal', {ctermfg = 17, ctermbg = 213, nocombine = true})
-- Note colors are "cterm" values, not rgb-as-ints
eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'Normal', false))
- eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'NotNormal', false))
+ eq({foreground = 17, background = 213, nocombine = true}, nvim("get_hl_by_name", 'NotNormal', false))
end)
it('nvim_get_hl_id_by_name', function()
@@ -214,6 +215,7 @@ describe("API: set highlight", function()
reverse = true,
undercurl = true,
strikethrough = true,
+ nocombine = true,
}
}
local highlight3_result_gui = {
@@ -236,6 +238,7 @@ describe("API: set highlight", function()
reverse = true,
undercurl = true,
strikethrough = true,
+ nocombine = true,
}
local function get_ns()
@@ -290,7 +293,7 @@ describe("API: set highlight", function()
exec_capture('highlight Test_hl'))
meths.set_hl(0, 'Test_hl2', highlight3_config)
- eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa',
+ eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough,nocombine ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa',
exec_capture('highlight Test_hl2'))
-- Colors are stored with the name they are defined, but
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index 6bc6651e04..eb2a467a8b 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()
@@ -503,6 +523,11 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true}))
end)
+ it('error when "replace_keycodes" is used without "expr"', function()
+ eq('"replace_keycodes" requires "expr"',
+ pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {replace_keycodes = true}))
+ end)
+
local optnames = {'nowait', 'silent', 'script', 'expr', 'unique'}
for _, opt in ipairs(optnames) do
-- note: need '%' to escape hyphens, which have special meaning in lua
@@ -817,17 +842,39 @@ 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)
- it('can make lua expr mappings', function()
+ it('can make lua expr mappings replacing keycodes', function()
exec_lua [[
- vim.api.nvim_set_keymap ('n', 'aa', '', {callback = function() return vim.api.nvim_replace_termcodes(':lua SomeValue = 99<cr>', true, false, true) end, expr = true })
+ vim.api.nvim_set_keymap ('n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
]]
feed('aa')
- eq(99, exec_lua[[return SomeValue]])
+ eq({'π<M-π>foo<'}, meths.buf_get_lines(0, 0, -1, false))
+ end)
+
+ it('can make lua expr mappings without replacing keycodes', function()
+ exec_lua [[
+ vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return '<space>' end, expr = true })
+ ]]
+
+ feed('iaa<esc>')
+
+ eq({'<space>'}, meths.buf_get_lines(0, 0, -1, false))
+ end)
+
+ it('lua expr mapping returning nil is equivalent to returnig an empty string', function()
+ exec_lua [[
+ vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return nil end, expr = true })
+ ]]
+
+ feed('iaa<esc>')
+
+ eq({''}, meths.buf_get_lines(0, 0, -1, false))
end)
it('does not reset pum in lua mapping', function()
@@ -1018,16 +1065,27 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
eq(1, exec_lua[[return GlobalCount]])
end)
- it('can make lua expr mappings', function()
+ it('can make lua expr mappings replacing keycodes', function()
exec_lua [[
- vim.api.nvim_buf_set_keymap (0, 'n', 'aa', '', {callback = function() return vim.api.nvim_replace_termcodes(':lua SomeValue = 99<cr>', true, false, true) end, expr = true })
+ vim.api.nvim_buf_set_keymap (0, 'n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
]]
feed('aa')
- eq(99, exec_lua[[return SomeValue ]])
+ eq({'π<M-π>foo<'}, meths.buf_get_lines(0, 0, -1, false))
+ end)
+
+ it('can make lua expr mappings without replacing keycodes', function()
+ exec_lua [[
+ vim.api.nvim_buf_set_keymap (0, 'i', 'aa', '', {callback = function() return '<space>' end, expr = true })
+ ]]
+
+ feed('iaa<esc>')
+
+ eq({'<space>'}, meths.buf_get_lines(0, 0, -1, false))
end)
+
it('can overwrite lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3724dbf820..17de6730fb 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -3733,6 +3733,12 @@ describe('API', function()
eq("", meths.cmd({ cmd = "Foo", bang = false }, { output = true }))
end)
it('works with modifiers', function()
+ -- with :silent output is still captured
+ eq('1',
+ meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } },
+ { output = true }))
+ -- with :silent message isn't added to message history
+ eq('', meths.cmd({ cmd = 'messages' }, { output = true }))
meths.create_user_command("Foo", 'set verbose', {})
eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true }))
eq(0, meths.get_option_value("verbose", {}))