Files
neovim/test/benchmark/option_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

57 lines
1.6 KiB
Lua

local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local bench = n.bench
describe('option set perf', function()
before_each(clear)
local trials = 20000
it('vim.o scalar (number)', function()
bench([[vim.o.scrolloff = i % 10]], { n = trials, label = 'vim.o.scrolloff = i % 10' })
end)
it('vim.o scalar (boolean)', function()
bench([[vim.o.wrap = (i % 2 == 0)]], { n = trials, label = 'vim.o.wrap = (i % 2 == 0)' })
end)
it('vim.o scalar (string)', function()
-- makeprg has a trivial did_set handler, so this isolates the set path itself.
bench([[vim.o.makeprg = 'make']], { n = trials, label = "vim.o.makeprg = 'make'" })
end)
it('vim.opt array via table', function()
bench([[vim.opt.wildignore = { '*.o', '*.a', '*.so' }]], {
n = trials,
label = "vim.opt.wildignore = {'*.o','*.a','*.so'}",
})
end)
it('vim.opt map via table', function()
bench([[vim.opt.listchars = { eol = '~', space = '.', tab = '> ' }]], {
n = trials,
label = "vim.opt.listchars = { eol='~', space='.', tab='> ' }",
})
end)
it('vim.opt:append (operation)', function()
bench(
[[
vim.o.wildignore = ''
vim.opt.wildignore:append({ '*.tmp', '*.bak' })
]],
{ n = trials, label = 'vim.opt.wildignore:append(...)' }
)
end)
it('nvim_set_option_value with table (direct API)', function()
bench([[vim.api.nvim_set_option_value('listchars', { eol = '~', space = '.' }, {})]], {
n = trials,
label = 'nvim_set_option_value(listchars, {..})',
})
end)
end)