Files
neovim/test/functional/terminal/clipboard_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

67 lines
1.6 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 eq = t.eq
local retry = t.retry
local clear = n.clear
local fn = n.fn
local testprg = n.testprg
local exec_lua = n.exec_lua
local eval = n.eval
describe(':terminal', function()
before_each(function()
clear()
exec_lua([[
local function clipboard(reg, type)
if type == 'copy' then
return function(lines)
local data = table.concat(lines, '\n')
vim.g.clipboard_data = data
end
end
if type == 'paste' then
return function()
error()
end
end
error('invalid type: ' .. type)
end
vim.g.clipboard = {
name = 'Test',
copy = {
['+'] = clipboard('+', 'copy'),
['*'] = clipboard('*', 'copy'),
},
paste = {
['+'] = clipboard('+', 'paste'),
['*'] = clipboard('*', 'paste'),
},
}
]])
end)
it('can write to the system clipboard', function()
eq('Test', eval('g:clipboard.name'))
local text = 'Hello, world! This is some\nexample text\nthat spans multiple\nlines'
local encoded = exec_lua('return vim.base64.encode(...)', text)
local function osc52(arg)
return string.format('\027]52;;%s\027\\', arg)
end
fn.jobstart({ testprg('shell-test'), '-t', osc52(encoded) }, { term = true })
retry(nil, 1000, function()
eq(text, exec_lua([[ return vim.g.clipboard_data ]]))
end)
end)
end)