edit_spec.lua 2.24 KB
Newer Older
ZyX's avatar
ZyX committed
1
local helpers = require('test.functional.helpers')(after_each)
2
local screen = require('test.functional.ui.screen')
3

4 5
local curbufmeths = helpers.curbufmeths
local curwinmeths = helpers.curwinmeths
6 7 8 9 10 11 12
local nvim_dir = helpers.nvim_dir
local command = helpers.command
local meths = helpers.meths
local clear = helpers.clear
local eq = helpers.eq

describe(':edit term://*', function()
ZyX's avatar
ZyX committed
13 14
  local get_screen = function(columns, lines)
    local scr = screen.new(columns, lines)
15
    scr:attach({rgb=false})
ZyX's avatar
ZyX committed
16 17 18
    return scr
  end

19 20 21
  before_each(function()
    clear()
    meths.set_option('shell', nvim_dir .. '/shell-test')
22
    meths.set_option('shellcmdflag', 'EXE')
23 24 25 26 27 28
  end)

  it('runs TermOpen event', function()
    meths.set_var('termopen_runs', {})
    command('autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))')
    command('edit term://')
29
    local termopen_runs = meths.get_var('termopen_runs')
30 31 32
    eq(1, #termopen_runs)
    eq(termopen_runs[1], termopen_runs[1]:match('^term://.//%d+:$'))
  end)
33

Justin M. Keyes's avatar
Justin M. Keyes committed
34
  it("runs TermOpen early enough to set buffer-local 'scrollback'", function()
ZyX's avatar
ZyX committed
35 36
    local columns, lines = 20, 4
    local scr = get_screen(columns, lines)
37 38
    local rep = 'a'
    meths.set_option('shellcmdflag', 'REP ' .. rep)
Justin M. Keyes's avatar
Justin M. Keyes committed
39
    local rep_size = rep:byte()  -- 'a' => 97
40
    local sb = 10
Justin M. Keyes's avatar
Justin M. Keyes committed
41
    command('autocmd TermOpen * :setlocal scrollback='..tostring(sb))
42
    command('edit term://foobar')
Justin M. Keyes's avatar
Justin M. Keyes committed
43

44 45
    local bufcontents = {}
    local winheight = curwinmeths.get_height()
Justin M. Keyes's avatar
Justin M. Keyes committed
46 47 48 49
    local buf_cont_start = rep_size - sb - winheight + 2
    local function bufline (i)
      return ('%d: foobar'):format(i)
    end
ZyX's avatar
ZyX committed
50 51
    for i = buf_cont_start,(rep_size - 1) do
      bufcontents[#bufcontents + 1] = bufline(i)
52 53 54
    end
    bufcontents[#bufcontents + 1] = ''
    bufcontents[#bufcontents + 1] = '[Process exited 0]'
Justin M. Keyes's avatar
Justin M. Keyes committed
55

ZyX's avatar
ZyX committed
56
    local exp_screen = '\n'
Justin M. Keyes's avatar
Justin M. Keyes committed
57 58
    for i = 1,(winheight - 1) do
      local line = bufcontents[#bufcontents - winheight + i]
ZyX's avatar
ZyX committed
59 60 61 62 63
      exp_screen = (exp_screen
                    .. line
                    .. (' '):rep(columns - #line)
                    .. '|\n')
    end
Justin M. Keyes's avatar
Justin M. Keyes committed
64 65 66
    exp_screen = exp_screen..'^[Process exited 0]  |\n'

    exp_screen = exp_screen..(' '):rep(columns)..'|\n'
ZyX's avatar
ZyX committed
67
    scr:expect(exp_screen)
Justin M. Keyes's avatar
Justin M. Keyes committed
68
    eq(bufcontents, curbufmeths.get_lines(0, -1, true))
69
  end)
70
end)