aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/map_functions_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-12 19:40:58 +0000
committerGitHub <noreply@github.com>2024-01-12 19:40:58 +0000
commit07a7c0ec999102f223a6aca17e93d33e18c02b94 (patch)
tree221ea513b45596f8e63035955494167fc20bf826 /test/functional/vimscript/map_functions_spec.lua
parent7f249936a989dbc21ad03e394197afc07cb9c0bf (diff)
parent795f896a5772d5e0795f86642bdf90c82efac45c (diff)
downloadrneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.gz
rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.bz2
rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.zip
Merge pull request #26994 from lewis6991/vimhelpers
test: big cleanup
Diffstat (limited to 'test/functional/vimscript/map_functions_spec.lua')
-rw-r--r--test/functional/vimscript/map_functions_spec.lua97
1 files changed, 48 insertions, 49 deletions
diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua
index b0c4a9747a..59d427ca90 100644
--- a/test/functional/vimscript/map_functions_spec.lua
+++ b/test/functional/vimscript/map_functions_spec.lua
@@ -7,9 +7,8 @@ local exec = helpers.exec
local exec_lua = helpers.exec_lua
local expect = helpers.expect
local feed = helpers.feed
-local funcs = helpers.funcs
-local meths = helpers.meths
-local nvim = helpers.nvim
+local fn = helpers.fn
+local api = helpers.api
local source = helpers.source
local command = helpers.command
local exec_capture = helpers.exec_capture
@@ -37,47 +36,47 @@ describe('maparg()', function()
}
it('returns a dictionary', function()
- nvim('command', 'nnoremap foo bar')
- eq('bar', funcs.maparg('foo'))
- eq(foo_bar_map_table, funcs.maparg('foo', 'n', false, true))
+ command('nnoremap foo bar')
+ eq('bar', fn.maparg('foo'))
+ eq(foo_bar_map_table, fn.maparg('foo', 'n', false, true))
end)
it('returns 1 for silent when <silent> is used', function()
- nvim('command', 'nnoremap <silent> foo bar')
- eq(1, funcs.maparg('foo', 'n', false, true)['silent'])
+ command('nnoremap <silent> foo bar')
+ eq(1, fn.maparg('foo', 'n', false, true)['silent'])
- nvim('command', 'nnoremap baz bat')
- eq(0, funcs.maparg('baz', 'n', false, true)['silent'])
+ command('nnoremap baz bat')
+ eq(0, fn.maparg('baz', 'n', false, true)['silent'])
end)
it('returns an empty string when no map is present', function()
- eq('', funcs.maparg('not a mapping'))
+ eq('', fn.maparg('not a mapping'))
end)
it('returns an empty dictionary when no map is present and dict is requested', function()
- eq({}, funcs.maparg('not a mapping', 'n', false, true))
+ eq({}, fn.maparg('not a mapping', 'n', false, true))
end)
it('returns the same value for noremap and <script>', function()
- nvim('command', 'inoremap <script> hello world')
- nvim('command', 'inoremap this that')
+ command('inoremap <script> hello world')
+ command('inoremap this that')
eq(
- funcs.maparg('hello', 'i', false, true)['noremap'],
- funcs.maparg('this', 'i', false, true)['noremap']
+ fn.maparg('hello', 'i', false, true)['noremap'],
+ fn.maparg('this', 'i', false, true)['noremap']
)
end)
it('returns a boolean for buffer', function()
-- Open enough windows to know we aren't on buffer number 1
- nvim('command', 'new')
- nvim('command', 'new')
- nvim('command', 'new')
- nvim('command', 'cnoremap <buffer> this that')
- eq(1, funcs.maparg('this', 'c', false, true)['buffer'])
+ command('new')
+ command('new')
+ command('new')
+ command('cnoremap <buffer> this that')
+ eq(1, fn.maparg('this', 'c', false, true)['buffer'])
-- Global will return 0 always
- nvim('command', 'nnoremap other another')
- eq(0, funcs.maparg('other', 'n', false, true)['buffer'])
+ command('nnoremap other another')
+ eq(0, fn.maparg('other', 'n', false, true)['buffer'])
end)
it('returns script numbers', function()
@@ -88,8 +87,8 @@ describe('maparg()', function()
nnoremap fizz :call <SID>maparg_test_function()<CR>
]])
- eq(1, funcs.maparg('fizz', 'n', false, true)['sid'])
- eq('testing', nvim('call_function', '<SNR>1_maparg_test_function', {}))
+ eq(1, fn.maparg('fizz', 'n', false, true)['sid'])
+ eq('testing', api.nvim_call_function('<SNR>1_maparg_test_function', {}))
end)
it('works with <F12> and others', function()
@@ -104,7 +103,7 @@ describe('maparg()', function()
]])
eq(1, eval('g:maparg_test_var'))
- eq(':let g:maparg_test_var = 1<CR>', funcs.maparg('<F12>', 'n', false, true)['rhs'])
+ eq(':let g:maparg_test_var = 1<CR>', fn.maparg('<F12>', 'n', false, true)['rhs'])
end)
it('works with <expr>', function()
@@ -127,7 +126,7 @@ describe('maparg()', function()
]])
eq(1, eval('g:counter'))
- local map_dict = funcs.maparg('<C-L>', 'i', false, true)
+ local map_dict = fn.maparg('<C-L>', 'i', false, true)
eq(1, map_dict['expr'])
eq('i', map_dict['mode'])
end)
@@ -144,10 +143,10 @@ describe('maparg()', function()
nnoremap c` d
nnoremap e` f`
]]))
- eq(ac('b`'), funcs.maparg(ac('a')))
- eq(ac(''), funcs.maparg(ac('c')))
- eq(ac('d'), funcs.maparg(ac('c`')))
- eq(ac('f`'), funcs.maparg(ac('e`')))
+ eq(ac('b`'), fn.maparg(ac('a')))
+ eq(ac(''), fn.maparg(ac('c')))
+ eq(ac('d'), fn.maparg(ac('c`')))
+ eq(ac('f`'), fn.maparg(ac('e`')))
local function acmap(lhs, rhs)
return {
@@ -170,10 +169,10 @@ describe('maparg()', function()
}
end
- eq({}, funcs.maparg(ac('c'), 'n', 0, 1))
- eq(acmap('a', 'b`'), funcs.maparg(ac('a'), 'n', 0, 1))
- eq(acmap('c`', 'd'), funcs.maparg(ac('c`'), 'n', 0, 1))
- eq(acmap('e`', 'f`'), funcs.maparg(ac('e`'), 'n', 0, 1))
+ eq({}, fn.maparg(ac('c'), 'n', 0, 1))
+ eq(acmap('a', 'b`'), fn.maparg(ac('a'), 'n', 0, 1))
+ eq(acmap('c`', 'd'), fn.maparg(ac('c`'), 'n', 0, 1))
+ eq(acmap('e`', 'f`'), fn.maparg(ac('e`'), 'n', 0, 1))
end)
end)
@@ -181,34 +180,34 @@ describe('mapset()', function()
before_each(clear)
it('can restore mapping with backslash in lhs', function()
- meths.set_keymap('n', '\\ab', 'a', {})
+ api.nvim_set_keymap('n', '\\ab', 'a', {})
eq('\nn \\ab a', exec_capture('nmap \\ab'))
- local mapargs = funcs.maparg('\\ab', 'n', false, true)
- meths.set_keymap('n', '\\ab', 'b', {})
+ local mapargs = fn.maparg('\\ab', 'n', false, true)
+ api.nvim_set_keymap('n', '\\ab', 'b', {})
eq('\nn \\ab b', exec_capture('nmap \\ab'))
- funcs.mapset('n', false, mapargs)
+ fn.mapset('n', false, mapargs)
eq('\nn \\ab a', exec_capture('nmap \\ab'))
end)
it('can restore mapping description from the dict returned by maparg()', function()
- meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' })
+ api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' })
eq('\nn lhs rhs\n map description', exec_capture('nmap lhs'))
- local mapargs = funcs.maparg('lhs', 'n', false, true)
- meths.set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' })
+ local mapargs = fn.maparg('lhs', 'n', false, true)
+ api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' })
eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture('nmap lhs'))
- funcs.mapset('n', false, mapargs)
+ fn.mapset('n', false, mapargs)
eq('\nn lhs rhs\n map description', 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 })
+ api.nvim_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 })
+ local mapargs = fn.maparg('foo', 'i', false, true)
+ api.nvim_set_keymap('i', 'foo', [['<l' .. 't>']], { expr = true })
feed('foo')
expect('<<lt>')
- funcs.mapset('i', false, mapargs)
+ fn.mapset('i', false, mapargs)
feed('foo')
expect('<<lt><')
end)
@@ -218,12 +217,12 @@ describe('mapset()', function()
eq('\ni foo * bar', exec_capture('iabbr foo'))
feed('ifoo ')
expect('bar ')
- local mapargs = funcs.maparg('foo', 'i', true, true)
+ local mapargs = fn.maparg('foo', 'i', true, true)
command('inoreabbr foo BAR')
eq('\ni foo * BAR', exec_capture('iabbr foo'))
feed('foo ')
expect('bar BAR ')
- funcs.mapset('i', true, mapargs)
+ fn.mapset('i', true, mapargs)
eq('\ni foo * bar', exec_capture('iabbr foo'))
feed('foo<Esc>')
expect('bar BAR bar')