robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
64a301184e
master
1-- Test for mappings and abbreviations 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each =t . describe , t . it , t . before_each 8local clear , feed , insert =n . clear , n . feed , n . insert 9local expect , poke_eventloop =n . expect , n . poke_eventloop 10local command , eq , eval , api =n . command , t . eq , n . eval , n . api 11local exec =n . exec 12local sleep =vim . uv . sleep 13 14describe ( 'mapping' , function () 15before_each ( clear ) 16 17it ( 'abbreviations with р (0x80)' , function () 18insert ( [[ 19test starts here: 20]] ) 21 22-- Abbreviations with р (0x80) should work. 23command ( 'inoreab чкпр vim' ) 24feed ( 'GAчкпр <esc>' ) 25 26expect ( [[ 27test starts here: 28vim ]] ) 29end ) 30 31-- oldtest: Test_map_ctrl_c_insert() 32it ( 'Ctrl-c works in Insert mode' , function () 33-- Mapping of ctrl-c in insert mode 34command ( 'set cpo-=< cpo-=k' ) 35command ( 'inoremap <c-c> <ctrl-c>' ) 36command ( 'cnoremap <c-c> dummy' ) 37command ( 'cunmap <c-c>' ) 38feed ( 'GA<cr>' ) 39-- XXX: editor must be in Insert mode before <C-C> is put into input buffer 40poke_eventloop () 41feed ( 'TEST2: CTRL-C |<c-c>A|<cr><esc>' ) 42command ( 'unmap! <c-c>' ) 43 44expect ( [[ 45 46TEST2: CTRL-C |<ctrl-c>A| 47]] ) 48end ) 49 50-- oldtest: Test_map_ctrl_c_visual() 51it ( 'Ctrl-c works in Visual mode' , function () 52command ( [[vnoremap <c-c> :<C-u>$put ='vmap works'<cr>]] ) 53feed ( 'GV' ) 54-- XXX: editor must be in Visual mode before <C-C> is put into input buffer 55poke_eventloop () 56feed ( 'vV<c-c>' ) 57command ( 'vunmap <c-c>' ) 58 59expect ( [[ 60 61vmap works]] ) 62end ) 63 64it ( 'langmap' , function () 65-- langmap should not get remapped in insert mode. 66command ( 'inoremap { FAIL_ilangmap' ) 67command ( 'set langmap=+{ langnoremap' ) 68feed ( 'o+<esc>' ) 69 70-- Insert mode expr mapping with langmap. 71command ( 'inoremap <expr> { "FAIL_iexplangmap"' ) 72feed ( 'o+<esc>' ) 73 74-- langmap should not get remapped in cmdline mode. 75command ( 'cnoremap { FAIL_clangmap' ) 76feed ( 'o+<esc>' ) 77command ( 'cunmap {' ) 78 79-- cmdline mode expr mapping with langmap. 80command ( 'cnoremap <expr> { "FAIL_cexplangmap"' ) 81feed ( 'o+<esc>' ) 82command ( 'cunmap {' ) 83 84-- Assert buffer contents. 85expect ( [[ 86 87+ 88+ 89+ 90+]] ) 91end ) 92 93-- oldtest: Test_map_feedkeys() 94it ( 'feedkeys' , function () 95insert ( [[ 96a b c d 97a b c d 98]] ) 99 100-- Vim's issue #212 (feedkeys insert mapping at current position) 101command ( 'nnoremap . :call feedkeys(".", "in")<cr>' ) 102feed ( '/^a b<cr>' ) 103feed ( '0qqdw.ifoo<esc>qj0@q<esc>' ) 104command ( 'unmap .' ) 105expect ( [[ 106fooc d 107fooc d 108]] ) 109end ) 110 111-- oldtest: Test_map_cursor() 112it ( 'i_CTRL-G_U' , function () 113-- <c-g>U<cursor> works only within a single line 114command ( 'imapclear' ) 115command ( 'imap ( ()<c-g>U<left>' ) 116feed ( 'G2o<esc>ki<cr>Test1: text with a (here some more text<esc>k.' ) 117-- test undo 118feed ( 'G2o<esc>ki<cr>Test2: text wit a (here some more text [und undo]<c-g>u<esc>k.u' ) 119command ( 'imapclear' ) 120command ( 'set whichwrap=<,>,[,]' ) 121feed ( 'G3o<esc>2k' ) 122-- Nvim: "." re-executes the whole insert session, including the (wrapping) 123-- CTRL-G U <Right>, instead of only the text typed after it. 124command ( 125[[:exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>."]] 126) 127 128expect ( [[ 129 130 131Test1: text with a (here some more text) 132Test1: text with a (here some more text) 133 134 135Test2: text wit a (here some more text [und undo]) 136Test3: text with a (parenthesis here 137new line hereTest3: text with a (parenthesis here 138new line here 139]] ) 140end ) 141 142-- oldtest: Test_mouse_drag_mapped_start_select() 143it ( 'dragging starts Select mode even if coming from mapping' , function () 144command ( 'set mouse=a' ) 145command ( 'set selectmode=mouse' ) 146 147command ( 'nnoremap <LeftDrag> <LeftDrag><Cmd><CR>' ) 148poke_eventloop () 149api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 0 ) 150poke_eventloop () 151api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 0 , 1 ) 152poke_eventloop () 153eq ( 's' , eval ( 'mode()' )) 154end ) 155 156-- oldtest: Test_mouse_drag_insert_map() 157it ( '<LeftDrag> mapping in Insert mode works correctly' , function () 158command ( 'set mouse=a' ) 159 160command ( 'inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>' ) 161feed ( 'i' ) 162poke_eventloop () 163api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 0 ) 164poke_eventloop () 165api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 0 , 1 ) 166poke_eventloop () 167eq ( 1 , eval ( 'g:dragged' )) 168eq ( 'v' , eval ( 'mode()' )) 169feed ( [[<C-\><C-N>]] ) 170 171command ( [[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]] ) 172feed ( 'i' ) 173poke_eventloop () 174api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 0 ) 175poke_eventloop () 176api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 0 , 1 ) 177poke_eventloop () 178eq ( 'n' , eval ( 'mode()' )) 179end ) 180 181-- oldtest: Test_map_after_timed_out_nop() 182it ( 'timeout works after an <Nop> mapping is triggered on timeout' , function () 183command ( 'set timeout timeoutlen=400' ) 184command ( 'inoremap ab TEST' ) 185command ( 'inoremap a <Nop>' ) 186-- Enter Insert mode 187feed ( 'i' ) 188-- Wait for the "a" mapping to time out 189feed ( 'a' ) 190sleep ( 500 ) 191-- Send "a" and wait for a period shorter than 'timeoutlen' 192feed ( 'a' ) 193sleep ( 100 ) 194-- Send "b", should trigger the "ab" mapping 195feed ( 'b' ) 196expect ( 'TEST' ) 197end ) 198 199-- oldtest: Test_showcmd_part_map() 200it ( "'showcmd' with a partial mapping" , function () 201local screen =Screen . new ( 60 , 6 ) 202exec ( [[ 203set notimeout showcmd 204nnoremap ,a <Ignore> 205nnoremap ;a <Ignore> 206nnoremap Àa <Ignore> 207nnoremap Ëa <Ignore> 208nnoremap βa <Ignore> 209nnoremap ωa <Ignore> 210nnoremap …a <Ignore> 211nnoremap <C-W>a <Ignore> 212]] ) 213 214for _ , c in ipairs ( { ',' , ';' , 'À' , 'Ë' , 'β' , 'ω' , '…' } ) do 215feed ( c ) 216screen : expect (( [[ 217^ | 218{1:~ }|*4 219%s | 220]] ): format ( c )) 221feed ( 'a' ) 222screen : expect ( [[ 223^ | 224{1:~ }|*4 225| 226]] ) 227end 228 229feed ( '\23' ) 230screen : expect ( [[ 231^ | 232{1:~ }|*4 233^W | 234]] ) 235feed ( 'a' ) 236screen : expect ( [[ 237^ | 238{1:~ }|*4 239| 240]] ) 241 242feed ( '<C-W>' ) 243screen : expect ( [[ 244^ | 245{1:~ }|*4 246^W | 247]] ) 248feed ( 'a' ) 249screen : expect ( [[ 250^ | 251{1:~ }|*4 252| 253]] ) 254end ) 255end )