robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.1 KiB64 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local Screen = require('test.functional.ui.screen')
5
6local describe, it, before_each = t.describe, t.it, t.before_each
7local testprg = n.testprg
8local command = n.command
9local fn = n.fn
10local api = n.api
11local clear = n.clear
12local eq = t.eq
13local matches = t.matches
14local pesc = vim.pesc
15
16describe(':edit term://*', function()
17  before_each(function()
18    clear()
19    api.nvim_set_option_value('shell', testprg('shell-test'), {})
20    api.nvim_set_option_value('shellcmdflag', 'EXE', {})
21  end)
22
23  it('runs TermOpen event', function()
24    api.nvim_set_var('termopen_runs', {})
25    command('autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))')
26    command('edit term://')
27    local termopen_runs = api.nvim_get_var('termopen_runs')
28    eq(1, #termopen_runs)
29    local cwd = fn.fnamemodify('.', ':p:~'):gsub([[/*$]], '')
30    matches('^term://' .. pesc(cwd) .. '//%d+:$', termopen_runs[1])
31  end)
32
33  it("runs TermOpen early enough to set buffer-local 'scrollback'", function()
34    local columns, lines = 20, 4
35    local scr = Screen.new(columns, lines, { rgb = false })
36    local rep = 97
37    api.nvim_set_option_value('shellcmdflag', 'REP ' .. rep, {})
38    command('set shellxquote=') -- win: avoid extra quotes
39    local sb = 10
40    command(
41      'autocmd TermOpen * :setlocal scrollback=' .. tostring(sb) .. '|call feedkeys("G", "n")'
42    )
43    command('edit term://foobar')
44
45    local bufcontents = {}
46    local winheight = api.nvim_win_get_height(0)
47    local buf_cont_start = rep - sb - winheight + 1
48    for i = buf_cont_start, (rep - 1) do
49      bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i)
50    end
51    bufcontents[#bufcontents + 1] = ''
52
53    local exp_screen = '\n'
54    for i = 1, (winheight - 1) do
55      local line = bufcontents[#bufcontents - winheight + i]
56      exp_screen = (exp_screen .. line .. (' '):rep(columns - #line) .. '|\n')
57    end
58    exp_screen = exp_screen .. '^[Process exited 0]  |\n'
59
60    exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
61    scr:expect(exp_screen)
62    eq(bufcontents, api.nvim_buf_get_lines(0, 0, -1, true))
63  end)
64end)