robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local eq =t . eq 7local exec =n . exec 8local exec_capture =n . exec_capture 9local feed =n . feed 10local api =n . api 11local clear =n . clear 12local command =n . command 13local expect =n . expect 14local insert =n . insert 15local eval =n . eval 16 17describe ( ':*map' , function () 18before_each ( clear ) 19 20it ( 'are not affected by &isident' , function () 21api . nvim_set_var ( 'counter' , 0 ) 22command ( 'nnoremap <C-x> :let counter+=1<CR>' ) 23api . nvim_set_option_value ( 'isident' , ( '%u' ): format (( '>' ): byte ()), {} ) 24command ( 'nnoremap <C-y> :let counter+=1<CR>' ) 25-- &isident used to disable keycode parsing here as well 26feed ( '\24\25<C-x><C-y>' ) 27eq ( 4 , api . nvim_get_var ( 'counter' )) 28end ) 29 30it ( ':imap <M-">' , function () 31command ( 'imap <M-"> foo' ) 32feed ( 'i-<M-">-' ) 33expect ( '-foo-' ) 34end ) 35 36it ( 'shows <Nop> as mapping rhs' , function () 37command ( 'nmap asdf <Nop>' ) 38eq ( 39[[ 40 41n asdf <Nop>]] , 42exec_capture ( 'nmap asdf' ) 43) 44end ) 45 46it ( 'mappings with description can be filtered' , function () 47api . nvim_set_keymap ( 'n' , 'asdf1' , 'qwert' , { desc ='do the one thing' } ) 48api . nvim_set_keymap ( 'n' , 'asdf2' , 'qwert' , { desc ='doesnot really do anything' } ) 49api . nvim_set_keymap ( 'n' , 'asdf3' , 'qwert' , { desc ='do the other thing' } ) 50eq ( 51[[ 52 53n asdf3 qwert 54do the other thing 55n asdf1 qwert 56do the one thing]] , 57exec_capture ( 'filter the nmap' ) 58) 59end ) 60 61it ( '<Plug> mappings ignore nore' , function () 62command ( 'let x = 0' ) 63eq ( 0 , api . nvim_eval ( 'x' )) 64command [[ 65nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> 66nmap increase_x_remap <Plug>(Increase_x) 67nnoremap increase_x_noremap <Plug>(Increase_x) 68]] 69feed ( 'increase_x_remap' ) 70eq ( 1 , api . nvim_eval ( 'x' )) 71feed ( 'increase_x_noremap' ) 72eq ( 2 , api . nvim_eval ( 'x' )) 73end ) 74 75it ( "Doesn't auto ignore nore for keys before or after <Plug> mapping" , function () 76command ( 'let x = 0' ) 77eq ( 0 , api . nvim_eval ( 'x' )) 78command [[ 79nnoremap x <nop> 80nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> 81nmap increase_x_remap x<Plug>(Increase_x)x 82nnoremap increase_x_noremap x<Plug>(Increase_x)x 83]] 84insert ( 'Some text' ) 85eq ( 'Some text' , eval ( "getline('.')" )) 86 87feed ( 'increase_x_remap' ) 88eq ( 1 , api . nvim_eval ( 'x' )) 89eq ( 'Some text' , eval ( "getline('.')" )) 90feed ( 'increase_x_noremap' ) 91eq ( 2 , api . nvim_eval ( 'x' )) 92eq ( 'Some te' , eval ( "getline('.')" )) 93end ) 94 95it ( ':unmap with rhs works when lhs is in another bucket #21530' , function () 96command ( 'map F <Plug>Foo' ) 97command ( 'unmap <Plug>Foo' ) 98eq ( '\nNo mapping found' , exec_capture ( 'map F' )) 99end ) 100end ) 101 102describe ( 'Screen' , function () 103local screen 104before_each ( function () 105clear () 106screen =Screen . new ( 20 , 5 ) 107end ) 108 109it ( 'cursor is restored after :map <expr> which calls input()' , function () 110command ( 'map <expr> x input("> ")' ) 111screen : expect ( [[ 112^ | 113{1:~ }|*3 114| 115]] ) 116feed ( 'x' ) 117screen : expect ( [[ 118| 119{1:~ }|*3 120> ^ | 121]] ) 122feed ( '\n' ) 123screen : expect ( [[ 124^ | 125{1:~ }|*3 126> | 127]] ) 128end ) 129 130it ( 'cursor is restored after :imap <expr> which calls input()' , function () 131command ( 'imap <expr> x input("> ")' ) 132feed ( 'i' ) 133screen : expect ( [[ 134^ | 135{1:~ }|*3 136{5:-- INSERT --} | 137]] ) 138feed ( 'x' ) 139screen : expect ( [[ 140| 141{1:~ }|*3 142> ^ | 143]] ) 144feed ( '\n' ) 145screen : expect ( [[ 146^ | 147{1:~ }|*3 148{5:-- INSERT --} | 149]] ) 150end ) 151 152it ( 'cursor position does not move after empty-string :cmap <expr> #19046' , function () 153command ( [[cnoremap <expr> <F2> '']] ) 154feed ( ':<F2>' ) 155screen : expect ( [[ 156| 157{1:~ }|*3 158:^ | 159]] ) 160end ) 161 162-- oldtest: Test_expr_map_restore_cursor() 163it ( 'cursor is restored after :map <expr> which redraws statusline vim-patch:8.1.2336' , function () 164exec ( [[ 165call setline(1, ['one', 'two', 'three']) 1662 167set ls=2 168hi! link StatusLine ErrorMsg 169noremap <expr> <C-B> Func() 170func Func() 171let g:on = !get(g:, 'on', 0) 172redraws 173return '' 174endfunc 175func Status() 176return get(g:, 'on', 0) ? '[on]' : '' 177endfunc 178set stl=%{Status()} 179]] ) 180feed ( '<C-B>' ) 181screen : expect ( [[ 182one | 183^two | 184three | 185{9:[on] }| 186| 187]] ) 188end ) 189 190it ( 'error in :nmap <expr> does not mess up display vim-patch:4.2.4338' , function () 191screen : try_resize ( 40 , 5 ) 192command ( 'nmap <expr> <F2> execute("throw 42")' ) 193feed ( '<F2>' ) 194screen : expect ( [[ 195| 196{3: }| 197{9:Error in :} | 198{9:E605: Exception not caught: 42} | 199{6:Press ENTER or type command to continue}^ | 200]] ) 201feed ( '<CR>' ) 202screen : expect ( [[ 203^ | 204{1:~ }|*3 205| 206]] ) 207end ) 208 209it ( 'error in :cmap <expr> handled correctly vim-patch:4.2.4338' , function () 210screen : try_resize ( 40 , 5 ) 211command ( 'cmap <expr> <F2> execute("throw 42")' ) 212feed ( ':echo "foo' ) 213screen : expect ( [[ 214| 215{1:~ }|*3 216:echo "foo^ | 217]] ) 218feed ( '<F2>' ) 219screen : expect ( [[ 220{3: }| 221:echo "foo | 222{9:Error in :} | 223{9:E605: Exception not caught: 42} | 224:echo "foo^ | 225]] ) 226feed ( '"' ) 227screen : expect ( [[ 228{3: }| 229:echo "foo | 230{9:Error in :} | 231{9:E605: Exception not caught: 42} | 232:echo "foo"^ | 233]] ) 234feed ( '\n' ) 235screen : expect ( [[ 236:echo "foo | 237{9:Error in :} | 238{9:E605: Exception not caught: 42} | 239foo | 240{6:Press ENTER or type command to continue}^ | 241]] ) 242end ) 243 244-- oldtest: Test_map_listing() 245it ( 'listing mappings clears command line vim-patch:8.2.4401' , function () 246screen : try_resize ( 40 , 5 ) 247command ( 'nmap a b' ) 248feed ( ': nmap a<CR>' ) 249screen : expect ( [[ 250^ | 251{1:~ }|*3 252n a b | 253]] ) 254end ) 255end )