robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.9 KiB89 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 clear = n.clear
6local command = n.command
7local eq = t.eq
8local pcall_err = t.pcall_err
9local get_win_var = n.api.nvim_win_get_var
10
11describe('setqflist()', function()
12  local setqflist = n.fn.setqflist
13
14  before_each(clear)
15
16  it('requires a list for {list}', function()
17    eq('Vim(call):E714: List required', pcall_err(command, 'call setqflist("foo")'))
18    eq('Vim(call):E714: List required', pcall_err(command, 'call setqflist(5)'))
19    eq('Vim(call):E714: List required', pcall_err(command, 'call setqflist({})'))
20  end)
21
22  it('requires a string for {action}', function()
23    eq('Vim(call):E928: String required', pcall_err(command, 'call setqflist([], 5)'))
24    eq('Vim(call):E928: String required', pcall_err(command, 'call setqflist([], [])'))
25    eq('Vim(call):E928: String required', pcall_err(command, 'call setqflist([], {})'))
26  end)
27
28  it('sets w:quickfix_title', function()
29    setqflist({ '' }, 'r', 'foo')
30    command('copen')
31    eq('foo', get_win_var(0, 'quickfix_title'))
32    setqflist({}, 'r', { ['title'] = 'qf_title' })
33    eq('qf_title', get_win_var(0, 'quickfix_title'))
34  end)
35
36  it('allows string {what} for backwards compatibility', function()
37    setqflist({}, 'r', '5')
38    command('copen')
39    eq('5', get_win_var(0, 'quickfix_title'))
40  end)
41
42  it('requires a dict for {what}', function()
43    eq(
44      'Vim(call):E715: Dictionary required',
45      pcall_err(command, 'call setqflist([], "r", function("function"))')
46    )
47  end)
48end)
49
50describe('setloclist()', function()
51  local setloclist = n.fn.setloclist
52
53  before_each(clear)
54
55  it('requires a list for {list}', function()
56    eq('Vim(call):E714: List required', pcall_err(command, 'call setloclist(0, "foo")'))
57    eq('Vim(call):E714: List required', pcall_err(command, 'call setloclist(0, 5)'))
58    eq('Vim(call):E714: List required', pcall_err(command, 'call setloclist(0, {})'))
59  end)
60
61  it('requires a string for {action}', function()
62    eq('Vim(call):E928: String required', pcall_err(command, 'call setloclist(0, [], 5)'))
63    eq('Vim(call):E928: String required', pcall_err(command, 'call setloclist(0, [], [])'))
64    eq('Vim(call):E928: String required', pcall_err(command, 'call setloclist(0, [], {})'))
65  end)
66
67  it('sets w:quickfix_title for the correct window', function()
68    command('rightbelow vsplit')
69    setloclist(1, {}, 'r', 'foo')
70    setloclist(2, {}, 'r', 'bar')
71    command('lopen')
72    eq('bar', get_win_var(0, 'quickfix_title'))
73    command('lclose | wincmd w | lopen')
74    eq('foo', get_win_var(0, 'quickfix_title'))
75  end)
76
77  it("doesn't crash when when window is closed in the middle #13721", function()
78    n.insert([[
79    hello world]])
80
81    command('vsplit')
82    command('autocmd WinLeave * :call nvim_win_close(0, v:true)')
83
84    command('call setloclist(0, [])')
85    command('lopen')
86
87    n.assert_alive()
88  end)
89end)