aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/buffer_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/terminal/buffer_spec.lua')
-rw-r--r--test/functional/terminal/buffer_spec.lua153
1 files changed, 81 insertions, 72 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 376b7b849e..96abd9f543 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -1,24 +1,27 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local thelpers = require('test.functional.terminal.helpers')
-local assert_alive = helpers.assert_alive
-local feed, clear = helpers.feed, helpers.clear
-local poke_eventloop = helpers.poke_eventloop
-local nvim_prog = helpers.nvim_prog
-local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
-local pcall_err = helpers.pcall_err
-local eq, neq = helpers.eq, helpers.neq
-local api = helpers.api
-local retry = helpers.retry
-local write_file = helpers.write_file
-local command = helpers.command
-local exc_exec = helpers.exc_exec
-local matches = helpers.matches
-local exec_lua = helpers.exec_lua
+local tt = require('test.functional.terminal.testutil')
+
+local assert_alive = n.assert_alive
+local feed, clear = n.feed, n.clear
+local poke_eventloop = n.poke_eventloop
+local nvim_prog = n.nvim_prog
+local eval, feed_command, source = n.eval, n.feed_command, n.source
+local pcall_err = t.pcall_err
+local eq, neq = t.eq, t.neq
+local api = n.api
+local retry = t.retry
+local testprg = n.testprg
+local write_file = t.write_file
+local command = n.command
+local exc_exec = n.exc_exec
+local matches = t.matches
+local exec_lua = n.exec_lua
local sleep = vim.uv.sleep
-local fn = helpers.fn
-local is_os = helpers.is_os
-local skip = helpers.skip
+local fn = n.fn
+local is_os = t.is_os
+local skip = t.skip
describe(':terminal buffer', function()
local screen
@@ -26,7 +29,7 @@ describe(':terminal buffer', function()
before_each(function()
clear()
command('set modifiable swapfile undolevels=20')
- screen = thelpers.screen_setup()
+ screen = tt.screen_setup()
end)
it('terminal-mode forces various options', function()
@@ -54,7 +57,7 @@ describe(':terminal buffer', function()
eq({ 0, 'both' }, eval('[&l:cursorline, &l:cursorlineopt]'))
end)
- it('terminal-mode disables cursorline when cursorlineopt is only set to "line', function()
+ it('terminal-mode disables cursorline when cursorlineopt is only set to "line"', function()
feed([[<C-\><C-N>]])
command('setlocal cursorline cursorlineopt=line')
feed('i')
@@ -205,22 +208,14 @@ describe(':terminal buffer', function()
eq(tbuf, eval('bufnr("%")'))
end)
- it('term_close() use-after-free #4393', function()
- feed_command('terminal yes')
- feed([[<C-\><C-n>]])
- feed_command('bdelete!')
- end)
-
describe('handles confirmations', function()
it('with :confirm', function()
- feed_command('terminal')
feed('<c-\\><c-n>')
feed_command('confirm bdelete')
screen:expect { any = 'Close "term://' }
end)
it('with &confirm', function()
- feed_command('terminal')
feed('<c-\\><c-n>')
feed_command('bdelete')
screen:expect { any = 'E89' }
@@ -273,7 +268,7 @@ describe(':terminal buffer', function()
it('does not segfault when pasting empty register #13955', function()
feed('<c-\\><c-n>')
feed_command('put a') -- register a is empty
- helpers.assert_alive()
+ n.assert_alive()
end)
it([[can use temporary normal mode <c-\><c-o>]], function()
@@ -317,13 +312,22 @@ describe(':terminal buffer', function()
pcall_err(command, 'write test/functional/fixtures/tty-test.c')
)
end)
+end)
+
+describe(':terminal buffer', function()
+ before_each(clear)
+
+ it('term_close() use-after-free #4393', function()
+ command('terminal yes')
+ feed('<Ignore>') -- Add input to separate two RPC requests
+ command('bdelete!')
+ end)
it('emits TermRequest events #26972', function()
- command('new')
local term = api.nvim_open_term(0, {})
local termbuf = api.nvim_get_current_buf()
- -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer
+ -- Test that <abuf> is the terminal buffer, not the current buffer
command('au TermRequest * let g:termbuf = +expand("<abuf>")')
command('wincmd p')
@@ -337,7 +341,6 @@ describe(':terminal buffer', function()
end)
it('TermReqeust synchronization #27572', function()
- command('new')
command('autocmd! nvim_terminal TermRequest')
local term = exec_lua([[
_G.input = {}
@@ -364,20 +367,13 @@ describe(':terminal buffer', function()
'\027[0n',
}, exec_lua('return _G.input'))
end)
-end)
-
-describe('No heap-buffer-overflow when using', function()
- local testfilename = 'Xtestfile-functional-terminal-buffers_spec'
- before_each(function()
+ it('no heap-buffer-overflow when using termopen(echo) #3161', function()
+ local testfilename = 'Xtestfile-functional-terminal-buffers_spec'
write_file(testfilename, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa')
- end)
-
- after_each(function()
- os.remove(testfilename)
- end)
-
- it('termopen(echo) #3161', function()
+ finally(function()
+ os.remove(testfilename)
+ end)
feed_command('edit ' .. testfilename)
-- Move cursor away from the beginning of the line
feed('$')
@@ -386,15 +382,36 @@ describe('No heap-buffer-overflow when using', function()
assert_alive()
feed_command('bdelete!')
end)
-end)
-describe('No heap-buffer-overflow when', function()
- it('set nowrap and send long line #11548', function()
+ it('no heap-buffer-overflow when sending long line with nowrap #11548', function()
feed_command('set nowrap')
feed_command('autocmd TermOpen * startinsert')
feed_command('call feedkeys("4000ai\\<esc>:terminal!\\<cr>")')
assert_alive()
end)
+
+ it('truncates number of composing characters to 5', function()
+ local chan = api.nvim_open_term(0, {})
+ local composing = ('a̳'):sub(2)
+ api.nvim_chan_send(chan, 'a' .. composing:rep(8))
+ retry(nil, nil, function()
+ eq('a' .. composing:rep(5), api.nvim_get_current_line())
+ end)
+ end)
+
+ it('handles split UTF-8 sequences #16245', function()
+ local screen = Screen.new(50, 7)
+ screen:attach()
+ fn.termopen({ testprg('shell-test'), 'UTF-8' })
+ screen:expect([[
+ ^å |
+ ref: å̲ |
+ 1: å̲ |
+ 2: å̲ |
+ 3: å̲ |
+ |*2
+ ]])
+ end)
end)
describe('on_lines does not emit out-of-bounds line indexes when', function()
@@ -431,16 +448,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function()
end)
end)
-it('terminal truncates number of composing characters to 5', function()
- clear()
- local chan = api.nvim_open_term(0, {})
- local composing = ('a̳'):sub(2)
- api.nvim_chan_send(chan, 'a' .. composing:rep(8))
- retry(nil, nil, function()
- eq('a' .. composing:rep(5), api.nvim_get_current_line())
- end)
-end)
-
describe('terminal input', function()
before_each(function()
clear()
@@ -468,7 +475,7 @@ end)
describe('terminal input', function()
it('sends various special keys with modifiers', function()
clear()
- local screen = thelpers.setup_child_nvim({
+ local screen = tt.setup_child_nvim({
'-u',
'NONE',
'-i',
@@ -477,18 +484,16 @@ describe('terminal input', function()
'colorscheme vim',
'--cmd',
'set notermguicolors',
- '--cmd',
- 'startinsert',
+ '-c',
+ 'while 1 | redraw | echo keytrans(getcharstr()) | endwhile',
})
- screen:expect {
- grid = [[
+ screen:expect([[
{1: } |
{4:~ }|*3
- {5:[No Name] 0,1 All}|
- {3:-- INSERT --} |
+ {5:[No Name] 0,0-1 All}|
+ |
{3:-- TERMINAL --} |
- ]],
- }
+ ]])
for _, key in ipairs({
'<M-Tab>',
'<M-CR>',
@@ -538,10 +543,14 @@ describe('terminal input', function()
'<ScrollWheelLeft>',
'<ScrollWheelRight>',
}) do
- feed('<CR><C-V>' .. key)
- retry(nil, nil, function()
- eq(key, api.nvim_get_current_line())
- end)
+ feed(key)
+ screen:expect(([[
+ |
+ {4:~ }|*3
+ {5:[No Name] 0,0-1 All}|
+ %s{1: }{MATCH: *}|
+ {3:-- TERMINAL --} |
+ ]]):format(key))
end
end)
end)
@@ -555,7 +564,7 @@ if is_os('win') then
feed_command('set modifiable swapfile undolevels=20')
poke_eventloop()
local cmd = { 'cmd.exe', '/K', 'PROMPT=$g$s' }
- screen = thelpers.screen_setup(nil, cmd)
+ screen = tt.screen_setup(nil, cmd)
end)
it('"put" operator sends data normally', function()