mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
test: Add basic tests for the TUI
The tests use `termopen` to spawn nvim and verify the TUI.
This commit is contained in:
parent
2182cd6081
commit
5d185c7772
@ -1,7 +1,7 @@
|
||||
local helpers = require('test.functional.helpers')
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
local nvim_dir = helpers.nvim_dir
|
||||
local execute, nvim = helpers.execute, helpers.nvim
|
||||
local execute, nvim, wait = helpers.execute, helpers.nvim, helpers.wait
|
||||
|
||||
local function feed_data(data)
|
||||
nvim('set_var', 'term_data', data)
|
||||
@ -31,13 +31,15 @@ local function clear_attrs() feed_termcode('[0;10m') end
|
||||
local function enable_mouse() feed_termcode('[?1002h') end
|
||||
local function disable_mouse() feed_termcode('[?1002l') end
|
||||
|
||||
local default_command = '["'..nvim_dir..'/tty-test'..'"]'
|
||||
|
||||
|
||||
local function screen_setup(extra_height)
|
||||
local function screen_setup(extra_height, command)
|
||||
nvim('command', 'highlight TermCursor cterm=reverse')
|
||||
nvim('command', 'highlight TermCursorNC ctermbg=11')
|
||||
nvim('set_var', 'terminal_scrollback_buffer_size', 10)
|
||||
if not extra_height then extra_height = 0 end
|
||||
if not command then command = default_command end
|
||||
local screen = Screen.new(50, 7 + extra_height)
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {reverse = true}, -- focused cursor
|
||||
@ -56,25 +58,29 @@ local function screen_setup(extra_height)
|
||||
-- tty-test puts the terminal into raw mode and echoes all input. tests are
|
||||
-- done by feeding it with terminfo codes to control the display and
|
||||
-- verifying output with screen:expect.
|
||||
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||
-- wait for "tty ready" to be printed before each test or the terminal may
|
||||
-- still be in canonical mode(will echo characters for example)
|
||||
--
|
||||
local empty_line = ' '
|
||||
local expected = {
|
||||
'tty ready ',
|
||||
'{1: } ',
|
||||
empty_line,
|
||||
empty_line,
|
||||
empty_line,
|
||||
empty_line,
|
||||
}
|
||||
for i = 1, extra_height do
|
||||
table.insert(expected, empty_line)
|
||||
end
|
||||
execute('enew | call termopen('..command..') | startinsert')
|
||||
if command == default_command then
|
||||
-- wait for "tty ready" to be printed before each test or the terminal may
|
||||
-- still be in canonical mode(will echo characters for example)
|
||||
--
|
||||
local empty_line = ' '
|
||||
local expected = {
|
||||
'tty ready ',
|
||||
'{1: } ',
|
||||
empty_line,
|
||||
empty_line,
|
||||
empty_line,
|
||||
empty_line,
|
||||
}
|
||||
for i = 1, extra_height do
|
||||
table.insert(expected, empty_line)
|
||||
end
|
||||
|
||||
table.insert(expected, '-- TERMINAL -- ')
|
||||
screen:expect(table.concat(expected, '\n'))
|
||||
table.insert(expected, '-- TERMINAL -- ')
|
||||
screen:expect(table.concat(expected, '\n'))
|
||||
else
|
||||
wait()
|
||||
end
|
||||
return screen
|
||||
end
|
||||
|
||||
|
106
test/functional/terminal/tui_spec.lua
Normal file
106
test/functional/terminal/tui_spec.lua
Normal file
@ -0,0 +1,106 @@
|
||||
-- Some sanity checks for the TUI using the builtin terminal emulator
|
||||
-- as a simple way to send keys and assert screen state.
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
local helpers = require('test.functional.helpers')
|
||||
local thelpers = require('test.functional.terminal.helpers')
|
||||
local feed = thelpers.feed_data
|
||||
local execute = helpers.execute
|
||||
|
||||
describe('tui', function()
|
||||
local screen
|
||||
|
||||
before_each(function()
|
||||
helpers.clear()
|
||||
screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog..'", "-u", "NONE", "--cmd", "set noswapfile"]')
|
||||
screen.timeout = 30000 -- pasting can be really slow in the TUI
|
||||
screen:expect([[
|
||||
{1: } |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
[No Name] |
|
||||
|
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
screen:detach()
|
||||
end)
|
||||
|
||||
it('accepts basic utf-8 input', function()
|
||||
feed('iabc\ntest1\ntest2')
|
||||
screen:expect([[
|
||||
abc |
|
||||
test1 |
|
||||
test2{1: } |
|
||||
~ |
|
||||
[No Name] [+] |
|
||||
-- INSERT -- |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
feed('\x1b')
|
||||
screen:expect([[
|
||||
abc |
|
||||
test1 |
|
||||
test{1:2} |
|
||||
~ |
|
||||
[No Name] [+] |
|
||||
|
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
end)
|
||||
|
||||
it('automatically sends <Paste> for bracketed paste sequences', function()
|
||||
feed('i\x1b[200~')
|
||||
screen:expect([[
|
||||
{1: } |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
[No Name] |
|
||||
-- INSERT (paste) -- |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
feed('pasted from terminal')
|
||||
screen:expect([[
|
||||
pasted from terminal{1: } |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
[No Name] [+] |
|
||||
-- INSERT (paste) -- |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
feed('\x1b[201~')
|
||||
screen:expect([[
|
||||
pasted from terminal{1: } |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
[No Name] [+] |
|
||||
-- INSERT -- |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
end)
|
||||
|
||||
it('can handle arbitrarily long bursts of input', function()
|
||||
execute('set ruler')
|
||||
local t = {}
|
||||
for i = 1, 3000 do
|
||||
t[i] = 'item ' .. tostring(i)
|
||||
end
|
||||
feed('i\x1b[200~')
|
||||
feed(table.concat(t, '\n'))
|
||||
feed('\x1b[201~')
|
||||
screen:expect([[
|
||||
item 2997 |
|
||||
item 2998 |
|
||||
item 2999 |
|
||||
item 3000{1: } |
|
||||
[No Name] [+] 3000,10 Bot|
|
||||
-- INSERT -- |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
end)
|
||||
end)
|
@ -163,6 +163,7 @@ function Screen.new(width, height)
|
||||
height = 14
|
||||
end
|
||||
local self = setmetatable({
|
||||
timeout = default_screen_timeout,
|
||||
title = '',
|
||||
icon = '',
|
||||
bell = false,
|
||||
@ -248,7 +249,7 @@ function Screen:wait(check, timeout)
|
||||
|
||||
return true
|
||||
end
|
||||
run(nil, notification_cb, nil, timeout or default_screen_timeout)
|
||||
run(nil, notification_cb, nil, timeout or self.timeout)
|
||||
if not checked then
|
||||
err = check()
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user