From bc17ad31dccb446fc24e0f6bb3cb2149ce951ae5 Mon Sep 17 00:00:00 2001 From: lePerdu Date: Wed, 18 Oct 2017 18:27:31 -0400 Subject: os/input.c: parse keycodes in non-string context #7411 cb02137dfac7 had two mistakes, of the same nature: trans_special() must be invoked with in_string=false unless the parsing context is a VimL string. replace_termcodes() and input_enqueue() are low-level mechanisms where VimL strings do not exist. keymap.c: adjust double-quote case to satisfy keymap_spec.lua closes #7410 --- test/functional/ex_cmds/map_spec.lua | 7 ++++ test/unit/keymap_spec.lua | 71 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 test/unit/keymap_spec.lua (limited to 'test') diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index b46f83405e..84d5bc2335 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -5,6 +5,7 @@ local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear local command = helpers.command +local expect = helpers.expect describe(':*map', function() before_each(clear) @@ -18,4 +19,10 @@ describe(':*map', function() feed('\24\25') eq(4, meths.get_var('counter')) end) + + it(':imap ', function() + command('imap foo') + feed('i--') + expect('-foo-') + end) end) diff --git a/test/unit/keymap_spec.lua b/test/unit/keymap_spec.lua new file mode 100644 index 0000000000..595a19eb17 --- /dev/null +++ b/test/unit/keymap_spec.lua @@ -0,0 +1,71 @@ +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 + +local keymap = helpers.cimport("./src/nvim/keymap.h") + +describe('keymap.c', function() + + 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' + eq(0, keymap.find_special_key(srcp, 3, modp, false, false, false)) + end) + + itp('keycode with multiple modifiers', function() + srcp[0] = '' + neq(0, keymap.find_special_key(srcp, 9, modp, false, false, false)) + neq(0, modp[0]) + end) + + itp('case-insensitive', function() + -- Compare other capitalizations to this. + srcp[0] = '' + local all_caps_key = + keymap.find_special_key(srcp, 5, modp, false, false, false) + local all_caps_mod = modp[0] + + srcp[0] = '' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, false, false, false)) + eq(all_caps_mod, modp[0]) + + srcp[0] = '' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, false, false, false)) + eq(all_caps_mod, modp[0]) + + srcp[0] = '' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, false, false, false)) + eq(all_caps_mod, modp[0]) + end) + + itp('double-quote in keycode #7411', function() + -- Unescaped with in_string=false + srcp[0] = '' + eq(string.byte('"'), + keymap.find_special_key(srcp, 5, modp, false, false, false)) + + -- Unescaped with in_string=true + eq(0, keymap.find_special_key(srcp, 5, modp, false, false, true)) + + -- Escaped with in_string=false + srcp[0] = '' + -- Should fail because the key is invalid + -- (more than 1 non-modifier character). + eq(0, keymap.find_special_key(srcp, 6, modp, false, false, false)) + + -- Escaped with in_string=true + eq(string.byte('"'), + keymap.find_special_key(srcp, 6, modp, false, false, true)) + end) + end) + +end) -- cgit