edit_spec.lua 2.1 KB

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