Files
neovim/test/functional/options/winfixbuf_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

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)