belloff_spec.lua 2.1 KB

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