diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-05-12 20:19:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 20:19:29 +0800 |
commit | 3a91adabda43376638e0edc80f54181258c98dea (patch) | |
tree | 7863a14dc1113b0304cd74e44f414de8533f9217 /test/unit/keycodes_spec.lua | |
parent | a2d4b862f16ed9814ce45a865a3596c958e066af (diff) | |
download | rneovim-3a91adabda43376638e0edc80f54181258c98dea.tar.gz rneovim-3a91adabda43376638e0edc80f54181258c98dea.tar.bz2 rneovim-3a91adabda43376638e0edc80f54181258c98dea.zip |
refactor: rename keymap.{c,h} to keycodes.{c,h} (#18535)
Most code in keymap.h is for keycode definitions, while most code in
keymap.c is for the parsing and conversion of keycodes.
The name "keymap" may also make people think these two files are for
mappings, while in fact keycodes are used even when no mappings are
involved, so "keycodes" should be a better file name than "keymap".
Diffstat (limited to 'test/unit/keycodes_spec.lua')
-rw-r--r-- | test/unit/keycodes_spec.lua | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/unit/keycodes_spec.lua b/test/unit/keycodes_spec.lua new file mode 100644 index 0000000000..5bf27c9232 --- /dev/null +++ b/test/unit/keycodes_spec.lua @@ -0,0 +1,72 @@ +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/keycodes.h') +local NULL = helpers.NULL + +describe('keycodes.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, 0, NULL)) + end) + + itp('keycode with multiple modifiers', function() + srcp[0] = '<C-M-S-A>' + neq(0, keymap.find_special_key(srcp, 9, modp, 0, NULL)) + neq(0, modp[0]) + end) + + itp('case-insensitive', function() + -- Compare other capitalizations to this. + srcp[0] = '<C-A>' + local all_caps_key = + keymap.find_special_key(srcp, 5, modp, 0, NULL) + local all_caps_mod = modp[0] + + srcp[0] = '<C-a>' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, 0, NULL)) + eq(all_caps_mod, modp[0]) + + srcp[0] = '<c-A>' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, 0, NULL)) + eq(all_caps_mod, modp[0]) + + srcp[0] = '<c-a>' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, 0, NULL)) + 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('"'), + keymap.find_special_key(srcp, 5, modp, 0, NULL)) + + -- Unescaped with in_string=true + eq(0, keymap.find_special_key(srcp, 5, modp, keymap.FSK_IN_STRING, NULL)) + + -- Escaped with in_string=false + srcp[0] = '<C-\\">' + -- Should fail because the key is invalid + -- (more than 1 non-modifier character). + eq(0, keymap.find_special_key(srcp, 6, modp, 0, NULL)) + + -- Escaped with in_string=true + eq(string.byte('"'), + keymap.find_special_key(srcp, 6, modp, keymap.FSK_IN_STRING, NULL)) + end) + end) + +end) |