K_spec.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local eq, clear, eval, feed, api, retry = t.eq, n.clear, n.eval, n.feed, n.api, t.retry
  4. describe('K', function()
  5. local test_file = 'K_spec_out'
  6. before_each(function()
  7. clear()
  8. os.remove(test_file)
  9. end)
  10. after_each(function()
  11. os.remove(test_file)
  12. end)
  13. it("invokes colon-prefixed 'keywordprg' as Vim command", function()
  14. n.source([[
  15. let @a='fnord'
  16. set keywordprg=:put]])
  17. -- K on the text "a" resolves to `:put a`.
  18. feed('ia<ESC>K')
  19. n.expect([[
  20. a
  21. fnord]])
  22. end)
  23. it("invokes non-prefixed 'keywordprg' as shell command", function()
  24. n.source([[
  25. let @a='fnord'
  26. set keywordprg=echo\ fnord>>]])
  27. -- K on the text "K_spec_out" resolves to `!echo fnord >> K_spec_out`.
  28. feed('i' .. test_file .. '<ESC>K')
  29. retry(nil, nil, function()
  30. eq(1, eval('filereadable("' .. test_file .. '")'))
  31. end)
  32. eq({ 'fnord' }, eval("readfile('" .. test_file .. "')"))
  33. -- Confirm that Neovim is still in terminal mode after K is pressed (#16692).
  34. vim.uv.sleep(500)
  35. eq('t', eval('mode()'))
  36. feed('<space>') -- Any key, not just <space>, can be used here to escape.
  37. eq('n', eval('mode()'))
  38. end)
  39. it("<esc> kills the buffer for a running 'keywordprg' command", function()
  40. n.source('set keywordprg=less')
  41. eval('writefile(["hello", "world"], "' .. test_file .. '")')
  42. feed('i' .. test_file .. '<esc>K')
  43. eq('t', eval('mode()'))
  44. -- Confirm that an arbitrary keypress doesn't escape (i.e., the process is
  45. -- still running). If the process were no longer running, an arbitrary
  46. -- keypress would escape.
  47. vim.uv.sleep(500)
  48. feed('<space>')
  49. eq('t', eval('mode()'))
  50. -- Confirm that <esc> kills the buffer for the running command.
  51. local bufnr = eval('bufnr()')
  52. feed('<esc>')
  53. eq('n', eval('mode()'))
  54. t.neq(bufnr, eval('bufnr()'))
  55. end)
  56. it('empty string falls back to :help #19298', function()
  57. api.nvim_set_option_value('keywordprg', '', {})
  58. api.nvim_buf_set_lines(0, 0, -1, true, { 'doesnotexist' })
  59. feed('K')
  60. eq('E149: Sorry, no help for doesnotexist', api.nvim_get_vvar('errmsg'))
  61. end)
  62. end)