mirror of
https://github.com/neovim/neovim.git
synced 2026-08-03 06:09:14 +00:00
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`.
61 lines
1.3 KiB
Lua
61 lines
1.3 KiB
Lua
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
local describe, it, before_each = t.describe, t.it, t.before_each
|
|
local clear = n.clear
|
|
local eq = t.eq
|
|
local exec = n.exec
|
|
local feed = n.feed
|
|
local api = n.api
|
|
|
|
before_each(clear)
|
|
|
|
describe('SafeState autocommand', function()
|
|
local function create_autocmd()
|
|
exec([[
|
|
let g:safe = 0
|
|
autocmd SafeState * ++once let g:safe += 1
|
|
]])
|
|
end
|
|
|
|
it('with pending operator', function()
|
|
feed('d')
|
|
create_autocmd()
|
|
eq(0, api.nvim_get_var('safe'))
|
|
feed('d')
|
|
eq(1, api.nvim_get_var('safe'))
|
|
end)
|
|
|
|
it('with specified register', function()
|
|
feed('"r')
|
|
create_autocmd()
|
|
eq(0, api.nvim_get_var('safe'))
|
|
feed('x')
|
|
eq(1, api.nvim_get_var('safe'))
|
|
end)
|
|
|
|
it('with i_CTRL-O', function()
|
|
feed('i<C-O>')
|
|
create_autocmd()
|
|
eq(0, api.nvim_get_var('safe'))
|
|
feed('x')
|
|
eq(1, api.nvim_get_var('safe'))
|
|
end)
|
|
|
|
it('with Insert mode completion', function()
|
|
feed('i<C-X><C-V>')
|
|
create_autocmd()
|
|
eq(0, api.nvim_get_var('safe'))
|
|
feed('<C-X><C-Z>')
|
|
eq(1, api.nvim_get_var('safe'))
|
|
end)
|
|
|
|
it('with Cmdline completion', function()
|
|
feed(':<Tab>')
|
|
create_autocmd()
|
|
eq(0, api.nvim_get_var('safe'))
|
|
feed('<C-E>')
|
|
eq(1, api.nvim_get_var('safe'))
|
|
end)
|
|
end)
|