diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-12-07 07:15:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 07:15:37 +0800 |
commit | 6b00b8a369480a6535e7d286dd6ea27a6b0c94a5 (patch) | |
tree | 320c5d780b43764edd7bb53709c68e89289706b2 | |
parent | 8bb5089974e14f043a0b0c17e4d38dbd0b9a9ab2 (diff) | |
download | rneovim-6b00b8a369480a6535e7d286dd6ea27a6b0c94a5.tar.gz rneovim-6b00b8a369480a6535e7d286dd6ea27a6b0c94a5.tar.bz2 rneovim-6b00b8a369480a6535e7d286dd6ea27a6b0c94a5.zip |
test(terminal): remove unnecessary string operations (#26434)
-rw-r--r-- | test/functional/terminal/buffer_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/terminal/helpers.lua | 27 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/terminal/window_spec.lua | 2 |
5 files changed, 15 insertions, 28 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index b92f1b1592..7a52ee2b13 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -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) diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 4ae054daa8..78c9218679 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -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 { diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index d687dff230..c882d51f34 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -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, {}) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 0c984069b3..a3043ab470 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -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 | diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 39fc2c2562..57f1c881b7 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -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() |