Files
neovim/test/functional/vimscript/getchar_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

98 lines
3.2 KiB
Lua

local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local exec = n.exec
local feed = n.feed
local async_command = n.async_meths.nvim_command
local poke_eventloop = n.poke_eventloop
describe('getchar()', function()
before_each(clear)
-- oldtest: Test_getchar_cursor_position()
it('cursor positioning', function()
local screen = Screen.new(40, 6)
exec([[
call setline(1, ['foobar', 'foobar', 'foobar'])
call cursor(3, 6)
]])
screen:expect([[
foobar |*2
fooba^r |
{1:~ }|*2
|
]])
-- Default: behaves like "msg" when immediately after printing a message,
-- even if :sleep moved cursor elsewhere.
for _, cmd in ipairs({
'echo 1234 | call getchar()',
'echo 1234 | call getchar(-1, {})',
"echo 1234 | call getchar(-1, #{cursor: 'msg'})",
'echo 1234 | sleep 1m | call getchar()',
'echo 1234 | sleep 1m | call getchar(-1, {})',
"echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'msg'})",
}) do
async_command(cmd)
screen:expect([[
foobar |*3
{1:~ }|*2
1234^ |
]])
feed('a')
screen:expect([[
foobar |*2
fooba^r |
{1:~ }|*2
1234 |
]])
end
-- Default: behaves like "keep" when not immediately after printing a message.
for _, cmd in ipairs({
'call getchar()',
'call getchar(-1, {})',
"call getchar(-1, #{cursor: 'keep'})",
"echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'keep'})",
}) do
async_command(cmd)
poke_eventloop()
screen:expect_unchanged()
feed('a')
poke_eventloop()
screen:expect_unchanged()
end
async_command("call getchar(-1, #{cursor: 'msg'})")
screen:expect([[
foobar |*3
{1:~ }|*2
^1234 |
]])
feed('a')
screen:expect([[
foobar |*2
fooba^r |
{1:~ }|*2
1234 |
]])
async_command("call getchar(-1, #{cursor: 'hide'})")
screen:expect([[
foobar |*3
{1:~ }|*2
1234 |
]])
feed('a')
screen:expect([[
foobar |*2
fooba^r |
{1:~ }|*2
1234 |
]])
end)
end)