local helpers = require("test.functional.helpers")(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq local exec = helpers.exec local exec_capture = helpers.exec_capture local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear local command = helpers.command local expect = helpers.expect local insert = helpers.insert local eval = helpers.eval describe(':*map', function() before_each(clear) it('are not affected by &isident', function() meths.set_var('counter', 0) command('nnoremap :let counter+=1') meths.set_option_value('isident', ('%u'):format(('>'):byte()), {}) command('nnoremap :let counter+=1') -- &isident used to disable keycode parsing here as well feed('\24\25') eq(4, meths.get_var('counter')) end) it(':imap ', function() command('imap foo') feed('i--') expect('-foo-') end) it('shows as mapping rhs', function() command('nmap asdf ') eq([[ n asdf ]], exec_capture('nmap asdf')) end) it('mappings with description can be filtered', function() meths.set_keymap('n', 'asdf1', 'qwert', {desc='do the one thing'}) meths.set_keymap('n', 'asdf2', 'qwert', {desc='doesnot really do anything'}) meths.set_keymap('n', 'asdf3', 'qwert', {desc='do the other thing'}) eq([[ n asdf3 qwert do the other thing n asdf1 qwert do the one thing]], exec_capture('filter the nmap')) end) it(' mappings ignore nore', function() command('let x = 0') eq(0, meths.eval('x')) command [[ nnoremap (Increase_x) let x+=1 nmap increase_x_remap (Increase_x) nnoremap increase_x_noremap (Increase_x) ]] feed('increase_x_remap') eq(1, meths.eval('x')) feed('increase_x_noremap') eq(2, meths.eval('x')) end) it("Doesn't auto ignore nore for keys before or after mapping", function() command('let x = 0') eq(0, meths.eval('x')) command [[ nnoremap x nnoremap (Increase_x) let x+=1 nmap increase_x_remap x(Increase_x)x nnoremap increase_x_noremap x(Increase_x)x ]] insert("Some text") eq('Some text', eval("getline('.')")) feed('increase_x_remap') eq(1, meths.eval('x')) eq('Some text', eval("getline('.')")) feed('increase_x_noremap') eq(2, meths.eval('x')) eq('Some te', eval("getline('.')")) end) it(':unmap with rhs works when lhs is in another bucket #21530', function() command('map F Foo') command('unmap Foo') eq('\nNo mapping found', exec_capture('map F')) end) end) describe('Screen', function() local screen before_each(function() clear() screen = Screen.new(20, 5) screen:attach() end) it('cursor is restored after :map which calls input()', function() command('map x input("> ")') screen:expect([[ ^ | ~ |*3 | ]]) feed('x') screen:expect([[ | ~ |*3 > ^ | ]]) feed('\n') screen:expect([[ ^ | ~ |*3 > | ]]) end) it('cursor is restored after :imap which calls input()', function() command('imap x input("> ")') feed('i') screen:expect([[ ^ | ~ |*3 -- INSERT -- | ]]) feed('x') screen:expect([[ | ~ |*3 > ^ | ]]) feed('\n') screen:expect([[ ^ | ~ |*3 -- INSERT -- | ]]) end) it('cursor position does not move after empty-string :cmap #19046', function() command([[cnoremap '']]) feed(':') screen:expect([[ | ~ |*3 :^ | ]]) end) -- oldtest: Test_expr_map_restore_cursor() it('cursor is restored after :map which redraws statusline vim-patch:8.1.2336', function() exec([[ call setline(1, ['one', 'two', 'three']) 2 set ls=2 hi! link StatusLine ErrorMsg noremap Func() func Func() let g:on = !get(g:, 'on', 0) redraws return '' endfunc func Status() return get(g:, 'on', 0) ? '[on]' : '' endfunc set stl=%{Status()} ]]) feed('') screen:expect([[ one | ^two | three | [on] | | ]]) end) it('error in :nmap does not mess up display vim-patch:4.2.4338', function() screen:try_resize(40, 5) command('nmap execute("throw 42")') feed('') screen:expect([[ |*2 Error detected while processing : | E605: Exception not caught: 42 | Press ENTER or type command to continue^ | ]]) feed('') screen:expect([[ ^ | ~ |*3 | ]]) end) it('error in :cmap handled correctly vim-patch:4.2.4338', function() screen:try_resize(40, 5) command('cmap execute("throw 42")') feed(':echo "foo') screen:expect([[ | ~ |*3 :echo "foo^ | ]]) feed('') screen:expect([[ | :echo "foo | Error detected while processing : | E605: Exception not caught: 42 | :echo "foo^ | ]]) feed('"') screen:expect([[ | :echo "foo | Error detected while processing : | E605: Exception not caught: 42 | :echo "foo"^ | ]]) feed('\n') screen:expect([[ :echo "foo | Error detected while processing : | E605: Exception not caught: 42 | foo | Press ENTER or type command to continue^ | ]]) end) -- oldtest: Test_map_listing() it('listing mappings clears command line vim-patch:8.2.4401', function() screen:try_resize(40, 5) command('nmap a b') feed(': nmap a') screen:expect([[ ^ | ~ |*3 n a b | ]]) end) end)