aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/map_functions_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:29 +0100
commit04f2f864e270e772c6326cefdf24947f0130e492 (patch)
tree46f83f909b888a66c741032ab955afc6eab84292 /test/functional/vimscript/map_functions_spec.lua
parent59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff)
downloadrneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip
refactor: format test/*
Diffstat (limited to 'test/functional/vimscript/map_functions_spec.lua')
-rw-r--r--test/functional/vimscript/map_functions_spec.lua85
1 files changed, 46 insertions, 39 deletions
diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua
index e3cc653e12..b0c4a9747a 100644
--- a/test/functional/vimscript/map_functions_spec.lua
+++ b/test/functional/vimscript/map_functions_spec.lua
@@ -19,22 +19,22 @@ describe('maparg()', function()
before_each(clear)
local foo_bar_map_table = {
- lhs='foo',
- lhsraw='foo',
- script=0,
- silent=0,
- rhs='bar',
- expr=0,
- sid=0,
- scriptversion=1,
- buffer=0,
- nowait=0,
- mode='n',
- mode_bits=0x01,
- abbr=0,
- noremap=1,
- lnum=0,
- }
+ lhs = 'foo',
+ lhsraw = 'foo',
+ script = 0,
+ silent = 0,
+ rhs = 'bar',
+ expr = 0,
+ sid = 0,
+ scriptversion = 1,
+ buffer = 0,
+ nowait = 0,
+ mode = 'n',
+ mode_bits = 0x01,
+ abbr = 0,
+ noremap = 1,
+ lnum = 0,
+ }
it('returns a dictionary', function()
nvim('command', 'nnoremap foo bar')
@@ -64,7 +64,7 @@ describe('maparg()', function()
eq(
funcs.maparg('hello', 'i', false, true)['noremap'],
funcs.maparg('this', 'i', false, true)['noremap']
- )
+ )
end)
it('returns a boolean for buffer', function()
@@ -135,7 +135,7 @@ describe('maparg()', function()
it('works with combining characters', function()
-- Using addacutes to make combining character better visible
local function ac(s)
- local acute = '\204\129' -- U+0301 COMBINING ACUTE ACCENT
+ local acute = '\204\129' -- U+0301 COMBINING ACUTE ACCENT
local ret = s:gsub('`', acute)
return ret
end
@@ -145,8 +145,8 @@ describe('maparg()', function()
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(''), funcs.maparg(ac('c')))
+ eq(ac('d'), funcs.maparg(ac('c`')))
eq(ac('f`'), funcs.maparg(ac('e`')))
local function acmap(lhs, rhs)
@@ -170,9 +170,9 @@ 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({}, 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))
end)
end)
@@ -182,30 +182,30 @@ describe('mapset()', function()
it('can restore mapping with backslash in lhs', function()
meths.set_keymap('n', '\\ab', 'a', {})
- eq('\nn \\ab a', exec_capture("nmap \\ab"))
+ eq('\nn \\ab a', exec_capture('nmap \\ab'))
local mapargs = funcs.maparg('\\ab', 'n', false, true)
meths.set_keymap('n', '\\ab', 'b', {})
- eq('\nn \\ab b', exec_capture("nmap \\ab"))
+ eq('\nn \\ab b', exec_capture('nmap \\ab'))
funcs.mapset('n', false, mapargs)
- eq('\nn \\ab a', exec_capture("nmap \\ab"))
+ 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'})
- eq('\nn lhs rhs\n map description', exec_capture("nmap lhs"))
+ meths.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'})
- eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture("nmap lhs"))
+ meths.set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' })
+ eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture('nmap lhs'))
funcs.mapset('n', false, mapargs)
- eq('\nn lhs rhs\n map description', exec_capture("nmap lhs"))
+ 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})
+ 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})
+ meths.set_keymap('i', 'foo', [['<l' .. 't>']], { expr = true })
feed('foo')
expect('<<lt>')
funcs.mapset('i', false, mapargs)
@@ -230,11 +230,14 @@ describe('mapset()', function()
end)
it('can restore Lua callback from the dict returned by maparg()', function()
- eq(0, exec_lua([[
+ eq(
+ 0,
+ exec_lua([[
GlobalCount = 0
vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
- ]]))
+ ]])
+ )
feed('asdf')
eq(1, exec_lua([[return GlobalCount]]))
@@ -262,9 +265,13 @@ describe('mapset()', function()
end)
it('does not leak memory if lhs is missing', function()
- eq('Vim:E460: Entries missing in mapset() dict argument',
- pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]]))
- eq('Vim:E460: Entries missing in mapset() dict argument',
- pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]]))
+ eq(
+ 'Vim:E460: Entries missing in mapset() dict argument',
+ pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]])
+ )
+ eq(
+ 'Vim:E460: Entries missing in mapset() dict argument',
+ pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]])
+ )
end)
end)