From 96c392dee3f8f04f90cc56ff752a18b5a915e869 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Tue, 11 Jan 2022 12:24:44 +0900 Subject: [PATCH] Improve tests --- lua/cmp/utils/keymap.lua | 2 +- lua/cmp/utils/keymap_spec.lua | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lua/cmp/utils/keymap.lua b/lua/cmp/utils/keymap.lua index daf9b0d..3a609e0 100644 --- a/lua/cmp/utils/keymap.lua +++ b/lua/cmp/utils/keymap.lua @@ -7,7 +7,7 @@ local keymap = {} ---@param keys string ---@return string keymap.t = function(keys) - return (string.gsub(keys, '(<[A-Za-z0-9_%-%[%]%^@]->)', function(match) + return (string.gsub(keys, '(<[A-Za-z0-9%-%[%]%^@]->)', function(match) return vim.api.nvim_eval(string.format([["\%s"]], match)) end)) end diff --git a/lua/cmp/utils/keymap_spec.lua b/lua/cmp/utils/keymap_spec.lua index 987c764..e185bf1 100644 --- a/lua/cmp/utils/keymap_spec.lua +++ b/lua/cmp/utils/keymap_spec.lua @@ -7,9 +7,22 @@ describe('keymap', function() before_each(spec.before) it('t', function() - assert.are.equal(keymap.t(''), vim.api.nvim_replace_termcodes('', true, true, true)) - assert.are.equal(keymap.t('u'), vim.api.nvim_replace_termcodes('u', true, true, true)) - assert.are.equal(keymap.t('aiueo'), vim.api.nvim_replace_termcodes('aiueo', true, true, true)) + for _, key in ipairs({ + '', + '', + '', + '', + '', + '', + '', + '(example)', + '="abc"', + 'normal! ==', + }) do + assert.are.equal(keymap.t(key), vim.api.nvim_replace_termcodes(key, true, true, true)) + assert.are.equal(keymap.t(key .. key), vim.api.nvim_replace_termcodes(key .. key, true, true, true)) + assert.are.equal(keymap.t(key .. key .. key), vim.api.nvim_replace_termcodes(key .. key .. key, true, true, true)) + end end) it('to_keymap', function()