2017-10-18 15:27:31 -07:00
|
|
|
local helpers = require("test.unit.helpers")(after_each)
|
|
|
|
local itp = helpers.gen_itp(it)
|
|
|
|
|
|
|
|
local ffi = helpers.ffi
|
|
|
|
local eq = helpers.eq
|
|
|
|
local neq = helpers.neq
|
|
|
|
|
2022-05-12 05:19:29 -07:00
|
|
|
local keymap = helpers.cimport('./src/nvim/keycodes.h')
|
2022-03-31 00:47:53 -07:00
|
|
|
local NULL = helpers.NULL
|
2017-10-18 15:27:31 -07:00
|
|
|
|
2022-05-12 05:19:29 -07:00
|
|
|
describe('keycodes.c', function()
|
2017-10-18 15:27:31 -07:00
|
|
|
|
|
|
|
describe('find_special_key()', function()
|
|
|
|
local srcp = ffi.new('const unsigned char *[1]')
|
|
|
|
local modp = ffi.new('int[1]')
|
|
|
|
|
|
|
|
itp('no keycode', function()
|
|
|
|
srcp[0] = 'abc'
|
2022-04-26 00:05:56 -07:00
|
|
|
eq(0, keymap.find_special_key(srcp, 3, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
itp('keycode with multiple modifiers', function()
|
|
|
|
srcp[0] = '<C-M-S-A>'
|
2022-04-26 00:05:56 -07:00
|
|
|
neq(0, keymap.find_special_key(srcp, 9, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
neq(0, modp[0])
|
|
|
|
end)
|
|
|
|
|
|
|
|
itp('case-insensitive', function()
|
|
|
|
-- Compare other capitalizations to this.
|
|
|
|
srcp[0] = '<C-A>'
|
|
|
|
local all_caps_key =
|
2022-04-26 00:05:56 -07:00
|
|
|
keymap.find_special_key(srcp, 5, modp, 0, NULL)
|
2017-10-18 15:27:31 -07:00
|
|
|
local all_caps_mod = modp[0]
|
|
|
|
|
|
|
|
srcp[0] = '<C-a>'
|
|
|
|
eq(all_caps_key,
|
2022-04-26 00:05:56 -07:00
|
|
|
keymap.find_special_key(srcp, 5, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
eq(all_caps_mod, modp[0])
|
|
|
|
|
|
|
|
srcp[0] = '<c-A>'
|
|
|
|
eq(all_caps_key,
|
2022-04-26 00:05:56 -07:00
|
|
|
keymap.find_special_key(srcp, 5, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
eq(all_caps_mod, modp[0])
|
|
|
|
|
|
|
|
srcp[0] = '<c-a>'
|
|
|
|
eq(all_caps_key,
|
2022-04-26 00:05:56 -07:00
|
|
|
keymap.find_special_key(srcp, 5, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
eq(all_caps_mod, modp[0])
|
|
|
|
end)
|
|
|
|
|
|
|
|
itp('double-quote in keycode #7411', function()
|
|
|
|
-- Unescaped with in_string=false
|
|
|
|
srcp[0] = '<C-">'
|
|
|
|
eq(string.byte('"'),
|
2022-04-26 00:05:56 -07:00
|
|
|
keymap.find_special_key(srcp, 5, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
|
|
|
|
-- Unescaped with in_string=true
|
2022-04-26 00:05:56 -07:00
|
|
|
eq(0, keymap.find_special_key(srcp, 5, modp, keymap.FSK_IN_STRING, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
|
|
|
|
-- Escaped with in_string=false
|
|
|
|
srcp[0] = '<C-\\">'
|
|
|
|
-- Should fail because the key is invalid
|
|
|
|
-- (more than 1 non-modifier character).
|
2022-04-26 00:05:56 -07:00
|
|
|
eq(0, keymap.find_special_key(srcp, 6, modp, 0, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
|
|
|
|
-- Escaped with in_string=true
|
|
|
|
eq(string.byte('"'),
|
2022-04-26 00:05:56 -07:00
|
|
|
keymap.find_special_key(srcp, 6, modp, keymap.FSK_IN_STRING, NULL))
|
2017-10-18 15:27:31 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|