local t = require('test.testutil') local n = require('test.functional.testnvim')() local eq = t.eq local exec_lua = n.exec_lua local clear = n.clear describe('vim.keycode() detailed info', function() before_each(clear) local function parse(key, simplify) local parsed = exec_lua([[return select(2,vim.keycode(...,true))]], key) return vim.tbl_map(function(tbl) if simplify == 1 then return { tbl.mod, tbl.key } elseif simplify == 2 then return { tbl.mod, tbl.key, tbl.key_raw } end return tbl end, parsed) end it('works', function() eq({ { mod = { 'M' }, key = 'f', key_raw = '' } }, parse('')) eq({ { { 'M' }, 'Home' } }, parse('', 1)) eq({ { { 'M' }, 'f' }, { {}, 'b' }, { {}, 'c' } }, parse('b', 1)) eq({ { { 'M' }, '>' } }, parse('>', 1)) eq({ { { 'M' }, 't_>>' } }, parse('>>', 1)) end) it('normalizes', function() -- stylua: ignore start eq({ { {}, '\\', '' } }, parse('\\', 2)) eq({ { { 'M' }, '\\', '' } }, parse('', 2)) eq({ { { 'C' }, '\\', '' } }, parse('', 2)) eq({ { {}, '|', '' } }, parse('|', 2)) eq({ { { 'M' }, '|', '' } }, parse('', 2)) eq({ { { 'C' }, '|', '' } }, parse('', 2)) eq({ { {}, '\127', '\127' } }, parse('\127', 2)) eq({ { { 'M' }, '\127', '' } }, parse('', 2)) eq({ { { 'C' }, '\127', '' } }, parse('', 2)) eq({ { {}, '<', '' } }, parse('<', 2)) eq({ { {}, '\t', '' } }, parse('\t', 2)) eq({ { {}, '\r', '' } }, parse('\r', 2)) eq({ { {}, '\n', '' } }, parse('\n', 2)) eq({ { {}, '\27', '' } }, parse('\27', 2)) eq({ { {}, ' ', '' } }, parse(' ', 2)) eq({ { { 'S' }, 'a', 'A' } }, parse('A', 2)) eq({ { { 'C' }, 'a', '' } }, parse('', 2)) -- stylua: ignore end eq({ { mod = {}, key = '<', key_raw = '', key_orig = 'lt' } }, parse('<')) end) it('handles utf8-chars', function() eq({ { {}, 'ö' }, { { 'M' }, 'ó' }, { {}, 'ú' }, { {}, 'ü' } }, parse('öúü', 1)) eq({ { {}, 'a' }, { {}, '\226\129\129' }, { {}, 'b' } }, parse('a\226\129\129b', 1)) eq({ { {}, 'a' }, { {}, '\242\129\129\129' }, { {}, 'b' } }, parse('a\242\129\129\129b', 1)) end) end)