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 clear =n . clear 7local command =n . command 8local api =n . api 9local feed =n . feed 10local poke_eventloop =n . poke_eventloop 11local eq =t . eq 12local retry =t . retry 13 14describe ( "'belloff'" , function () 15local screen 16 17before_each ( function () 18clear () 19screen =Screen . new ( 42 , 5 ) 20screen : expect ( [[ 21^ | 22{1:~ }|*3 23| 24]] ) 25end ) 26 27it ( 'various flags work properly' , function () 28command ( 'set cpoptions+=E' ) 29 30local map ={ 31backspace ='i<BS><Esc>' , 32cursor ='i<Up><Esc>' , 33copy ='i<C-Y><Esc>' , 34ctrlg ='i<C-G><C-G><Esc>' , 35error ='J' , 36esc ='<Esc>' , 37operator ='y0' , 38register ='i<C-R>@<Esc>' , 39} 40 41local items ={} ---@type string[] 42local inputs ={} ---@type string[] 43for item , input in pairs ( map ) do 44table . insert ( items , item ) 45table . insert ( inputs , input ) 46end 47 48local values ={} ---@type string[] 49for i , _ in ipairs ( items ) do 50-- each tested 'belloff' value enables at most one item 51local parts =vim . deepcopy ( items ) 52table . remove ( parts , i ) 53local value =table . concat ( parts , ',' ) 54table . insert ( values , value ) 55end 56table . insert ( values , 'all' ) 57 58for i , value in ipairs ( values ) do 59api . nvim_set_option_value ( 'belloff' , value , {} ) 60 61for j , input in ipairs ( inputs ) do 62screen . bell =false 63local beep =value ~= 'all' and i == j 64-- Nvim avoids beeping more than 3 times in half a second, 65-- so retry if beeping is expected but not received. 66retry ( not beep and 1 or nil , 1000 , function () 67feed ( input ) 68poke_eventloop () 69screen : expect ( { 70condition =function () 71eq ( beep , screen . bell , ( '%s with belloff=%s' ): format ( items [ j ], value )) 72end , 73unchanged =not beep , 74} ) 75end ) 76end 77end 78end ) 79end )