robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Test for v:hlsearch 2 3source check.vim 4source screendump.vim 5 6func Test_hlsearch () 7new 8call setline ( 1 , repeat ([ 'aaa' ], 10 )) 9set hlsearch nolazyredraw 10" redraw is needed to make hlsearch highlight the matches 11exe "normal! /aaa\<CR>" |redraw 12let r1 = screenattr ( 1 , 1 ) 13nohlsearch |redraw 14call assert_notequal ( r1 , screenattr ( 1 , 1 )) 15let v: hlsearch = 1 |redraw 16call assert_equal ( r1 , screenattr ( 1 , 1 )) 17let v: hlsearch = 0 |redraw 18call assert_notequal ( r1 , screenattr ( 1 , 1 )) 19set hlsearch |redraw 20call assert_equal ( r1 , screenattr ( 1 , 1 )) 21let v: hlsearch = 0 |redraw 22call assert_notequal ( r1 , screenattr ( 1 , 1 )) 23exe "normal! n" |redraw 24call assert_equal ( r1 , screenattr ( 1 , 1 )) 25let v: hlsearch = 0 |redraw 26call assert_notequal ( r1 , screenattr ( 1 , 1 )) 27exe "normal! /\<CR>" |redraw 28call assert_equal ( r1 , screenattr ( 1 , 1 )) 29set nohls 30exe "normal! /\<CR>" |redraw 31call assert_notequal ( r1 , screenattr ( 1 , 1 )) 32call assert_fails ( 'let v:hlsearch=[]' , 'E745' ) 33call garbagecollect ( 1 ) 34call getchar ( 1 ) 35enew ! 36endfunc 37 38func Test_hlsearch_hangs () 39if ! has ( 'reltime' ) || ! has ( 'float' ) 40return 41endif 42 43" So, it turns out the Windows 7 implements TimerQueue timers differently 44" and they can expire *before* the requested time has elapsed. So allow for 45" the timeout occurring after 80 ms (5 * 16 (the typical clock tick)). 46if has ( "win32" ) 47let min_timeout = 0.08 48else 49let min_timeout = 0.1 50endif 51 52" This pattern takes a long time to match, it should timeout. 53new 54call setline ( 1 , [ 'aaa' , repeat ( 'abc ' , 100000 ), 'ccc' ]) 55let start = reltime () 56set hlsearch nolazyredraw redrawtime = 101 57let @/= '\%#=1a*.*X\@<=b*' 58redraw 59let elapsed = reltimefloat ( reltime ( start )) 60call assert_inrange ( min_timeout , 1.0 , elapsed ) 61set nohlsearch redrawtime & 62bwipe ! 63endfunc 64 65func Test_hlsearch_eol_highlight () 66new 67call append ( 1 , repeat ([ '' ], 9 )) 68set hlsearch nolazyredraw 69exe "normal! /$\<CR>" |redraw 70let attr = screenattr ( 1 , 1 ) 71for row in range ( 2 , 10 ) 72call assert_equal ( attr , screenattr ( row , 1 ), 'in line ' . row ) 73endfor 74set nohlsearch 75bwipe ! 76endfunc 77 78func Test_hlsearch_Ctrl_R () 79CheckScreendump 80CheckRunVimInTerminal 81 82let lines =<< trim END 83set incsearch hlsearch 84let @" = "text" 85put 86END 87call writefile ( lines , 'XhlsearchCtrlR' , 'D' ) 88let buf = RunVimInTerminal ( '-S XhlsearchCtrlR' , #{ rows : 6 , cols : 60 }) 89 90call term_sendkeys ( buf , "/\<C-R>\<C-R>\"" ) 91call VerifyScreenDump ( buf , 'Test_hlsearch_ctrlr_1' , {}) 92 93call term_sendkeys ( buf , "\<Esc>" ) 94call StopVimInTerminal ( buf ) 95endfunc 96 97func Test_hlsearch_clipboard () 98CheckScreendump 99CheckRunVimInTerminal 100CheckFeature clipboard_working 101 102let lines =<< trim END 103set incsearch hlsearch 104let @* = "text" 105put * 106END 107call writefile ( lines , 'XhlsearchClipboard' , 'D' ) 108let buf = RunVimInTerminal ( '-S XhlsearchClipboard' , #{ rows : 6 , cols : 60 }) 109 110call term_sendkeys ( buf , "/\<C-R>*" ) 111call VerifyScreenDump ( buf , 'Test_hlsearch_ctrlr_1' , {}) 112 113call term_sendkeys ( buf , "\<Esc>" ) 114call StopVimInTerminal ( buf ) 115endfunc 116 117" vim: shiftwidth=2 sts=2 expandtab