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 , after_each =t . describe , t . it , t . before_each , t . after_each 6local clear =n . clear 7local exec_lua =n . exec_lua 8 9describe ( 'extmark perf' , function () 10before_each ( function () 11clear () 12 13exec_lua ( [[ 14out = {} 15function start() 16ts = vim.uv.hrtime() 17end 18function stop(name) 19out[#out+1] = ('%14.6f ms - %s'):format((vim.uv.hrtime() - ts) / 1000000, name) 20end 21]] ) 22end ) 23 24after_each ( function () 25for _ , line in ipairs ( exec_lua ( [[return out]] )) do 26( line ) 27end 28end ) 29 30it ( 'repeatedly calling nvim_buf_clear_namespace #28615' , function () 31exec_lua ( [[ 32vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'foo', 'bar' }) 33local ns0 = vim.api.nvim_create_namespace('ns0') 34local ns1 = vim.api.nvim_create_namespace('ns1') 35 36for _ = 1, 10000 do 37vim.api.nvim_buf_set_extmark(0, ns0, 0, 0, {}) 38end 39vim.api.nvim_buf_set_extmark(0, ns1, 1, 0, {}) 40 41start() 42for _ = 1, 10000 do 43vim.api.nvim_buf_clear_namespace(0, ns1, 0, -1) 44end 45stop('nvim_buf_clear_namespace') 46]] ) 47end ) 48 49it ( 'many non-wrapped virtual lines' , function () 50local screen =Screen . new ( 40 , 999 ) 51exec_lua ( [[ 52vim.cmd('1new') 53vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3' }) 54local ns = vim.api.nvim_create_namespace('virt_lines') 55local virt_lines = {} 56for i = 1, 2000 do 57virt_lines[i] = { { 'VIRT_LINE', 'ErrorMsg' } } 58end 59vim.api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_lines = virt_lines }) 60]] ) 61 62exec_lua ( [[ 63vim.cmd('resize 995') 64 65start() 66vim.cmd('redraw') 67stop('redraw with virt lines at the bottom') 68]] ) 69screen : expect ( [[ 70^line1 | 71{9:VIRT_LINE} |*994 72{3:[No Name] [+] }| 73| 74{2:[No Name] }| 75| 76]] ) 77 78n . command ( 'resize 1' ) 79screen : expect ( [[ 80^line1 | 81{3:[No Name] [+] }| 82| 83{1:~ }|*994 84{2:[No Name] }| 85| 86]] ) 87 88exec_lua ( [[ 89vim.cmd('resize 995') 90 91start() 92vim.cmd('normal! j') 93stop('moving cursor down to line 2') 94 95start() 96vim.cmd('normal! j') 97stop('moving cursor down to line 3') 98 99start() 100vim.cmd('redraw') 101stop('redraw with virt lines at the top') 102]] ) 103screen : expect ( [[ 104{9:VIRT_LINE} |*993 105line2 | 106^line3 | 107{3:[No Name] [+] }| 108| 109{2:[No Name] }| 110| 111]] ) 112 113exec_lua ( [[ 114start() 115vim.cmd('normal! k') 116stop('moving cursor up to line 2') 117 118start() 119vim.cmd('normal! k') 120stop('moving cursor up to line 1') 121]] ) 122end ) 123end )