From 3a91adabda43376638e0edc80f54181258c98dea Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 12 May 2022 20:19:29 +0800 Subject: 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". --- test/symbolic/klee/nvim/keymap.c | 2 +- test/symbolic/klee/viml_expressions_lexer.c | 2 +- test/symbolic/klee/viml_expressions_parser.c | 2 +- test/unit/keycodes_spec.lua | 72 ++++++++++++++++++++++++++++ test/unit/keymap_spec.lua | 72 ---------------------------- 5 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 test/unit/keycodes_spec.lua delete mode 100644 test/unit/keymap_spec.lua (limited to 'test') diff --git a/test/symbolic/klee/nvim/keymap.c b/test/symbolic/klee/nvim/keymap.c index ed5f95a344..1f7f0e0911 100644 --- a/test/symbolic/klee/nvim/keymap.c +++ b/test/symbolic/klee/nvim/keymap.c @@ -1,7 +1,7 @@ #include #include "nvim/types.h" -#include "nvim/keymap.h" +#include "nvim/keycodes.h" #include "nvim/ascii.h" #include "nvim/eval/typval.h" diff --git a/test/symbolic/klee/viml_expressions_lexer.c b/test/symbolic/klee/viml_expressions_lexer.c index ee7dc312e9..03c9d66ca4 100644 --- a/test/symbolic/klee/viml_expressions_lexer.c +++ b/test/symbolic/klee/viml_expressions_lexer.c @@ -17,7 +17,7 @@ #include "nvim/charset.c" #include "nvim/garray.c" #include "nvim/gettext.c" -#include "nvim/keymap.c" +#include "nvim/keycodes.c" #include "nvim/viml/parser/expressions.c" #define INPUT_SIZE 7 diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index 9a876ed3fa..b0e1d71127 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -17,7 +17,7 @@ #include "nvim/garray.c" #include "nvim/gettext.c" #include "nvim/viml/parser/expressions.c" -#include "nvim/keymap.c" +#include "nvim/keycodes.c" #define INPUT_SIZE 50 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] = '' + 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] = '' + local all_caps_key = + keymap.find_special_key(srcp, 5, modp, 0, NULL) + local all_caps_mod = modp[0] + + srcp[0] = '' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, 0, NULL)) + eq(all_caps_mod, modp[0]) + + srcp[0] = '' + eq(all_caps_key, + keymap.find_special_key(srcp, 5, modp, 0, NULL)) + eq(all_caps_mod, modp[0]) + + srcp[0] = '' + 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] = '' + 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] = '' + -- 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) diff --git a/test/unit/keymap_spec.lua b/test/unit/keymap_spec.lua deleted file mode 100644 index 1f1f32bb9e..0000000000 --- a/test/unit/keymap_spec.lua +++ /dev/null @@ -1,72 +0,0 @@ -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') -local NULL = helpers.NULL - -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, 0, NULL)) - end) - - itp('keycode with multiple modifiers', function() - srcp[0] = '' - 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] = '' - local all_caps_key = - keymap.find_special_key(srcp, 5, modp, 0, NULL) - local all_caps_mod = modp[0] - - srcp[0] = '' - eq(all_caps_key, - keymap.find_special_key(srcp, 5, modp, 0, NULL)) - eq(all_caps_mod, modp[0]) - - srcp[0] = '' - eq(all_caps_key, - keymap.find_special_key(srcp, 5, modp, 0, NULL)) - eq(all_caps_mod, modp[0]) - - srcp[0] = '' - 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] = '' - 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] = '' - -- 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) -- cgit