mirror of
https://github.com/neovim/neovim.git
synced 2026-07-31 12:49:11 +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`.
132 lines
4.1 KiB
Lua
132 lines
4.1 KiB
Lua
-- shada buffer list saving/reading support
|
|
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
local t_shada = require('test.functional.shada.testutil')
|
|
|
|
local describe, it, after_each = t.describe, t.it, t.after_each
|
|
local nvim_command, fn, eq, api = n.command, n.fn, t.eq, n.api
|
|
local expect_exit = n.expect_exit
|
|
|
|
local reset, clear = t_shada.reset, t_shada.clear
|
|
|
|
describe('shada support code', function()
|
|
local testfilename = 'Xtestfile-functional-shada-buffers'
|
|
local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
|
|
after_each(clear)
|
|
|
|
it('is able to dump and restore buffer list', function()
|
|
reset('set shada+=%')
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
expect_exit(nvim_command, 'qall')
|
|
reset('set shada+=%')
|
|
eq(3, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
eq(testfilename, fn.bufname(2))
|
|
eq(testfilename_2, fn.bufname(3))
|
|
end)
|
|
|
|
it('does not restore buffer list without % in &shada', function()
|
|
reset('set shada+=%')
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
expect_exit(nvim_command, 'qall')
|
|
reset()
|
|
eq(1, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
end)
|
|
|
|
it('does not dump buffer list without % in &shada', function()
|
|
reset()
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
expect_exit(nvim_command, 'qall')
|
|
reset('set shada+=%')
|
|
eq(1, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
end)
|
|
|
|
it('does not dump unlisted buffer', function()
|
|
reset('set shada+=%')
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
api.nvim_set_option_value('buflisted', false, {})
|
|
expect_exit(nvim_command, 'qall')
|
|
reset('set shada+=%')
|
|
eq(2, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
eq(testfilename, fn.bufname(2))
|
|
end)
|
|
|
|
it('does not dump quickfix buffer', function()
|
|
reset('set shada+=%')
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
api.nvim_set_option_value('buftype', 'quickfix', {})
|
|
expect_exit(nvim_command, 'qall')
|
|
reset('set shada+=%')
|
|
eq(2, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
eq(testfilename, fn.bufname(2))
|
|
end)
|
|
|
|
it('does not dump unnamed buffers', function()
|
|
reset('set shada+=% hidden')
|
|
api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
|
|
nvim_command('enew')
|
|
api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
|
|
eq(2, fn.bufnr('$'))
|
|
expect_exit(nvim_command, 'qall!')
|
|
reset('set shada+=% hidden')
|
|
eq(1, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
end)
|
|
|
|
it('restores 1 buffer with %1 in &shada, #5759', function()
|
|
reset('set shada+=%1')
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
expect_exit(nvim_command, 'qall')
|
|
reset('set shada+=%1')
|
|
eq(2, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
eq(testfilename, fn.bufname(2))
|
|
end)
|
|
|
|
it("does not add 'nobuflisted' buffers to v:oldfiles", function()
|
|
reset("set shada='100")
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('setlocal nobuflisted')
|
|
nvim_command('edit ' .. testfilename_2)
|
|
nvim_command('setlocal buflisted')
|
|
expect_exit(nvim_command, 'qall')
|
|
reset("set shada='100")
|
|
local oldfiles = api.nvim_get_vvar('oldfiles')
|
|
eq(1, #oldfiles)
|
|
t.matches(vim.pesc(testfilename_2), oldfiles[1])
|
|
end)
|
|
|
|
it("saves bdelete'd buffer to v:oldfiles #39010", function()
|
|
reset("set shada='100")
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('bdelete')
|
|
nvim_command('edit ' .. testfilename_2)
|
|
expect_exit(nvim_command, 'qall')
|
|
reset("set shada='100")
|
|
local oldfiles = api.nvim_get_vvar('oldfiles')
|
|
eq(2, #oldfiles)
|
|
end)
|
|
|
|
it("does not dump bdelete'd buffer to buffer list", function()
|
|
reset('set shada+=%')
|
|
nvim_command('edit ' .. testfilename)
|
|
nvim_command('edit ' .. testfilename_2)
|
|
nvim_command('bdelete ' .. testfilename)
|
|
expect_exit(nvim_command, 'qall')
|
|
reset('set shada+=%')
|
|
eq(2, fn.bufnr('$'))
|
|
eq('', fn.bufname(1))
|
|
eq(testfilename_2, fn.bufname(2))
|
|
end)
|
|
end)
|