summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/api/buffer_spec.lua
AgeCommit message (Collapse)AuthorFiles
2026-01-21 fix(api): auto-load buffers in nvim_buf_set_* operations (#35046)glepnir1
fix(api): auto-load buffers in nvim_buf_set_* operations Problem: Setting marks, lines, or text on unloaded buffers fails because ml_line_count is not accurate until the buffer is loaded. Solution: Add require_loaded_buffer() helper and use it in write operations (nvim_buf_set_lines, nvim_buf_set_text, nvim_buf_set_mark). These now auto-load buffers as needed.
2025-12-15refactor(test): deprecates functions in some tests #36972glepnir1
Problem: feed_command, nvim_buf_set_option, nvim_buf_get_number, and exc_exec are marked as deprecated. Solution: Remove them from the test units in api/buffer_spec, autocmd/focus_spec, ui/input_spec, and editor/put_spec. Some test units only used a few deprecated functions, so creating a separate PR for each would be excessive. Therefore, several were combined into a single PR.
2025-10-27fix(api): inconsistent scrolling when deleting before topline (#36301)zeertzjq1
Problem: Inconsistent scrolling when deleting before topline with API. Solution: Only special-case inserting just before topline, not deleting.
2024-11-14fix(tests): needing two calls to setup a screen is cringebfredl1
Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session.
2024-09-03fix(api): nvim_buf_get_text() crashes with large negative column #28740vanaigr1
Problem: crash when calling nvim_buf_get_text() with a large negative start_col: call nvim_buf_get_text(0, 0, -123456789, 0, 0, {}) Solution: clamp start_col after subtracting it from the line length.
2024-05-26refactor(tests): use more global highlight definitionsbfredl1
2024-04-23test: improve test conventionsdundargoc1
Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
2024-04-16fix(api): ignore 'autochdir' when renaming other buf (#28376)zeertzjq1
Problem: Renaming non-current buffer changes working directory when 'autochdir' is set. Solution: Temporarily disable 'autochdir'. Add more tests for the win_set_buf change.
2024-04-10refactor(test): inject after_each differentlyLewis Russell1
2024-04-08test: improve test conventionsdundargoc1
Work on https://github.com/neovim/neovim/issues/27004.
2024-04-04test: reduce `exec_lua` callsdundargoc1
`exec_lua` makes code slighly harder to read, so it's beneficial to remove it in cases where it's possible or convenient. Not all `exec_lua` calls should be removed even if the test passes as it changes the semantics of the test even if it happens to pass. From https://github.com/neovim/neovim/pull/28155#discussion_r1548185779: "Note for tests like this, which fundamentally are about conversion, you end up changing what conversion you are testing. Even if the result happens to be same (as they often are, as we like the rules to be consistent if possible), you are now testing the RPC conversion rules instead of the vim script to in-process lua conversion rules." From https://github.com/neovim/neovim/pull/28155#discussion_r1548190152: "A test like this specifies that the cursor is valid immediately and not after a separate cycle of normal (or an other input-processing) mode."
2024-03-23refactor(tests): all screen tests should use highlightsbfredl1
This is the first installment of a multi-PR series significantly refactoring how highlights are being specified. The end goal is to have a base set of 20 ish most common highlights, and then specific files only need to add more groups to that as needed. As a complicating factor, we also want to migrate to the new default color scheme eventually. But by sharing a base set, that future PR will hopefully be a lot smaller since a lot of tests will be migrated just simply by updating the base set in place. As a first step, fix the anti-pattern than Screen defaults to ignoring highlights. Highlights are integral part of the screen state, not something "extra" which we only test "sometimes". For now, we still allow opt-out via the intentionally ugly screen._default_attr_ids = nil The end goal is to get rid of all of these eventually (which will be easier as part of the color scheme migration)
2024-03-14fix(api): fix set_lines viewport adjustment, but this time goodbfredl1
fixes #27720
2024-03-13fix(api/buffer): fix handling of viewport of non-current bufferbfredl1
A lot of functions in move.c only worked for curwin, alternatively took a `wp` arg but still only work if that happens to be curwin. Refactor those that are needed for update_topline(wp) to work for any window. fixes #27723 fixes #27720
2024-01-16test: use integers for API Buffer/Window/Tabpage EXT typesLewis Russell1
2024-01-12test: rename (meths, funcs) -> (api, fn)Lewis Russell1
2024-01-12test: normalise nvim bridge functionsLewis Russell1
- remove helpers.cur*meths - remove helpers.nvim
2024-01-12test: typing for helpers.methsLewis Russell1
2024-01-12test: do not inject vim module into global helpersLewis Russell1
2024-01-03build: enable lintlua for test/ dirJustin M. Keyes1
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 stylua for entire `test/` directory. - Exclude these high-churn files until this issue is resolved: https://github.com/JohnnyMorganz/StyLua/issues/829 ``` test/functional/ui/decorations_spec.lua | 3560 ++++++++++++++++++++++++++++++++++++---------------- test/functional/ui/float_spec.lua | 5826 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- test/functional/ui/multigrid_spec.lua | 1349 ++++++++++++++------ ``` - Make surgical changes to these files (or add `stylua: ignore` in some small scopes) to improve the result: ``` test/functional/vimscript/msgpack_functions_spec.lua | 1414 +++++++++++++++------ test/functional/api/buffer_spec.lua | 1389 +++++++++++---------- test/functional/api/vim_spec.lua | 2740 +++++++++++++++++++++++----------------- ``` - These "high churn" files are NOT excluded because the changes are largely an improvement: ``` test/functional/plugin/lsp_spec.lua | 2198 ++++++++++++++++++--------------- test/functional/plugin/shada_spec.lua | 4078 +++++++++++++++++++++++++++++++++++------------------------- test/functional/ui/cmdline_spec.lua | 1199 +++++++++++------- test/functional/ui/popupmenu_spec.lua | 1267 +++++++++++-------- test/functional/ui/messages_spec.lua | 1643 +++++++++++++++--------- ``` - TODO: how to check "all directories"? With `GLOB_DIRS *` and `/.deps/` (or `.deps/`) in `.styluaignore`, Lua code in `.deps/` is still checked...
2023-12-19fix(api): don't set coladd of mark (#26648)zeertzjq1
2023-12-12Merge pull request #26486 from glepnir/fix_linebytebfredl1
fix(eval): use no_ff instead of ffdos as condition
2023-12-12fix: use no_ff instead of ffdos as conditionglepnir1
Problem: line2byte behavior is changed after commit b051b13. It no longer return `-1` on empty buffer. Solution: use `nof_ff` instead of `!ff_dos` as condition. Then compatible behavior of line2byte() is restored.
2023-12-09test: avoid repeated screen lines in expected stateszeertzjq1
This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g
2023-10-29fix(api): load buffer first on nvim_buf_set_lines (#25823)Raphael1
Fix #22670 Fix #8659
2023-09-11fix(api): more intuitive cursor updates in nvim_buf_set_textSergey Slipchenko1
Fixes #22526
2023-08-30fix(api): nvim_buf_get_offset in a new buffer with zero or one linesbfredl1
fixes #24930
2023-08-29fix(api): better topline adjustments in nvim_buf_set_linesbfredl1
Some more reasonable defaults for topline: - if topline was replaced with another line, that now becomes topline - if line was inserted just before topline, display it. This is more similar to the previous API behavior.
2023-08-28fix(api): handle clearing out last line of non-current bufferbfredl1
fixes #24911
2023-08-27fix(undo): fix crash caused by checking undolevels in wrong bufferbfredl1
fixes #24894
2023-08-27fix(api): fix inconsistent behavior of topline touched in recent refactorbfredl1
The change in #24824 0081549 was not a regression, however it was an incomplete change. Unfortunately some common plugins come to depend on this exising self-inconsistent behavior. These plugins are going to need to update for 0.10 nvim_buf_set_lines used to NOT adjust the topline correctly if a buffer was displayed in just one window. However, if displayed in multiple windows, it was correctly adjusted for any window not deemed the current window for the buffer (which could be an arbitrary choice if the buffer was not already current, as noted in the last rafactor) This fixes so that all windows have their topline adjusted. The added tests show this behavior, which should be the reasonable one.
2023-08-26refactor(change): do API changes to buffer without curbuf switchbfredl1
Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired.
2023-07-04fix(api): allow negative column arguments for nvim_buf_set_text (#23501)notomo1
2023-06-06refactor(defaults): do not use C specific default values for options (#22500)Gregory Anders1
The options 'path', 'include', and 'define' all use C-specific default values. This may have made sense a long time ago when Vim was mostly used just for writing C, but this is no longer the case, and we have ample support for filetype specific configuration. Make the default values of these options empty and move the C-specific values into a filetype plugin where they belong. Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2023-05-22test: don't unnecessarily specify win/buf for `nvim_(get|set)_option_value`Famiu Haque1
`nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter.
2023-05-21refactor(options): deprecate nvim[_buf|_win]_[gs]et_optionLewis Russell1
Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: famiu <famiuhaque@protonmail.com>
2023-02-14refactor(api): VALIDATE macros #22256Justin M. Keyes1
- VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args
2022-11-15fix(api): nvim_buf_get_text regression (#21071)Lewis Russell1
2022-11-14feat(lua-api): avoid unnecessary allocations (#19877)Lewis Russell1
Lua makes (or reuses) an internal copy of strings, so we can safely push buf pointers onto the stack.
2022-11-14feat(test): add Lua forms for API methods (#20152)Lewis Russell1
2022-08-06fix(api): fix nvim_buf_set_text heap-use-after-free (#19644)zeertzjq1
The line returned but ml_get_buf() may be freed by another call to ml_get_buf(), so it is necessary to make a copy.
2022-06-23fix(api): check for inclusive buffer line index out of bounds correctly (#19056)zeertzjq1
2022-02-23fix(api)!: correctly handle negative line numbers for nvim_buf_set_text (#17498)Gregory Anders1
nvim_buf_set_text does not handle negative row numbers correctly: for example, nvim_buf_set_text(0, -2, 0, -1, 20, {"Hello", "world"}) should replace the 2nd to last line in the buffer with "Hello" and the first 20 characters of the last line with "world". Instead, it reports "start_row out of bounds". This happens because when negative line numbers are used, they are incremented by one additional number to make the non-negative line numbers end-exclusive. However, the line numbers for nvim_buf_set_text should be end-inclusive. In #15181 we handled this for nvim_buf_get_text by adding a new parameter to `normalize_index`. We can solve the problem with nvim_buf_set_text by simply availing ourselves of this new argument. This is a breaking change, but makes the semantics of negative line numbers much clearer and more obvious (as well as matching nvim_buf_get_text). BREAKING CHANGE: Existing usages of nvim_buf_set_text that use negative line numbers will be off-by-one.
2022-02-22feat(api): implement nvim_buf_get_text (#15181)Gregory Anders1
nvim_buf_get_text is the mirror of nvim_buf_set_text. It differs from nvim_buf_get_lines in that it allows retrieving only portions of lines. While this can typically be done easily enough by API clients, implementing this function provides symmetry between the get/set text/lines APIs, and also provides a nice convenience that saves API clients the work of having to slice the result of nvim_buf_get_lines themselves.
2021-12-04feat(api): add nvim_get_option_valueGregory Anders1
2021-11-01refactor(api/marks)!: add opts param for feature extensibility (#16146)Javier Lopez1
In the future we might want to extend the concept of named marks and adding opts reduces the need of changing the function signature in the furute.
2021-10-05feat(api): named marks set, get, delete #15346Javier Lopez1
Adds the following API functions. - nvim_buf_set_mark(buf, name, line, col) * Set marks in a buffer. - nvim_buf_del_mark(buf, name) * Delete a mark that belongs to buffer. - nvim_del_mark(name) * Delete a global mark. - nvim_get_mark(name) * Get a global mark. Tests: - Adds test to all the new api functions, and adds more for the existing nvim_buf_get_mark. * Tests include failure cases. Documentation: - Adds documentation for all the new functions, and improves the existing fucntion docs.
2021-02-07correctly mark changed regions for set_textchentau1
2021-01-01api: set_text: more tests, and fixing lintchentau1
removing pending virtcol tests Allow passing in empty array as a shorthand for array with empty string; add more documentation add check for start_row as well
2021-01-01api: set_text: rebase, update to new api, and add more testsTony Chen1