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