K_spec.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local eq, clear, eval, feed, retry =
  3. helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.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. helpers.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. helpers.expect([[
  20. a
  21. fnord]])
  22. end)
  23. it("invokes non-prefixed 'keywordprg' as shell command", function()
  24. helpers.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() eq(1, eval('filereadable("'..test_file..'")')) end)
  30. eq({'fnord'}, eval("readfile('"..test_file.."')"))
  31. -- Confirm that Neovim is still in terminal mode after K is pressed (#16692).
  32. helpers.sleep(500)
  33. eq('t', eval('mode()'))
  34. feed('<space>') -- Any key, not just <space>, can be used here to escape.
  35. eq('n', eval('mode()'))
  36. end)
  37. it("<esc> kills the buffer for a running 'keywordprg' command", function()
  38. helpers.source('set keywordprg=less')
  39. eval('writefile(["hello", "world"], "' .. test_file .. '")')
  40. feed('i' .. test_file .. '<esc>K')
  41. eq('t', eval('mode()'))
  42. -- Confirm that an arbitrary keypress doesn't escape (i.e., the process is
  43. -- still running). If the process were no longer running, an arbitrary
  44. -- keypress would escape.
  45. helpers.sleep(500)
  46. feed('<space>')
  47. eq('t', eval('mode()'))
  48. -- Confirm that <esc> kills the buffer for the running command.
  49. local bufnr = eval('bufnr()')
  50. feed('<esc>')
  51. eq('n', eval('mode()'))
  52. helpers.neq(bufnr, eval('bufnr()'))
  53. end)
  54. end)