mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
test(terminal): remove unnecessary string operations (#26434)
This commit is contained in:
@ -487,7 +487,7 @@ if is_os('win') then
|
||||
clear()
|
||||
feed_command('set modifiable swapfile undolevels=20')
|
||||
poke_eventloop()
|
||||
local cmd = '["cmd.exe","/K","PROMPT=$g$s"]'
|
||||
local cmd = { "cmd.exe", "/K", "PROMPT=$g$s" }
|
||||
screen = thelpers.screen_setup(nil, cmd)
|
||||
end)
|
||||
|
||||
|
@ -52,9 +52,9 @@ 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 = '["'..testprg('tty-test')..'"]'
|
||||
local default_command = { testprg('tty-test') }
|
||||
|
||||
local function screen_setup(extra_rows, command, cols, opts)
|
||||
local function screen_setup(extra_rows, command, cols, env, screen_opts)
|
||||
extra_rows = extra_rows and extra_rows or 0
|
||||
command = command and command or default_command
|
||||
cols = cols and cols or 50
|
||||
@ -81,9 +81,10 @@ local function screen_setup(extra_rows, command, cols, opts)
|
||||
[15] = {underline = true, foreground = 12},
|
||||
})
|
||||
|
||||
screen:attach(opts or {rgb=false})
|
||||
screen:attach(screen_opts or {rgb=false})
|
||||
|
||||
nvim('command', 'enew | call termopen('..command..')')
|
||||
nvim('command', 'enew')
|
||||
nvim('call_function', 'termopen', {command, env and {env = env} or nil})
|
||||
nvim('input', '<CR>')
|
||||
local vim_errmsg = nvim('eval', 'v:errmsg')
|
||||
if vim_errmsg and "" ~= vim_errmsg then
|
||||
@ -96,7 +97,7 @@ local function screen_setup(extra_rows, command, cols, opts)
|
||||
|
||||
-- tty-test puts the terminal into raw mode and echoes input. Tests work by
|
||||
-- feeding termcodes to control the display and asserting by screen:expect.
|
||||
if command == default_command and opts == nil then
|
||||
if command == default_command and screen_opts == nil 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 = (' '):rep(cols)
|
||||
@ -125,22 +126,8 @@ end
|
||||
|
||||
local function setup_child_nvim(args, opts)
|
||||
opts = opts or {}
|
||||
|
||||
local argv = { nvim_prog, unpack(args) }
|
||||
local cmd = string.format('[%s]', vim.iter(argv):map(function(s)
|
||||
return string.format('\'%s\'', s)
|
||||
end):join(', '))
|
||||
|
||||
if opts.env then
|
||||
local s = {}
|
||||
for k, v in pairs(opts.env) do
|
||||
table.insert(s, string.format('%s: \'%s\'', k, v))
|
||||
end
|
||||
|
||||
cmd = string.format('%s, #{env: #{%s}}', cmd, table.concat(s, ', '))
|
||||
end
|
||||
|
||||
return screen_setup(0, cmd, opts.cols)
|
||||
return screen_setup(0, argv, opts.cols, opts.env)
|
||||
end
|
||||
|
||||
return {
|
||||
|
@ -392,9 +392,9 @@ describe("'scrollback' option", function()
|
||||
it('set to 0 behaves as 1', function()
|
||||
local screen
|
||||
if is_os('win') then
|
||||
screen = thelpers.screen_setup(nil, "['cmd.exe']", 30)
|
||||
screen = thelpers.screen_setup(nil, { 'cmd.exe' }, 30)
|
||||
else
|
||||
screen = thelpers.screen_setup(nil, "['sh']", 30)
|
||||
screen = thelpers.screen_setup(nil, { 'sh' }, 30)
|
||||
end
|
||||
|
||||
meths.set_option_value('scrollback', 0, {})
|
||||
@ -407,10 +407,10 @@ describe("'scrollback' option", function()
|
||||
local screen
|
||||
if is_os('win') then
|
||||
command([[let $PROMPT='$$']])
|
||||
screen = thelpers.screen_setup(nil, "['cmd.exe']", 30)
|
||||
screen = thelpers.screen_setup(nil, { 'cmd.exe' }, 30)
|
||||
else
|
||||
command('let $PS1 = "$"')
|
||||
screen = thelpers.screen_setup(nil, "['sh']", 30)
|
||||
screen = thelpers.screen_setup(nil, { 'sh' }, 30)
|
||||
end
|
||||
|
||||
meths.set_option_value('scrollback', 200, {})
|
||||
|
@ -1887,8 +1887,8 @@ describe('TUI', function()
|
||||
finally(function()
|
||||
os.remove('testF')
|
||||
end)
|
||||
local screen = thelpers.screen_setup(0, '"'..nvim_prog
|
||||
..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"')
|
||||
local screen = thelpers.screen_setup(0, nvim_prog
|
||||
..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF')
|
||||
feed_data(':w testF\n:q\n')
|
||||
screen:expect([[
|
||||
:w testF |
|
||||
|
@ -179,7 +179,7 @@ describe(':terminal with multigrid', function()
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = thelpers.screen_setup(0,nil,50,{ext_multigrid=true})
|
||||
screen = thelpers.screen_setup(0, nil, 50, nil, {ext_multigrid=true})
|
||||
end)
|
||||
|
||||
it('resizes to requested size', function()
|
||||
|
Reference in New Issue
Block a user