2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-03-25 05:14:47 -07:00
|
|
|
local thelpers = require('test.functional.terminal.helpers')
|
2021-09-01 09:42:53 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
2015-03-25 05:14:47 -07:00
|
|
|
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
|
2020-10-19 11:17:51 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
2017-04-08 14:12:26 -07:00
|
|
|
local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
|
2022-09-22 16:21:51 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
2015-04-03 15:44:26 -07:00
|
|
|
local eq, neq = helpers.eq, helpers.neq
|
2022-07-30 06:40:30 -07:00
|
|
|
local meths = helpers.meths
|
|
|
|
local retry = helpers.retry
|
2017-03-04 12:12:57 -07:00
|
|
|
local write_file = helpers.write_file
|
2021-12-07 17:41:46 -07:00
|
|
|
local command = helpers.command
|
2020-03-10 17:59:13 -07:00
|
|
|
local exc_exec = helpers.exc_exec
|
2021-08-16 20:06:49 -07:00
|
|
|
local matches = helpers.matches
|
2021-12-07 17:41:46 -07:00
|
|
|
local exec_lua = helpers.exec_lua
|
|
|
|
local sleep = helpers.sleep
|
2022-07-30 13:07:58 -07:00
|
|
|
local funcs = helpers.funcs
|
2022-11-21 17:13:30 -07:00
|
|
|
local is_os = helpers.is_os
|
2022-11-13 06:52:19 -07:00
|
|
|
local skip = helpers.skip
|
2015-03-25 05:14:47 -07:00
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
describe(':terminal buffer', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('set modifiable swapfile undolevels=20')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2015-03-25 05:14:47 -07:00
|
|
|
screen = thelpers.screen_setup()
|
|
|
|
end)
|
|
|
|
|
2020-05-04 21:04:47 -07:00
|
|
|
it('terminal-mode forces various options', function()
|
|
|
|
feed([[<C-\><C-N>]])
|
2021-10-06 15:31:14 -07:00
|
|
|
command('setlocal cursorline cursorlineopt=both cursorcolumn scrolloff=4 sidescrolloff=7')
|
|
|
|
eq({ 'both', 1, 1, 4, 7 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('nt', eval('mode(1)'))
|
2020-05-04 21:04:47 -07:00
|
|
|
|
|
|
|
-- Enter terminal-mode ("insert" mode in :terminal).
|
|
|
|
feed('i')
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('t', eval('mode(1)'))
|
2021-10-06 15:31:14 -07:00
|
|
|
eq({ 'number', 1, 0, 0, 0 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('terminal-mode does not change cursorlineopt if cursorline is disabled', function()
|
|
|
|
feed([[<C-\><C-N>]])
|
|
|
|
command('setlocal nocursorline cursorlineopt=both')
|
|
|
|
feed('i')
|
|
|
|
eq({ 0, 'both' }, eval('[&l:cursorline, &l:cursorlineopt]'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('terminal-mode disables cursorline when cursorlineopt is only set to "line', function()
|
|
|
|
feed([[<C-\><C-N>]])
|
|
|
|
command('setlocal cursorline cursorlineopt=line')
|
|
|
|
feed('i')
|
|
|
|
eq({ 0, 'line' }, eval('[&l:cursorline, &l:cursorlineopt]'))
|
2020-05-04 21:04:47 -07:00
|
|
|
end)
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
describe('when a new file is edited', function()
|
|
|
|
before_each(function()
|
|
|
|
feed('<c-\\><c-n>:set bufhidden=wipe<cr>:enew<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
:enew |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will hide the buffer, ignoring the bufhidden option', function()
|
|
|
|
feed(':bnext:l<esc>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('swap and undo', function()
|
|
|
|
before_each(function()
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2017-02-26 19:10:55 -07:00
|
|
|
{2:^ } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not create swap files', function()
|
2019-12-01 23:43:16 -07:00
|
|
|
local swapfile = nvim('exec', 'swapname', true):gsub('\n', '')
|
2015-03-25 05:14:47 -07:00
|
|
|
eq(nil, io.open(swapfile))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not create undofiles files', function()
|
|
|
|
local undofile = nvim('eval', 'undofile(bufname("%"))')
|
|
|
|
eq(nil, io.open(undofile))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('cannot be modified directly', function()
|
|
|
|
feed('<c-\\><c-n>dd')
|
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2017-02-26 19:10:55 -07:00
|
|
|
{2:^ } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{8:E21: Cannot make changes, 'modifiable' is off} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('sends data to the terminal when the "put" operator is used', function()
|
|
|
|
feed('<c-\\><c-n>gg"ayj')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('let @a = "appended " . @a')
|
2015-03-25 05:14:47 -07:00
|
|
|
feed('"ap"ap')
|
|
|
|
screen:expect([[
|
|
|
|
^tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:let @a = "appended " . @a |
|
|
|
|
]])
|
|
|
|
-- operator count is also taken into consideration
|
|
|
|
feed('3"ap')
|
|
|
|
screen:expect([[
|
|
|
|
^tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
:let @a = "appended " . @a |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('sends data to the terminal when the ":put" command is used', function()
|
|
|
|
feed('<c-\\><c-n>gg"ayj')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('let @a = "appended " . @a')
|
|
|
|
feed_command('put a')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
^tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:put a |
|
|
|
|
]])
|
|
|
|
-- line argument is only used to move the cursor
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('6put a')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
^ |
|
|
|
|
:6put a |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('can be deleted', function()
|
|
|
|
feed('<c-\\><c-n>:bd!<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
:bd! |
|
|
|
|
]])
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('bnext')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
:bnext |
|
|
|
|
]])
|
|
|
|
end)
|
2015-04-03 15:44:26 -07:00
|
|
|
|
|
|
|
it('handles loss of focus gracefully', function()
|
2016-05-14 19:56:11 -07:00
|
|
|
-- Change the statusline to avoid printing the file name, which varies.
|
2022-12-19 09:37:45 -07:00
|
|
|
nvim('set_option_value', 'statusline', '==========', {})
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('set laststatus=0')
|
2015-04-03 15:44:26 -07:00
|
|
|
|
|
|
|
-- Save the buffer number of the terminal for later testing.
|
|
|
|
local tbuf = eval('bufnr("%")')
|
2023-03-16 17:12:33 -07:00
|
|
|
local exitcmd = is_os('win')
|
2019-08-11 05:28:19 -07:00
|
|
|
and "['cmd', '/c', 'exit']"
|
|
|
|
or "['sh', '-c', 'exit']"
|
2015-04-03 15:44:26 -07:00
|
|
|
source([[
|
2016-11-11 13:13:55 -07:00
|
|
|
function! SplitWindow(id, data, event)
|
2015-04-03 15:44:26 -07:00
|
|
|
new
|
2015-04-05 10:20:08 -07:00
|
|
|
call feedkeys("iabc\<Esc>")
|
2015-04-03 15:44:26 -07:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
startinsert
|
2019-08-11 05:28:19 -07:00
|
|
|
call jobstart(]]..exitcmd..[[, {'on_exit': function("SplitWindow")})
|
2015-04-05 10:20:08 -07:00
|
|
|
call feedkeys("\<C-\>", 't') " vim will expect <C-n>, but be exited out of
|
|
|
|
" the terminal before it can be entered.
|
2015-04-03 15:44:26 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
-- We should be in a new buffer now.
|
|
|
|
screen:expect([[
|
2015-04-05 10:20:08 -07:00
|
|
|
ab^c |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{5:========== }|
|
2015-04-03 15:44:26 -07:00
|
|
|
rows: 2, cols: 50 |
|
|
|
|
{2: } |
|
|
|
|
{1:========== }|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
neq(tbuf, eval('bufnr("%")'))
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('quit!') -- Should exit the new window, not the terminal.
|
2015-04-03 15:44:26 -07:00
|
|
|
eq(tbuf, eval('bufnr("%")'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('set laststatus=1') -- Restore laststatus to the default.
|
2015-04-03 15:44:26 -07:00
|
|
|
end)
|
2016-05-14 19:56:11 -07:00
|
|
|
|
|
|
|
it('term_close() use-after-free #4393', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('terminal yes')
|
2016-05-14 19:56:11 -07:00
|
|
|
feed([[<C-\><C-n>]])
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('bdelete!')
|
2016-05-14 19:56:11 -07:00
|
|
|
end)
|
2018-07-12 05:57:20 -07:00
|
|
|
|
|
|
|
describe('handles confirmations', function()
|
|
|
|
it('with :confirm', function()
|
|
|
|
feed_command('terminal')
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
feed_command('confirm bdelete')
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{any='Close "term://'}
|
2018-07-12 05:57:20 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with &confirm', function()
|
|
|
|
feed_command('terminal')
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
feed_command('bdelete')
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{any='E89'}
|
2018-07-12 05:57:20 -07:00
|
|
|
feed('<cr>')
|
|
|
|
eq('terminal', eval('&buftype'))
|
|
|
|
feed_command('set confirm | bdelete')
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{any='Close "term://'}
|
2018-07-12 05:57:20 -07:00
|
|
|
feed('y')
|
|
|
|
neq('terminal', eval('&buftype'))
|
|
|
|
end)
|
|
|
|
end)
|
2019-11-28 21:09:03 -07:00
|
|
|
|
|
|
|
it('it works with set rightleft #11438', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2019-11-28 21:09:03 -07:00
|
|
|
local columns = eval('&columns')
|
|
|
|
feed(string.rep('a', columns))
|
|
|
|
command('set rightleft')
|
|
|
|
screen:expect([[
|
|
|
|
ydaer ytt|
|
|
|
|
{1:a}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
command('bdelete!')
|
|
|
|
end)
|
2020-03-10 17:59:13 -07:00
|
|
|
|
2021-08-28 08:58:27 -07:00
|
|
|
it('requires bang (!) to close a running job #15402', function()
|
2023-05-14 05:29:18 -07:00
|
|
|
skip(is_os('win'), "Test freezes the CI and makes it time out")
|
2020-03-10 17:59:13 -07:00
|
|
|
eq('Vim(wqall):E948: Job still running', exc_exec('wqall'))
|
2021-08-28 08:58:27 -07:00
|
|
|
for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do
|
|
|
|
matches('^Vim%('..cmd:gsub('%%', '')..'%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$',
|
|
|
|
exc_exec(cmd))
|
|
|
|
end
|
2021-08-16 20:06:49 -07:00
|
|
|
command('call jobstop(&channel)')
|
2021-08-28 08:58:27 -07:00
|
|
|
assert(0 >= eval('jobwait([&channel], 1000)[0]'))
|
2021-08-16 20:06:49 -07:00
|
|
|
command('bdelete')
|
2020-03-10 17:59:13 -07:00
|
|
|
end)
|
2021-02-26 18:55:32 -07:00
|
|
|
|
2021-08-28 08:58:27 -07:00
|
|
|
it('stops running jobs with :quit', function()
|
|
|
|
-- Open in a new window to avoid terminating the nvim instance
|
|
|
|
command('split')
|
|
|
|
command('terminal')
|
|
|
|
command('set nohidden')
|
|
|
|
command('quit')
|
|
|
|
end)
|
|
|
|
|
2022-01-08 08:29:32 -07:00
|
|
|
it('does not segfault when pasting empty register #13955', function()
|
2021-02-26 18:55:32 -07:00
|
|
|
feed('<c-\\><c-n>')
|
2022-01-08 08:29:32 -07:00
|
|
|
feed_command('put a') -- register a is empty
|
2021-02-27 08:38:38 -07:00
|
|
|
helpers.assert_alive()
|
2021-02-26 18:55:32 -07:00
|
|
|
end)
|
2022-07-30 13:07:58 -07:00
|
|
|
|
|
|
|
it([[can use temporary normal mode <c-\><c-o>]], function()
|
|
|
|
eq('t', funcs.mode(1))
|
|
|
|
feed [[<c-\><c-o>]]
|
|
|
|
screen:expect{grid=[[
|
|
|
|
tty ready |
|
|
|
|
{2:^ } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{3:-- (terminal) --} |
|
|
|
|
]]}
|
|
|
|
eq('ntT', funcs.mode(1))
|
|
|
|
|
|
|
|
feed [[:let g:x = 17]]
|
|
|
|
screen:expect{grid=[[
|
|
|
|
tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:let g:x = 17^ |
|
|
|
|
]]}
|
|
|
|
|
|
|
|
feed [[<cr>]]
|
|
|
|
screen:expect{grid=[[
|
|
|
|
tty ready |
|
|
|
|
{1: } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]]}
|
|
|
|
eq('t', funcs.mode(1))
|
|
|
|
end)
|
2022-09-22 16:21:51 -07:00
|
|
|
|
|
|
|
it('writing to an existing file with :w fails #13549', function()
|
|
|
|
eq('Vim(write):E13: File exists (add ! to override)',
|
|
|
|
pcall_err(command, 'write test/functional/fixtures/tty-test.c'))
|
|
|
|
end)
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 12:12:57 -07:00
|
|
|
describe('No heap-buffer-overflow when using', function()
|
|
|
|
local testfilename = 'Xtestfile-functional-terminal-buffers_spec'
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
write_file(testfilename, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
os.remove(testfilename)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('termopen(echo) #3161', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('edit ' .. testfilename)
|
2017-03-04 12:12:57 -07:00
|
|
|
-- Move cursor away from the beginning of the line
|
|
|
|
feed('$')
|
|
|
|
-- Let termopen() modify the buffer
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('call termopen("echo")')
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('bdelete!')
|
2017-03-04 12:12:57 -07:00
|
|
|
end)
|
|
|
|
end)
|
2020-07-27 08:51:41 -07:00
|
|
|
|
|
|
|
describe('No heap-buffer-overflow when', function()
|
|
|
|
it('set nowrap and send long line #11548', function()
|
|
|
|
feed_command('set nowrap')
|
|
|
|
feed_command('autocmd TermOpen * startinsert')
|
|
|
|
feed_command('call feedkeys("4000ai\\<esc>:terminal!\\<cr>")')
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2020-07-27 08:51:41 -07:00
|
|
|
end)
|
|
|
|
end)
|
2021-12-07 17:41:46 -07:00
|
|
|
|
|
|
|
describe('on_lines does not emit out-of-bounds line indexes when', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
exec_lua([[
|
|
|
|
function _G.register_callback(bufnr)
|
|
|
|
_G.cb_error = ''
|
|
|
|
vim.api.nvim_buf_attach(bufnr, false, {
|
|
|
|
on_lines = function(_, bufnr, _, firstline, _, _)
|
|
|
|
local status, msg = pcall(vim.api.nvim_buf_get_offset, bufnr, firstline)
|
|
|
|
if not status then
|
|
|
|
_G.cb_error = msg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('creating a terminal buffer #16394', function()
|
2022-01-01 07:28:52 -07:00
|
|
|
feed_command('autocmd TermOpen * ++once call v:lua.register_callback(str2nr(expand("<abuf>")))')
|
2021-12-07 17:41:46 -07:00
|
|
|
feed_command('terminal')
|
|
|
|
sleep(500)
|
|
|
|
eq('', exec_lua([[return _G.cb_error]]))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('deleting a terminal buffer #16394', function()
|
|
|
|
feed_command('terminal')
|
|
|
|
sleep(500)
|
|
|
|
feed_command('lua _G.register_callback(0)')
|
|
|
|
feed_command('bdelete!')
|
|
|
|
eq('', exec_lua([[return _G.cb_error]]))
|
|
|
|
end)
|
2022-11-06 20:02:29 -07:00
|
|
|
|
|
|
|
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)
|
2021-12-07 17:41:46 -07:00
|
|
|
end)
|
2022-07-30 06:40:30 -07:00
|
|
|
|
|
|
|
it('terminal truncates number of composing characters to 5', function()
|
|
|
|
clear()
|
|
|
|
local chan = meths.open_term(0, {})
|
|
|
|
local composing = ('a̳'):sub(2)
|
|
|
|
meths.chan_send(chan, 'a' .. composing:rep(8))
|
|
|
|
retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end)
|
|
|
|
end)
|
2023-03-19 10:23:34 -07:00
|
|
|
|
2023-07-17 06:42:55 -07:00
|
|
|
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 })
|
|
|
|
]])
|
|
|
|
command('startinsert')
|
|
|
|
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)
|
|
|
|
|
2023-03-19 10:23:34 -07:00
|
|
|
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
|
2023-06-23 14:32:07 -07:00
|
|
|
|
|
|
|
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)
|