robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local clear , eq , ok =n . clear , t . eq , t . ok 6local neq , command , fn =t . neq , n . command , n . fn 7local matches =t . matches 8local reltime , reltimestr , reltimefloat =fn . reltime , fn . reltimestr , fn . reltimefloat 9 10describe ( 'reltimestr(), reltimefloat()' , function () 11before_each ( clear ) 12 13it ( 'acceptance' , function () 14local now =reltime () 15command ( 'sleep 10m' ) 16local later =reltime () 17local elapsed =reltime ( now ) 18 19neq ( '0.0' , reltimestr ( elapsed )) 20ok ( reltimefloat ( elapsed ) > 0.0 ) 21-- original vim test for < 0.1, but easily fails on travis 22matches ( '0%.' , reltimestr ( elapsed )) 23ok ( reltimefloat ( elapsed ) < 1.0 ) 24 25local same =reltime ( now , now ) 26local samestr =string . gsub ( reltimestr ( same ), ' ' , '' ) 27samestr =string . sub ( samestr , 1 , 5 ) 28 29eq ( '0.000' , samestr ) 30eq ( 0.0 , reltimefloat ( same )) 31 32local differs =reltime ( now , later ) 33neq ( '0.0' , reltimestr ( differs )) 34ok ( reltimefloat ( differs ) > 0.0 ) 35-- original vim test for < 0.1, but easily fails on travis 36matches ( '0%.' , reltimestr ( differs )) 37ok ( reltimefloat ( differs ) < 1.0 ) 38end ) 39 40it ( '(start - end) returns negative #10452' , function () 41local older_time =reltime () 42command ( 'sleep 1m' ) 43local newer_time =reltime () 44 45-- Start/end swapped: should be something like -0.002123. 46local tm_s =tonumber ( reltimestr ( reltime ( newer_time , older_time ))) 47local tm_f =reltimefloat ( reltime ( newer_time , older_time )) 48ok ( tm_s < 0 and tm_s > - 10 ) 49ok ( tm_f < 0 and tm_f > - 10 ) 50 51-- Not swapped: should be something like 0.002123. 52tm_s =tonumber ( reltimestr ( reltime ( older_time , newer_time ))) 53tm_f =reltimefloat ( reltime ( older_time , newer_time )) 54ok ( tm_s > 0 and tm_s < 10 ) 55ok ( tm_f > 0 and tm_f < 10 ) 56end ) 57end )