aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/buffer_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
commit339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch)
treea6167fc8fcfc6ae2dc102f57b2473858eac34063 /test/functional/terminal/buffer_spec.lua
parent067dc73729267c0262438a6fdd66e586f8496946 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'test/functional/terminal/buffer_spec.lua')
-rw-r--r--test/functional/terminal/buffer_spec.lua158
1 files changed, 143 insertions, 15 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 9c8b983ff7..6fcd029a5b 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -17,14 +17,14 @@ local sleep = helpers.sleep
local funcs = helpers.funcs
local is_os = helpers.is_os
local skip = helpers.skip
+local nvim_prog = helpers.nvim_prog
describe(':terminal buffer', function()
local screen
before_each(function()
clear()
- feed_command('set modifiable swapfile undolevels=20')
- poke_eventloop()
+ command('set modifiable swapfile undolevels=20')
screen = thelpers.screen_setup()
end)
@@ -197,12 +197,11 @@ describe(':terminal buffer', function()
it('handles loss of focus gracefully', function()
-- Change the statusline to avoid printing the file name, which varies.
- nvim('set_option', 'statusline', '==========')
- feed_command('set laststatus=0')
+ nvim('set_option_value', 'statusline', '==========', {})
-- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")')
- local exitcmd = helpers.is_os('win')
+ local exitcmd = is_os('win')
and "['cmd', '/c', 'exit']"
or "['sh', '-c', 'exit']"
source([[
@@ -231,8 +230,6 @@ describe(':terminal buffer', function()
neq(tbuf, eval('bufnr("%")'))
feed_command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")'))
-
- feed_command('set laststatus=1') -- Restore laststatus to the default.
end)
it('term_close() use-after-free #4393', function()
@@ -281,6 +278,7 @@ describe(':terminal buffer', function()
end)
it('requires bang (!) to close a running job #15402', function()
+ skip(is_os('win'), "Test freezes the CI and makes it time out")
eq('Vim(wqall):E948: Job still running', exc_exec('wqall'))
for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do
matches('^Vim%('..cmd:gsub('%%', '')..'%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$',
@@ -412,14 +410,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function()
feed_command('bdelete!')
eq('', exec_lua([[return _G.cb_error]]))
end)
-
- it('runs TextChangedT event', function()
- meths.set_var('called', 0)
- command('autocmd TextChangedT * ++once let g:called = 1')
- feed_command('terminal')
- feed('iaa')
- eq(1, meths.get_var('called'))
- end)
end)
it('terminal truncates number of composing characters to 5', function()
@@ -429,3 +419,141 @@ it('terminal truncates number of composing characters to 5', function()
meths.chan_send(chan, 'a' .. composing:rep(8))
retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end)
end)
+
+describe('terminal input', function()
+ before_each(function()
+ clear()
+ exec_lua([[
+ _G.input_data = ''
+ vim.api.nvim_open_term(0, { on_input = function(_, _, _, data)
+ _G.input_data = _G.input_data .. data
+ end })
+ ]])
+ feed('i')
+ poke_eventloop()
+ end)
+
+ it('<C-Space> is sent as NUL byte', function()
+ feed('aaa<C-Space>bbb')
+ eq('aaa\0bbb', exec_lua([[return _G.input_data]]))
+ end)
+
+ it('unknown special keys are not sent', function()
+ feed('aaa<Help>bbb')
+ eq('aaabbb', exec_lua([[return _G.input_data]]))
+ end)
+end)
+
+describe('terminal input', function()
+ it('sends various special keys with modifiers', function()
+ clear()
+ local screen = thelpers.screen_setup(0,
+ string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--cmd", "startinsert"]]=], nvim_prog))
+ screen:expect{grid=[[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,1 All}|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
+ ]]}
+ for _, key in ipairs({
+ '<M-Tab>', '<M-CR>', '<M-Esc>',
+ '<BS>', '<S-Tab>', '<Insert>', '<Del>', '<PageUp>', '<PageDown>',
+ '<S-Up>', '<C-Up>', '<Up>', '<S-Down>', '<C-Down>', '<Down>',
+ '<S-Left>', '<C-Left>', '<Left>', '<S-Right>', '<C-Right>', '<Right>',
+ '<S-Home>', '<C-Home>', '<Home>', '<S-End>', '<C-End>', '<End>',
+ '<C-LeftMouse>', '<C-LeftRelease>', '<2-LeftMouse>', '<2-LeftRelease>',
+ '<S-RightMouse>', '<S-RightRelease>', '<2-RightMouse>', '<2-RightRelease>',
+ '<M-MiddleMouse>', '<M-MiddleRelease>', '<2-MiddleMouse>', '<2-MiddleRelease>',
+ '<S-ScrollWheelUp>', '<S-ScrollWheelDown>', '<ScrollWheelUp>', '<ScrollWheelDown>',
+ '<S-ScrollWheelLeft>', '<S-ScrollWheelRight>', '<ScrollWheelLeft>', '<ScrollWheelRight>',
+ }) do
+ feed('<CR><C-V>' .. key)
+ retry(nil, nil, function() eq(key, meths.get_current_line()) end)
+ end
+ end)
+end)
+
+if is_os('win') then
+ describe(':terminal in Windows', function()
+ local screen
+
+ before_each(function()
+ clear()
+ feed_command('set modifiable swapfile undolevels=20')
+ poke_eventloop()
+ local cmd = '["cmd.exe","/K","PROMPT=$g$s"]'
+ screen = thelpers.screen_setup(nil, cmd)
+ end)
+
+ it('"put" operator sends data normally', function()
+ feed('<c-\\><c-n>G')
+ feed_command('let @a = ":: tty ready"')
+ feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"')
+ feed('"ap"ap')
+ screen:expect([[
+ |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ ^> {2: } |
+ :let @a = @a . "\n:: appended " . @a . "\n\n" |
+ ]])
+ -- operator count is also taken into consideration
+ feed('3"ap')
+ screen:expect([[
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ ^> {2: } |
+ :let @a = @a . "\n:: appended " . @a . "\n\n" |
+ ]])
+ end)
+
+ it('":put" command sends data normally', function()
+ feed('<c-\\><c-n>G')
+ feed_command('let @a = ":: tty ready"')
+ feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"')
+ feed_command('put a')
+ screen:expect([[
+ |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > {2: } |
+ |
+ ^ |
+ :put a |
+ ]])
+ -- line argument is only used to move the cursor
+ feed_command('6put a')
+ screen:expect([[
+ |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ ^> {2: } |
+ :6put a |
+ ]])
+ end)
+ end)
+end
+
+describe('termopen()', function()
+ before_each(clear)
+
+ it('disallowed when textlocked and in cmdwin buffer', function()
+ command("autocmd TextYankPost <buffer> ++once call termopen('foo')")
+ matches("Vim%(call%):E565: Not allowed to change text or change window$",
+ pcall_err(command, "normal! yy"))
+
+ feed("q:")
+ eq("Vim:E11: Invalid in command-line window; <CR> executes, CTRL-C quits",
+ pcall_err(funcs.termopen, "bar"))
+ end)
+end)