diff --git a/test/benchmark/decor_spec.lua b/test/benchmark/decor_spec.lua index 2e04d44686..b4ce4b55c2 100644 --- a/test/benchmark/decor_spec.lua +++ b/test/benchmark/decor_spec.lua @@ -8,7 +8,7 @@ describe('decor perf', function() it('can handle long lines', function() Screen.new(100, 101) - local result = exec_lua [==[ + local result = exec_lua(function() local ephemeral_pattern = { { 0, 4, 'Comment', 11 }, { 0, 3, 'Keyword', 12 }, @@ -61,7 +61,7 @@ describe('decor perf', function() return true end, on_line = function() - add_pattern(ephemeral_pattern, true) + add_pattern(ephemeral_pattern, true) end, }) @@ -69,16 +69,16 @@ describe('decor perf', function() local total = {} local provider = {} - for i = 1, 100 do + for _ = 1, 100 do local tic = vim.uv.hrtime() - vim.cmd'redraw!' + vim.cmd 'redraw!' local toc = vim.uv.hrtime() table.insert(total, toc - tic) table.insert(provider, pe - ps) end return { total, provider } - ]==] + end) local total, provider = unpack(result) table.sort(total) @@ -102,22 +102,22 @@ describe('decor perf', function() it('can handle long lines with treesitter highlighting', function() Screen.new(100, 51) - local result = exec_lua [==[ + local result = exec_lua(function() local long_line = 'local a = { ' .. ('a = 5, '):rep(2000) .. '}' vim.api.nvim_buf_set_lines(0, 0, 0, false, { long_line }) vim.api.nvim_win_set_cursor(0, { 1, 0 }) vim.treesitter.start(0, 'lua') local total = {} - for i = 1, 50 do + for _ = 1, 50 do local tic = vim.uv.hrtime() - vim.cmd'redraw!' + vim.cmd 'redraw!' local toc = vim.uv.hrtime() table.insert(total, toc - tic) end return { total } - ]==] + end) local total = unpack(result) table.sort(total) diff --git a/test/benchmark/treesitter_spec.lua b/test/benchmark/treesitter_spec.lua index f83aa51eb0..222a2ae8fb 100644 --- a/test/benchmark/treesitter_spec.lua +++ b/test/benchmark/treesitter_spec.lua @@ -49,33 +49,28 @@ describe('treesitter perf', function() ]] end) - local function test_long_line(pos, wrap, line, grid) + local function test_long_line(_pos, _wrap, _line, grid) local screen = Screen.new(20, 11) - local result = exec_lua( - [==[ - local pos, wrap, line = ... + local result = exec_lua(function(...) + local pos, wrap, line = ... - vim.api.nvim_buf_set_lines(0, 0, 0, false, { line }) - vim.api.nvim_win_set_cursor(0, pos) - vim.api.nvim_set_option_value('wrap', wrap, { win = 0 }) + vim.api.nvim_buf_set_lines(0, 0, 0, false, { line }) + vim.api.nvim_win_set_cursor(0, pos) + vim.api.nvim_set_option_value('wrap', wrap, { win = 0 }) - vim.treesitter.start(0, 'lua') + vim.treesitter.start(0, 'lua') - local total = {} - for i = 1, 100 do - local tic = vim.uv.hrtime() - vim.cmd'redraw!' - local toc = vim.uv.hrtime() - table.insert(total, toc - tic) - end + local total = {} + for _ = 1, 100 do + local tic = vim.uv.hrtime() + vim.cmd 'redraw!' + local toc = vim.uv.hrtime() + table.insert(total, toc - tic) + end - return { total } - ]==], - pos, - wrap, - line - ) + return { total } + end, _pos, _wrap, _line) screen:expect({ grid = grid or '' }) diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 1e702b1954..a839de9d70 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -716,46 +716,44 @@ describe('decorations providers', function() setup_screen(screen) local function record() - exec_lua [[ - p_min = { math.huge, math.huge } - p_max = { -math.huge, -math.huge } - function pos_gt(a, b) + exec_lua(function() + _G.p_min = { math.huge, math.huge } + _G.p_max = { -math.huge, -math.huge } + function _G.pos_gt(a, b) return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2]) end - function pos_lt(a, b) + function _G.pos_lt(a, b) return a[1] < b[1] or (a[1] == b[1] and a[2] < b[2]) end - ]] + end) setup_provider [[ local function on_do(kind, _, bufnr, br, bc, er, ec) if kind == 'range' then local b = { br, bc } local e = { er, ec } - if pos_gt(p_min, b) then - p_min = b + if _G.pos_gt(_G.p_min, b) then + _G.p_min = b end - if pos_lt(p_max, e) then - p_max = e + if _G.pos_lt(_G.p_max, e) then + _G.p_max = e end end end ]] end local function check(min, max) - local function pos_gt(a, b) - return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2]) - end - local function pos_lt(a, b) - return a[1] < b[1] or (a[1] == b[1] and a[2] < b[2]) - end - local p_min = exec_lua('return p_min') - assert(not pos_gt(p_min, min), + local p_min = exec_lua('return _G.p_min') + assert( + p_min[1] < min[1] or (p_min[1] == min[1] and p_min[2] <= min[2]), "minimum position " .. vim.inspect(p_min) - .. " should be before the first char") - local p_max = exec_lua('return p_max') - assert(not pos_lt(p_max, max), + .. " should be before the first char" + ) + local p_max = exec_lua('return _G.p_max') + assert( + p_max[1] > max[1] or (p_max[1] == max[1] and p_max[2] >= max[2]), "maximum position " .. vim.inspect(p_max) - .. " should be on or after the last char") + .. " should be on or after the last char" + ) end -- Multiple lines.