diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-10-18 22:39:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-18 14:39:27 +0000 |
commit | 395f420fc65cb99f1c5cf17e230b962cb1e74bcd (patch) | |
tree | 92fdaf262480a9cd585459ea48cc3aed87df7669 | |
parent | b5e69b32d7e299b8283f13f4f97081f6cf795f0a (diff) | |
download | rneovim-395f420fc65cb99f1c5cf17e230b962cb1e74bcd.tar.gz rneovim-395f420fc65cb99f1c5cf17e230b962cb1e74bcd.tar.bz2 rneovim-395f420fc65cb99f1c5cf17e230b962cb1e74bcd.zip |
fix(options): fix some 'belloff' flags not working properly (#30856)
Problem: Some 'belloff' flags don't work properly.
Solution: Keep BO_ flags and p_bo_values[] in sync.
-rw-r--r-- | src/nvim/optionstr.c | 4 | ||||
-rw-r--r-- | test/functional/options/belloff_spec.lua | 79 |
2 files changed, 81 insertions, 2 deletions
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 1850b82209..082073148e 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -72,8 +72,8 @@ static char *(p_ambw_values[]) = { "single", "double", NULL }; static char *(p_bg_values[]) = { "light", "dark", NULL }; static char *(p_bkc_values[]) = { "yes", "auto", "no", "breaksymlink", "breakhardlink", NULL }; static char *(p_bo_values[]) = { "all", "backspace", "cursor", "complete", "copy", "ctrlg", "error", - "esc", "ex", "hangul", "lang", "mess", "showmatch", "operator", - "register", "shell", "spell", "wildmode", NULL }; + "esc", "ex", "hangul", "insertmode", "lang", "mess", "showmatch", + "operator", "register", "shell", "spell", "wildmode", NULL }; // Note: Keep this in sync with briopt_check() static char *(p_briopt_values[]) = { "shift:", "min:", "sbr", "list:", "column:", NULL }; // Note: Keep this in sync with diffopt_changed() diff --git a/test/functional/options/belloff_spec.lua b/test/functional/options/belloff_spec.lua new file mode 100644 index 0000000000..6bd96538d2 --- /dev/null +++ b/test/functional/options/belloff_spec.lua @@ -0,0 +1,79 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() +local Screen = require('test.functional.ui.screen') + +local clear = n.clear +local command = n.command +local api = n.api +local feed = n.feed +local poke_eventloop = n.poke_eventloop +local eq = t.eq +local retry = t.retry + +describe("'belloff'", function() + local screen + + before_each(function() + clear() + screen = Screen.new(42, 5) + screen:attach() + screen:expect([[ + ^ | + {1:~ }|*3 + | + ]]) + end) + + it('various flags work properly', function() + command('set cpoptions+=E') + + local map = { + backspace = 'i<BS><Esc>', + cursor = 'i<Up><Esc>', + copy = 'i<C-Y><Esc>', + ctrlg = 'i<C-G><C-G><Esc>', + error = 'J', + esc = '<Esc>', + operator = 'y0', + register = 'i<C-R>@<Esc>', + } + + local items = {} ---@type string[] + local inputs = {} ---@type string[] + for item, input in pairs(map) do + table.insert(items, item) + table.insert(inputs, input) + end + + local values = {} ---@type string[] + for i, _ in ipairs(items) do + -- each tested 'belloff' value enables at most one item + local parts = vim.deepcopy(items) + table.remove(parts, i) + local value = table.concat(parts, ',') + table.insert(values, value) + end + table.insert(values, 'all') + + for i, value in ipairs(values) do + api.nvim_set_option_value('belloff', value, {}) + + for j, input in ipairs(inputs) do + screen.bell = false + local beep = value ~= 'all' and i == j + -- Nvim avoids beeping more than 3 times in half a second, + -- so retry if beeping is expected but not received. + retry(not beep and 1 or nil, 1000, function() + feed(input) + poke_eventloop() + screen:expect({ + condition = function() + eq(beep, screen.bell, ('%s with belloff=%s'):format(items[j], value)) + end, + unchanged = not beep, + }) + end) + end + end + end) +end) |