aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/functional/terminal/helpers.lua46
-rw-r--r--test/functional/terminal/tui_spec.lua106
-rw-r--r--test/functional/ui/screen.lua3
3 files changed, 134 insertions, 21 deletions
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index e488495139..ae13aab277 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -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
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
new file mode 100644
index 0000000000..d604703fee
--- /dev/null
+++ b/test/functional/terminal/tui_spec.lua
@@ -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)
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 08c4bfae0b..1be83d745e 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -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