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`.
54 lines
1.5 KiB
Lua
54 lines
1.5 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 pcall_err = t.pcall_err
|
|
|
|
local clear = n.clear
|
|
local exec_lua = n.exec_lua
|
|
|
|
describe("'winfixbuf'", function()
|
|
before_each(function()
|
|
clear()
|
|
end)
|
|
|
|
---@return integer
|
|
local function setup_winfixbuf()
|
|
return exec_lua([[
|
|
local buffer = vim.api.nvim_create_buf(true, true)
|
|
vim.api.nvim_create_buf(true, true) -- Make another buffer
|
|
vim.wo.winfixbuf = true
|
|
return buffer
|
|
]])
|
|
end
|
|
|
|
it('nvim_win_set_buf on non-current buffer', function()
|
|
local other_buf = setup_winfixbuf()
|
|
t.eq(
|
|
"Vim:E1513: Cannot switch buffer. 'winfixbuf' is enabled",
|
|
t.pcall_err(n.api.nvim_win_set_buf, 0, other_buf)
|
|
)
|
|
end)
|
|
|
|
it('nvim_set_current_buf on non-current buffer', function()
|
|
local other_buf = setup_winfixbuf()
|
|
t.eq(
|
|
"Vim:E1513: Cannot switch buffer. 'winfixbuf' is enabled",
|
|
t.pcall_err(n.api.nvim_set_current_buf, other_buf)
|
|
)
|
|
end)
|
|
|
|
it('nvim_win_set_buf on current buffer', function()
|
|
setup_winfixbuf()
|
|
local curbuf = n.api.nvim_get_current_buf()
|
|
n.api.nvim_win_set_buf(0, curbuf)
|
|
t.eq(curbuf, n.api.nvim_get_current_buf())
|
|
end)
|
|
|
|
it('nvim_set_current_buf on current buffer', function()
|
|
setup_winfixbuf()
|
|
local curbuf = n.api.nvim_get_current_buf()
|
|
n.api.nvim_set_current_buf(curbuf)
|
|
t.eq(curbuf, n.api.nvim_get_current_buf())
|
|
end)
|
|
end)
|