robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.3 KiB63 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local command = n.command
6local eq = t.eq
7local exec_capture = n.exec_capture
8local exec_lua = n.exec_lua
9local feed = n.feed
10local fn = n.fn
11local matches = t.matches
12
13describe(':marks', function()
14  before_each(function()
15    n.clear {}
16    fn.setline(1, { 'one', 'two', 'three' })
17    feed('ma')
18    exec_lua(function()
19      local ns = vim.api.nvim_create_namespace('my.plugin')
20      vim.api.nvim_buf_set_extmark(0, ns, 1, 0, {})
21      vim.api.nvim_buf_set_extmark(0, ns, 2, 1, {})
22      vim.api.nvim_create_namespace('empty.ns') -- no extmarks: not completed, not mentioned
23    end)
24  end)
25
26  it('completes names, lists extmarks', function()
27    -- Completion offers the set marks and the buffer's extmark namespaces.
28    eq({ '"', "'", '.', 'a', 'my.plugin' }, fn.getcompletion('marks ', 'cmdline'))
29    -- :marks (no args) only mentions the namespaces instead of listing their extmarks.
30    local out = exec_capture('marks')
31    matches('mark line  col file/text', out)
32    matches('Extmark namespaces %(use ":marks {ns}"%): my%.plugin', out)
33    eq(nil, out:find('empty%.ns'))
34    -- ":marks {ns}" lists that namespace's extmarks.
35    out = exec_capture('marks my.plugin')
36    matches('id%s+line%s+col text', out)
37    matches('1%s+2%s+0 two', out)
38    matches('2%s+3%s+1 three', out)
39    -- Not a namespace: the usual mark-names filter.
40    matches('mark line  col file/text', exec_capture('marks aB'))
41  end)
42
43  it(':filter on file/text column; E283; "No marks set"', function()
44    fn.setpos("'b", { 0, 2, 1, 0 })
45    local out = exec_capture('filter /two/ marks')
46    matches(' b%s+2%s+0 two', out)
47    eq(nil, out:find(' a ', 1, true)) -- mark a is on "one": filtered out
48    matches('E283: No marks matching "z"', t.pcall_err(command, 'marks z'))
49    -- Bare :marks with every row filtered out.
50    matches('No marks set', exec_capture('filter /xxx-nomatch/ marks'))
51  end)
52
53  it("prompt buffer: ':' mark in getmarklist() and :marks", function()
54    command('enew | set buftype=prompt')
55    feed('ifoo<Esc>')
56    local found = false
57    for _, m in ipairs(fn.getmarklist(fn.bufnr(''))) do
58      found = found or m.mark == "':"
59    end
60    eq(true, found)
61    matches(' :%s+%d+%s+%d+ ', exec_capture('marks'))
62  end)
63end)