robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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