robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
052498ed42
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local api =n . api 5local write_file =t . write_file 6local concat_tables =t . concat_tables 7 8local tmpname =t . tmpname () 9 10-- o={ 11-- args=…, 12-- args_rm=…, 13-- shadafile=…, 14-- } 15local function reset ( o ) 16assert ( o == nil or type ( o ) == 'table' or type ( o ) == 'string' ) 17o =o and o or {} 18local args_rm =o . args_rm or {} 19table . insert ( args_rm , '-i' ) 20local args ={ 21'-i' , 22o . shadafile or tmpname , 23} 24if type ( o ) == 'string' then 25args =concat_tables ( args , { '--cmd' , o } ) 26elseif o . args then 27args =concat_tables ( args , o . args ) 28end 29n . clear { 30args_rm =args_rm , 31args =args , 32} 33api . nvim_set_var ( 'tmpname' , tmpname ) 34end 35 36local clear =function () 37n . expect_exit ( n . command , 'qall!' ) 38os . remove ( tmpname ) 39end 40 41local get_shada_rw =function ( fname ) 42local wshada =function ( text ) 43write_file ( fname , text , true ) 44end 45local sdrcmd =function ( bang ) 46return 'rshada' .. ( bang and '!' or '' ) .. ' ' .. fname 47end 48local clean =function () 49os . remove ( fname ) 50local i =( 'a' ): byte () 51while i <= ( 'z' ): byte () do 52if not os . remove ( fname .. ( '.tmp.%c' ): format ( i )) then 53break 54end 55i =i + 1 56end 57end 58return wshada , sdrcmd , fname , clean 59end 60 61local mpack_keys ={ 'type' , 'timestamp' , 'length' , 'value' } 62 63local read_shada_file =function ( fname ) 64local fd =io . open ( fname , 'r' ) 65local mstring =fd : read ( '*a' ) 66fd : close () 67local unpack =vim . mpack . Unpacker () 68local ret ={} 69local cur , val 70local i =0 71local off =1 72while off <= # mstring do 73val , off =unpack ( mstring , off ) 74if i % 4 == 0 then 75cur ={} 76ret [ # ret + 1 ] =cur 77end 78cur [ mpack_keys [( i % 4 ) + 1 ]] =val 79i =i + 1 80end 81return ret 82end 83 84return { 85reset =reset , 86clear =clear , 87get_shada_rw =get_shada_rw , 88read_shada_file =read_shada_file , 89}