aboutsummaryrefslogtreecommitdiff
path: root/test/unit/statusline_spec.lua
Commit message (Collapse)AuthorAge
* refactor(option): simplify error buffer handlingLewis Russell2026-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Option validators and setters repeatedly pass error buffers and their sizes separately. Some setters return messages in static storage. Solution: - Add CharBuf for borrowed writable storage, with its length including space for a terminating NUL. - Move option error buffers to the callers that report errors. Preserve existing buffer sizes, truncation, and calls that do not need a message. - Consolidate option error formatting and the duplicated code that lists valid option values. - Return error messages directly from do_one_set_option(). - Remove unused arguments from get_option_newval() and set_option_value_for(). - Handle legacy TTY assignments in the existing callers and remove the redundant compatibility wrapper. - Reuse CharBuf for Tree-sitter query errors. - Pass CharBuf through the statusline and statuscolumn builders, retaining the buffer sizes provided by their callers, including title formatting. AI-assisted
* fix(statusline)!: usefulness of %{%...%} in auto-hiding item groups #41817Sébastien Hoffmann2026-09-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: auto-hiding item groups (minwid==0) are hidden unless they contain a non-empty normal item or no items at all. In general, normal items are those that show information: strings, numbers, flags. Expression items %{...} are also treated as normal, see for example the terminal exit code in the flags section. But in contrast, when using re-evaluated expression items %{%...%}, the item group looks for normal items in the expression result. This is useful for dynamically deciding which items should be in use. Example: stl=%f%(\ %h%w%{%&buftype==''?'%m%r':''%}%). But when the result only contains non-normal items like highlights, the non-emptiness of the result doesn't ensure the item group to be shown. Example: the diagnostics section uses %{%...%} to add highlighting, and thus cannot use auto-hiding and has to resort to a non-idiomatic and verbose solution to add padding between itself and the next section. Solution: look for normal items (empty or not) in the expression result. If there are none, treat the whole result as one normal item. BREAKING CHANGE: it is no longer easily possible to use %{%...%} to add dynamic content with non-normal items (e.g. highlighting) to an item group with minwid==0 without influencing auto-hiding. Workaround: add a dummy empty normal item like %{''} to the result. Or refactor so that the whole item group is created inside %{%...%}.
* test(harness): migrate away from magic globalsJustin M. Keyes2026-07-21
| | | | | | | | | | | | | | | | | | | | | Problem: The magic globals `it`, `describe`, etc., are more trouble than they are worth. - Hooking into `after_each` requires `getfenv()` hacks. - They confuse luals/emmylua, because the top-level `.luarc.json` isn't merged with `test/.luarc.json` (apparently a luals limitation?) - They totally defeat discoverability because the user just has to "know" about the various magic symbols. So they harm DX, which means they serve no purpose at all. Solution: - Expose the test API from `testutil`, so tests can call `t.it()`, `t.describe()`, etc., in the conventional way. - Drop `getfenv()` hacks. - Drop the `setfenv()` injection in `load_chunk`. - Drop `test/_meta.lua`.
* fix(statusline): prevent integer overflow with huge item groups #40837Sébastien Hoffmann2026-07-19
| | | | | | | | Problem: when PR #40621 removed a 50 cell restriction to item group minwid, a possible integer overflow was introduced when the added padding is multiplied with the number of fillchar bytes. Solution: when there is not enough buffer capacity left, reduce the number of added fillchars before calculating the number of added bytes.
* feat(statusline)!: allow %= in item groups, scope %< to item groups #40369Sébastien Hoffmann2026-06-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Separation markers (%=) are ignored within item groups. This lead to a regression when the C implementation of the statusline was replaced with a default expression. When the user configured a custom ruler expression with a %= and used the overloaded item group syntax to set the ruler width, the separation marker worked in the ruler, but not when the ruler was incorporated into the statusline where the item group syntax was interpreted in the usual way. Solution: Analogously to top-level behaviour, expand separation markers evenly within item groups until `minwid` is reached (if set). ref https://github.com/neovim/neovim/pull/33036 fix https://github.com/neovim/neovim/issues/39984 ref https://github.com/neovim/neovim/issues/40247 Problem: The recursion offset into the static `stl_items` was not taken into account when adjusting the item count after truncation. Steps to reproduce: first prepare `stl_items`: set stl=%{%repeat('%#Error#',10)%} then watch how the Error highlight leaks into the recursive call: set stl=%l%l%l%{%nvim_eval_statusline('test%l%<',{'maxwidth':3,'highlights':1}).highlights%} ref https://github.com/neovim/neovim/issues/32259 * fix(statusline): consistent truncation at multicell character Problem 1: truncation of item groups at multicell character didn't take into account that minwid can be specified as a negative number. Problem 2: after truncation at top-level from the right at multicell character, the returned width was always `maxwidth`, even though the actual width was reduced. In vim, this can be observed as a statusline that is not fully drawn until the edge of the screen: vim --clean +"set ls=2 stl=%{%repeat('x',&columns-2)%}🙂x%<" Problem 3: after truncation at top-level from the left at multicell character, the resulting gap to reach `maxwidth` again was filled with fillchars, but then the final NUL was not set correctly. This can be seen in the following example, where the statuscolumn spills into the editing area starting from line 10: nvim --clean +"set number stc=%<x🙂%{repeat('x',43)}%l" +"norm yy10p" Solution: fix the small errors and, at top-level, consistently reduce the size instead of compensating with fillchars. In the case of the statusline and the winbar, the remaining place is filled with the configured fillchars in `win_redr_custom`, after `build_stl_str_hl` has returned. In all other cases (title, icon, statuscol, tabline, ruler), there seems to be no point in adding additional spaces at the end. * feat(statusline)!: scope %< to item groups Problem: Previously, item groups were only truncated at the beginning, which is often not desired. In the example %.15(path: %f%) the group's title/label is truncated away: <th/to/file.txt Truncation markers (%<) in item groups were processed at the top-level in the end, which can be confusing. Only the first %< is used for the whole string, and it is used even if the containing item group is hidden. Additionally, in the case of hidden item groups, the marker's position was not adapted. For example, %(hidden%<%)%f had the effect of truncating the path somewhere in the middle: /path/<file.txt Solution: Make truncation consistent with top-level behaviour, which has a better default of truncating at the first `Normal` item, i.e. path: <file.txt and allows for fine-grained control with truncation markers (%<). E.g. %.15(path: %f%<%) now yields path: /path/to> The original behaviour can be restored like so: %.15(%<path: %f%) BREAKING CHANGE: %< is no longer processed at top-level - the default truncation behaviour has changed: now at first item - truncation markers inside item groups don't affect truncation outside of the item group anymore - several truncation markers can now have an effect when separated with item groups, whereas previously only the first one globally had ref https://github.com/neovim/neovim/issues/39984
* fix(statusline): prevent various buffer overflows with item groups #40219Sébastien Hoffmann2026-06-13
| | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Various out-of-bounds writes inherited from vim (examples assume MAXPATHL==4096): - truncated item groups where minwid>maxwid: nvim --clean +"set stl=%<%{%repeat('x',4096-11)%}%50.5(12🙂345%)" leads to fillchars spilling over the end of the group/buffer while trying to compensate for truncating at a multicell character because minwid<=maxwid is assumed - left-aligned item groups with multi-byte fillchar: nvim --clean +"set fillchars+=stl:∙ stl=%<%{%repeat('x',4096-3)%}%-2(X%)" wrongly leads to padding at the end of the statusline and `out_p-out==4097` because the bounds check assumes a 1-byte fillchar - right-aligned item groups with 1-byte fillchar: nvim --clean +"set stl=%<%{%repeat('x',4096-4)%}%4(XY%)" leads to "YX" instead of "XY" at the end of the statusline because `memmove` is done before adjusting the offset - right-aligned item groups with multi-byte fillchar: nvim --clean +"set fillchars+=stl:∙ stl=%5(X%)" leads to "∙∙∙∙<e2>", i.e. the fillchar is being written over the group contents and eventually being overwritten itself at the second byte with the final NUL, because the padding counter assumes a 1-byte fillchar; to crash Neovim, nvim --clean +"set fillchars+=stl:∙ stl=%<%{%repeat('x',4096-149)%}%50(X%)" Solution: Clearer variable names and no recycling of variables for different purposes.
* vim-patch:9.2.0078: [security]: stack-buffer-overflow in build_stl_str_hl() ↵zeertzjq2026-02-28
| | | | | | | | | | | | | | | | | | | (#38102) Problem: A stack-buffer-overflow occurs when rendering a statusline with a multi-byte fill character on a very wide terminal. The size check in build_stl_str_hl() uses the cell width rather than the byte length, allowing the subsequent fill loop to write beyond the 4096-byte MAXPATHL buffer (ehdgks0627, un3xploitable). Solution: Update the size check to account for the byte length of the fill character (using MB_CHAR2LEN). Github Advisory: https://github.com/vim/vim/security/advisories/GHSA-gmqx-prf2-8mwf https://github.com/vim/vim/commit/4e5b9e31cb7484ad156fba995fdce3c9b075b5fd Co-authored-by: Christian Brabandt <cb@256bit.org>
* refactor(api)!: rename Dictionary => DictJustin M. Keyes2024-09-23
| | | | | | | | | | | | | | In the api_info() output: :new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val') ... {'return_type': 'ArrayOf(Integer, 2)', 'name': 'nvim_win_get_position', 'method': v:true, 'parameters': [['Window', 'window']], 'since': 1} The `ArrayOf(Integer, 2)` return type didn't break clients when we added it, which is evidence that clients don't use the `return_type` field, thus renaming Dictionary => Dict in api_info() is not (in practice) a breaking change.
* refactor(test): inject after_each differentlyLewis Russell2024-04-10
|
* test: improve test conventionsdundargoc2024-04-08
| | | | Work on https://github.com/neovim/neovim/issues/27004.
* refactor(api): refactor more api functions to use arena returnbfredl2024-02-08
| | | | | | | | | | | | | | | Currently having two separate memory strategies for API return values is a bit unnecessary, and mostly a consequence of converting the hot spot cases which needed it first. But there is really no downside to using arena everywhere (which implies also directly using strings which are allocated earlier or even statically, without copy). There only restriction is we need to know the size of arrays in advance, but this info can often be passed on from some earlier stage if it is missing. This collects some "small" cases. The more complex stuff will get a PR each.
* refactor(options): use schar_T representation for fillchars and listcharsbfredl2024-01-08
| | | | | | | | | | | A bit big, but practically it was a lot simpler to change over all fillchars and all listchars at once, to not need to maintain two parallel implementations. This is mostly an internal refactor, but it also removes an arbitrary limitation: that 'fillchars' and 'listchars' values can only be single-codepoint characters. Now any character which fits into a single screen cell can be used.
* refactor(options): reduce `findoption()` usageFamiu Haque2023-12-09
| | | | | | Problem: Many places in the code use `findoption()` to access an option using its name, even if the option index is available. This is very slow because it requires looping through the options array over and over. Solution: Use option index instead of name wherever possible. Also introduce an `OptIndex` enum which contains the index for every option as enum constants, this eliminates the need to pass static option names as strings.
* build: enable lintlua for test/unit/ dir #26396Justin M. Keyes2023-12-04
| | | | | | | | | | | | | Problem: Not all Lua code is checked by stylua. Automating code-style is an important mechanism for reducing time spent on accidental (non-essential) complexity. Solution: - Enable lintlua for `test/unit/` directory. - TODO: only `test/functional/` remains unchecked. previous: 45fe4d11add933df76a2ea4bf52ce8904f4a778b previous: 517f0cc634b985057da5b95cf4ad659ee456a77e
* test(unit): move statusline tests to statusline_spec.lua (#25441)zeertzjq2023-09-30