robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Cmdline-mode tests. 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 , insert , fn , eq , feed =n . clear , n . insert , n . fn , t . eq , n . feed 9local eval =n . eval 10local command =n . command 11local api =n . api 12 13describe ( 'cmdline' , function () 14before_each ( clear ) 15 16describe ( 'Ctrl-R' , function () 17it ( 'pasting non-special register inserts <CR> *between* lines' , function () 18insert ( [[ 19line1abc 20line2somemoretext 21]] ) 22-- Yank 2 lines linewise, then paste to cmdline. 23feed ( [[<C-\><C-N>gg0yj:<C-R>0]] ) 24-- <CR> inserted between lines, NOT after the final line. 25eq ( 'line1abc\rline2somemoretext' , fn . getcmdline ()) 26 27-- Yank 2 lines charwise, then paste to cmdline. 28feed ( [[<C-\><C-N>gg05lyvj:<C-R>0]] ) 29-- <CR> inserted between lines, NOT after the final line. 30eq ( 'abc\rline2' , fn . getcmdline ()) 31 32-- Yank 1 line linewise, then paste to cmdline. 33feed ( [[<C-\><C-N>ggyy:<C-R>0]] ) 34-- No <CR> inserted. 35eq ( 'line1abc' , fn . getcmdline ()) 36end ) 37 38it ( 'pasting special register inserts <CR>, <NL>' , function () 39feed ( [[:<C-R>="foo\nbar\rbaz"<CR>]] ) 40eq ( 'foo\nbar\rbaz' , fn . getcmdline ()) 41end ) 42 43it ( 'pasting handles composing chars properly' , function () 44local screen =Screen . new ( 60 , 4 ) 45-- 'arabicshape' cheats and always redraws everything which trivially works, 46-- this test is for partial redraws in 'noarabicshape' mode. 47command ( 'set noarabicshape' ) 48fn . setreg ( 'a' , '💻' ) 49feed ( ':test 🧑' ) 50screen : expect ( [[ 51| 52{1:~ }|*2 53:test 🧑^ | 54]] ) 55feed ( '<c-r><c-r>a' ) 56screen : expect ( [[ 57| 58{1:~ }|*2 59:test 🧑💻^ | 60]] ) 61end ) 62end ) 63 64it ( 'Ctrl-Shift-V supports entering unsimplified key notations' , function () 65feed ( ':"<C-S-V><C-J><C-S-V><C-@><C-S-V><C-[><C-S-V><C-S-M><C-S-V><M-C-I><C-S-V><C-D-J><CR>' ) 66 67eq ( '"<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>' , eval ( '@:' )) 68end ) 69 70it ( 'redraws statusline when toggling overstrike' , function () 71local screen =Screen . new ( 60 , 4 ) 72command ( 'set laststatus=2 statusline=%!mode(1)' ) 73feed ( ':' ) 74screen : expect { 75grid =[[ 76| 77{1:~ }| 78{3:c }| 79:^ | 80]] , 81} 82feed ( '<Insert>' ) 83screen : expect { 84grid =[[ 85| 86{1:~ }| 87{3:cr }| 88:^ | 89]] , 90} 91end ) 92 93describe ( 'history' , function () 94it ( 'correctly clears start of the history' , function () 95-- Regression test: check absence of the memory leak when clearing start of 96-- the history using cmdhist.c/clr_history(). 97eq ( 1 , fn . histadd ( ':' , 'foo' )) 98eq ( 1 , fn . histdel ( ':' )) 99eq ( '' , fn . histget ( ':' , - 1 )) 100end ) 101 102it ( 'correctly clears end of the history' , function () 103-- Regression test: check absence of the memory leak when clearing end of 104-- the history using cmdhist.c/clr_history(). 105api . nvim_set_option_value ( 'history' , 1 , {} ) 106eq ( 1 , fn . histadd ( ':' , 'foo' )) 107eq ( 1 , fn . histdel ( ':' )) 108eq ( '' , fn . histget ( ':' , - 1 )) 109end ) 110 111it ( 'correctly removes item from history' , function () 112-- Regression test: check that cmdhist.c/del_history_idx() correctly clears 113-- history index after removing history entry. If it does not then deleting 114-- history will result in a double free. 115eq ( 1 , fn . histadd ( ':' , 'foo' )) 116eq ( 1 , fn . histadd ( ':' , 'bar' )) 117eq ( 1 , fn . histadd ( ':' , 'baz' )) 118eq ( 1 , fn . histdel ( ':' , - 2 )) 119eq ( 1 , fn . histdel ( ':' )) 120eq ( '' , fn . histget ( ':' , - 1 )) 121end ) 122end ) 123end )