neovim/test/functional/terminal/edit_spec.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.3 KiB
Lua
Raw Normal View History

local helpers = require('test.functional.helpers')(after_each)
local screen = require('test.functional.ui.screen')
local testprg = helpers.testprg
local command = helpers.command
local fn = helpers.fn
local api = helpers.api
local clear = helpers.clear
local eq = helpers.eq
local matches = helpers.matches
local pesc = vim.pesc
describe(':edit term://*', function()
2016-02-27 22:12:55 -07:00
local get_screen = function(columns, lines)
local scr = screen.new(columns, lines)
2024-01-02 18:09:18 -07:00
scr:attach({ rgb = false })
2016-02-27 22:12:55 -07:00
return scr
end
before_each(function()
clear()
api.nvim_set_option_value('shell', testprg('shell-test'), {})
api.nvim_set_option_value('shellcmdflag', 'EXE', {})
end)
it('runs TermOpen event', function()
api.nvim_set_var('termopen_runs', {})
command('autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))')
command('edit term://')
local termopen_runs = api.nvim_get_var('termopen_runs')
eq(1, #termopen_runs)
local cwd = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
2024-01-02 18:09:18 -07:00
matches('^term://' .. pesc(cwd) .. '//%d+:$', termopen_runs[1])
end)
2017-02-21 07:16:48 -07:00
it("runs TermOpen early enough to set buffer-local 'scrollback'", function()
2016-02-27 22:12:55 -07:00
local columns, lines = 20, 4
local scr = get_screen(columns, lines)
local rep = 97
api.nvim_set_option_value('shellcmdflag', 'REP ' .. rep, {})
2024-01-02 18:09:18 -07:00
command('set shellxquote=') -- win: avoid extra quotes
local sb = 10
2024-01-02 18:09:18 -07:00
command(
'autocmd TermOpen * :setlocal scrollback=' .. tostring(sb) .. '|call feedkeys("G", "n")'
)
command('edit term://foobar')
2017-02-21 07:16:48 -07:00
local bufcontents = {}
local winheight = api.nvim_win_get_height(0)
local buf_cont_start = rep - sb - winheight + 2
2024-01-02 18:09:18 -07:00
for i = buf_cont_start, (rep - 1) do
bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i)
end
bufcontents[#bufcontents + 1] = ''
bufcontents[#bufcontents + 1] = '[Process exited 0]'
2017-02-21 07:16:48 -07:00
2016-02-27 22:12:55 -07:00
local exp_screen = '\n'
2024-01-02 18:09:18 -07:00
for i = 1, (winheight - 1) do
2017-02-21 07:16:48 -07:00
local line = bufcontents[#bufcontents - winheight + i]
2024-01-02 18:09:18 -07:00
exp_screen = (exp_screen .. line .. (' '):rep(columns - #line) .. '|\n')
2016-02-27 22:12:55 -07:00
end
2024-01-02 18:09:18 -07:00
exp_screen = exp_screen .. '^[Process exited 0] |\n'
2017-02-21 07:16:48 -07:00
2024-01-02 18:09:18 -07:00
exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
2016-02-27 22:12:55 -07:00
scr:expect(exp_screen)
eq(bufcontents, api.nvim_buf_get_lines(0, 0, -1, true))
end)
end)