robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local n =require ( 'test.functional.testnvim' )() 2local t =require ( 'test.testutil' ) 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 exec_lua =n . exec_lua 8 9describe ( 'treesitter perf' , function () 10before_each ( function () 11clear () 12end ) 13 14it ( 'can handle large folds' , function () 15n . command 'edit ./src/nvim/eval.c' 16exec_lua [[ 17local parser = vim.treesitter.get_parser(0, "c", {}) 18vim.treesitter.highlighter.new(parser) 19 20local function keys(k) 21vim.api.nvim_feedkeys(k, 't', true) 22end 23 24vim.opt.foldmethod = "manual" 25vim.opt.lazyredraw = false 26 27vim.cmd '1000,7000fold' 28vim.cmd '999' 29 30local function mk_keys(n) 31local acc = "" 32for _ = 1, n do 33acc = acc .. "j" 34end 35for _ = 1, n do 36acc = acc .. "k" 37end 38 39return "qq" .. acc .. "q" 40end 41 42local start = vim.uv.hrtime() 43keys(mk_keys(10)) 44 45for _ = 1, 100 do 46keys "@q" 47vim.cmd'redraw!' 48end 49 50return vim.uv.hrtime() - start 51]] 52end ) 53 54local function test_long_line ( _pos , _wrap , _line , grid ) 55local screen =Screen . new ( 20 , 11 ) 56 57local result =exec_lua ( function ( ... ) 58local pos , wrap , line =... 59 60vim . api . nvim_buf_set_lines ( 0 , 0 , 0 , false , { line } ) 61vim . api . nvim_win_set_cursor ( 0 , pos ) 62vim . api . nvim_set_option_value ( 'wrap' , wrap , { win =0 } ) 63 64vim . treesitter . start ( 0 , 'lua' ) 65 66local total ={} 67for _ =1 , 100 do 68local tic =vim . uv . hrtime () 69vim . cmd 'redraw!' 70local toc =vim . uv . hrtime () 71table . insert ( total , toc - tic ) 72end 73 74return { total } 75end , _pos , _wrap , _line ) 76 77screen : expect ( { grid =grid or '' } ) 78 79local total =unpack ( result ) 80table . sort ( total ) 81 82local ms =1 / 1000000 83local res =string . format ( 84'min, 25%%, median, 75%%, max:\n\t%0.2fms,\t%0.2fms,\t%0.2fms,\t%0.2fms,\t%0.2fms' , 85total [ 1 ] * ms , 86total [ 1 + math . floor ( # total * 0.25 )] * ms , 87total [ 1 + math . floor ( # total * 0.5 )] * ms , 88total [ 1 + math . floor ( # total * 0.75 )] * ms , 89total [ # total ] * ms 90) 91( '\nTotal ' .. res ) 92end 93 94local long_line ='local a = { ' .. ( 'a = 5, ' ): rep ( 500 ) .. '}' 95it ( 'can redraw the beginning of a long line with wrapping' , function () 96local grid =[[ 97{15:^local} {25:a} {15:=} {16:{} {25:a} {15:=} {26:5}{16:,} {25:a}| 98{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} | 99{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}| 100{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}| 101{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} | 102{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}| 103{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} | 104{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}| 105{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} | 106{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}| 107| 108]] 109test_long_line ( { 1 , 0 } , true , long_line , grid ) 110end ) 111 112it ( 'can redraw the middle of a long line with wrapping' , function () 113local grid =[[ 114{1:<<<}{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} | 115{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}| 116{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}| 117{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} | 118{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}| 119{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} | 120{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}| 121{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} | 122{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}| 123{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}^ {15:=} {26:5}| 124| 125]] 126test_long_line ( { 1 , math . floor ( # long_line / 2 ) } , true , long_line , grid ) 127end ) 128 129it ( 'can redraw the end of a long line with wrapping' , function () 130local grid =[[ 131{1:<<<}{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}| 132{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} | 133{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}| 134{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} | 135{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}| 136{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}| 137{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} | 138{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}| 139{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} | 140{15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {16:^}} | 141| 142]] 143test_long_line ( { 1 , # long_line - 1 } , true , long_line , grid ) 144end ) 145 146it ( 'can redraw the beginning of a long line without wrapping' , function () 147local grid =[[ 148{15:^local} {25:a} {15:=} {16:{} {25:a} {15:=} {26:5}{16:,} {25:a}| 149| 150{1:~ }|*8 151| 152]] 153test_long_line ( { 1 , 0 } , false , long_line , grid ) 154end ) 155 156it ( 'can redraw the middle of a long line without wrapping' , function () 157local grid =[[ 158{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}^ {15:=} {26:5}{16:,} {25:a} {15:=} | 159| 160{1:~ }|*8 161| 162]] 163test_long_line ( { 1 , math . floor ( # long_line / 2 ) } , false , long_line , grid ) 164end ) 165 166it ( 'can redraw the end of a long line without wrapping' , function () 167local grid =[[ 168{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {16:^}} | 169| 170{1:~ }|*8 171| 172]] 173test_long_line ( { 1 , # long_line - 1 } , false , long_line , grid ) 174end ) 175 176local long_line_mb ='local a = { ' .. ( 'À = 5, ' ): rep ( 500 ) .. '}' 177it ( 'can redraw the middle of a long line with multibyte characters' , function () 178local grid =[[ 179{1:<<<}{26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} | 180{25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,}| 181{25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}| 182{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} | 183{26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=}| 184{26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} | 185{15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À}| 186{15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} | 187{25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,}| 188{25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À}^ {15:=} {26:5}| 189| 190]] 191test_long_line ( { 1 , math . floor ( # long_line_mb / 2 ) } , true , long_line_mb , grid ) 192end ) 193end )