local helpers = require('test.functional.helpers')(after_each) local clear, feed_command = helpers.clear, helpers.feed_command local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq local command = helpers.command local expect = helpers.expect local meths = helpers.meths local exec_lua = helpers.exec_lua local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') before_each(clear) describe('mappings', function() local add_mapping = function(mapping, send) local cmd = "nnoremap "..mapping.." :call rpcnotify(1, 'mapped', '" ..send:gsub('<', '').."')" feed_command(cmd) end local check_mapping = function(mapping, expected) feed(mapping) eq({'notification', 'mapped', {expected}}, next_msg()) end before_each(function() add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('', '') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') add_mapping('','') end) it('ok', function() check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('', '') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') check_mapping('','') end) it('support meta + multibyte char mapping', function() add_mapping('', '') check_mapping('', '') end) end) describe('input utf sequences that contain K_SPECIAL (0x80)', function() it('ok', function() feed('i…') expect('…') end) it('can be mapped', function() command('inoremap … E280A6') feed('i…') expect('E280A6') end) end) describe('input utf sequences that contain CSI (0x9B)', function() it('ok', function() feed('iě') expect('ě') end) it('can be mapped', function() command('inoremap ě C49B') feed('iě') expect('C49B') end) end) describe('input non-printable chars', function() after_each(function() os.remove('Xtest-overwrite') end) it("doesn't crash when echoing them back", function() write_file("Xtest-overwrite", [[foobar]]) local screen = Screen.new(60,8) screen:set_default_attr_ids({ [1] = {bold = true, foreground = Screen.colors.Blue1}, [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, [3] = {bold = true, foreground = Screen.colors.SeaGreen4} }) screen:attach() command("set display-=msgsep shortmess-=F") feed_command("e Xtest-overwrite") screen:expect([[ ^foobar | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| "Xtest-overwrite" [noeol] 1L, 6C | ]]) -- The timestamp is in second resolution, wait two seconds to be sure. screen:sleep(2000) write_file("Xtest-overwrite", [[smurf]]) feed_command("w") screen:expect([[ {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| "Xtest-overwrite" | {2:WARNING: The file has been changed since reading it!!!} | {3:Do you really want to write to it (y/n)?}^ | ]]) feed("u") screen:expect([[ {1:~ }| {1:~ }| {1:~ }| {1:~ }| "Xtest-overwrite" | {2:WARNING: The file has been changed since reading it!!!} | {3:Do you really want to write to it (y/n)?}u | {3:Do you really want to write to it (y/n)?}^ | ]]) feed("\005") screen:expect([[ {1:~ }| {1:~ }| {1:~ }| "Xtest-overwrite" | {2:WARNING: The file has been changed since reading it!!!} | {3:Do you really want to write to it (y/n)?}u | {3:Do you really want to write to it (y/n)?} | {3:Do you really want to write to it (y/n)?}^ | ]]) feed("n") screen:expect([[ {1:~ }| {1:~ }| "Xtest-overwrite" | {2:WARNING: The file has been changed since reading it!!!} | {3:Do you really want to write to it (y/n)?}u | {3:Do you really want to write to it (y/n)?} | {3:Do you really want to write to it (y/n)?}n | {3:Press ENTER or type command to continue}^ | ]]) feed("") screen:expect([[ ^foobar | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| | ]]) end) end) describe("event processing and input", function() it('not blocked by event bursts', function() meths.set_keymap('', '', "lua vim.rpcnotify(1, 'stop') winning = true ", {noremap=true}) exec_lua [[ winning = false burst = vim.schedule_wrap(function(tell) if tell then vim.rpcnotify(1, 'start') end -- Are we winning, son? if not winning then burst(false) end end) burst(true) ]] eq({'notification', 'start', {}}, next_msg()) feed '' eq({'notification', 'stop', {}}, next_msg()) end) end)