neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

edit_spec.lua (2179B)


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