robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.2 KiB79 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local command = n.command
8local api = n.api
9local feed = n.feed
10local poke_eventloop = n.poke_eventloop
11local eq = t.eq
12local retry = t.retry
13
14describe("'belloff'", function()
15  local screen
16
17  before_each(function()
18    clear()
19    screen = Screen.new(42, 5)
20    screen:expect([[
21      ^                                          |
22      {1:~                                         }|*3
23                                                |
24    ]])
25  end)
26
27  it('various flags work properly', function()
28    command('set cpoptions+=E')
29
30    local map = {
31      backspace = 'i<BS><Esc>',
32      cursor = 'i<Up><Esc>',
33      copy = 'i<C-Y><Esc>',
34      ctrlg = 'i<C-G><C-G><Esc>',
35      error = 'J',
36      esc = '<Esc>',
37      operator = 'y0',
38      register = 'i<C-R>@<Esc>',
39    }
40
41    local items = {} ---@type string[]
42    local inputs = {} ---@type string[]
43    for item, input in pairs(map) do
44      table.insert(items, item)
45      table.insert(inputs, input)
46    end
47
48    local values = {} ---@type string[]
49    for i, _ in ipairs(items) do
50      -- each tested 'belloff' value enables at most one item
51      local parts = vim.deepcopy(items)
52      table.remove(parts, i)
53      local value = table.concat(parts, ',')
54      table.insert(values, value)
55    end
56    table.insert(values, 'all')
57
58    for i, value in ipairs(values) do
59      api.nvim_set_option_value('belloff', value, {})
60
61      for j, input in ipairs(inputs) do
62        screen.bell = false
63        local beep = value ~= 'all' and i == j
64        -- Nvim avoids beeping more than 3 times in half a second,
65        -- so retry if beeping is expected but not received.
66        retry(not beep and 1 or nil, 1000, function()
67          feed(input)
68          poke_eventloop()
69          screen:expect({
70            condition = function()
71              eq(beep, screen.bell, ('%s with belloff=%s'):format(items[j], value))
72            end,
73            unchanged = not beep,
74          })
75        end)
76      end
77    end
78  end)
79end)