2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2016-02-27 20:54:05 -07:00
|
|
|
local screen = require('test.functional.ui.screen')
|
2016-02-27 18:49:26 -07:00
|
|
|
|
2022-06-22 05:51:52 -07:00
|
|
|
local testprg = helpers.testprg
|
2016-02-27 18:49:26 -07:00
|
|
|
local command = helpers.command
|
2024-01-12 10:59:57 -07:00
|
|
|
local fn = helpers.fn
|
|
|
|
local api = helpers.api
|
2016-02-27 18:49:26 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local eq = helpers.eq
|
2020-01-26 01:24:42 -07:00
|
|
|
local matches = helpers.matches
|
2024-01-12 04:28:20 -07:00
|
|
|
local pesc = vim.pesc
|
2016-02-27 18:49:26 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-02-27 18:49:26 -07:00
|
|
|
before_each(function()
|
|
|
|
clear()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('shell', testprg('shell-test'), {})
|
|
|
|
api.nvim_set_option_value('shellcmdflag', 'EXE', {})
|
2016-02-27 18:49:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('runs TermOpen event', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('termopen_runs', {})
|
2016-02-27 18:49:26 -07:00
|
|
|
command('autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))')
|
|
|
|
command('edit term://')
|
2024-01-12 10:59:57 -07:00
|
|
|
local termopen_runs = api.nvim_get_var('termopen_runs')
|
2016-02-27 18:49:26 -07:00
|
|
|
eq(1, #termopen_runs)
|
2024-01-12 10:59:57 -07:00
|
|
|
local cwd = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
|
2024-01-02 18:09:18 -07:00
|
|
|
matches('^term://' .. pesc(cwd) .. '//%d+:$', termopen_runs[1])
|
2016-02-27 18:49:26 -07:00
|
|
|
end)
|
2016-02-27 20:54:05 -07:00
|
|
|
|
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)
|
2019-07-16 12:35:53 -07:00
|
|
|
local rep = 97
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('shellcmdflag', 'REP ' .. rep, {})
|
2024-01-02 18:09:18 -07:00
|
|
|
command('set shellxquote=') -- win: avoid extra quotes
|
2016-02-27 20:54:05 -07:00
|
|
|
local sb = 10
|
2024-01-02 18:09:18 -07:00
|
|
|
command(
|
|
|
|
'autocmd TermOpen * :setlocal scrollback=' .. tostring(sb) .. '|call feedkeys("G", "n")'
|
|
|
|
)
|
2016-02-27 20:54:05 -07:00
|
|
|
command('edit term://foobar')
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2016-02-27 20:54:05 -07:00
|
|
|
local bufcontents = {}
|
2024-01-12 10:59:57 -07:00
|
|
|
local winheight = api.nvim_win_get_height(0)
|
2019-07-16 12:35:53 -07:00
|
|
|
local buf_cont_start = rep - sb - winheight + 2
|
2024-01-02 18:09:18 -07:00
|
|
|
for i = buf_cont_start, (rep - 1) do
|
2017-03-30 15:41:52 -07:00
|
|
|
bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i)
|
2016-02-27 20:54:05 -07:00
|
|
|
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)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(bufcontents, api.nvim_buf_get_lines(0, 0, -1, true))
|
2016-02-27 20:54:05 -07:00
|
|
|
end)
|
2016-02-27 18:49:26 -07:00
|
|
|
end)
|