neovim

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

K_spec.lua (2239B)


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