|
| 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:attach() |
| 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) |
| 79 | +end) |
0 commit comments