···11+# Testing
22+33+There are two flavors of test. Both run inside nvim.
44+55+## Unit tests
66+77+These mostly just test lua stuff, but might still require some vim specifics
88+like vim apis and editor variables.
99+1010+Run using `run_tests.sh`.
1111+1212+## Functional tests
1313+1414+These test more high level things and assert on things like buffer contents.
1515+These assume you have a `nvim.test` set up in the normal config location.
1616+1717+Run using `run_functional_tests.sh`.
1818+1919+TODO: Document the expected setup, basically just a config that uses the `vc*` plugins via lazy or whatever.
+59
lua/vcmarkers_tests/functional/helpers.lua
···11+local M = {}
22+33+local testing = require "vclib.testing"
44+55+--- Create a buffer with given contents.
66+---@param contents string Multiline string to set in buffer.
77+---@return integer bufnr The buffer number.
88+function M.create_buffer(contents)
99+ local bufnr = vim.api.nvim_create_buf(false, true)
1010+ local lines = testing.dedent_into_lines(contents)
1111+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
1212+ vim.api.nvim_set_current_buf(bufnr)
1313+ return bufnr
1414+end
1515+1616+--- Set cursor position.
1717+---@param line integer Line number (1-indexed).
1818+---@param col? integer Column number (0-indexed), defaults to 0.
1919+function M.set_cursor(line, col)
2020+ col = col or 0
2121+ vim.api.nvim_win_set_cursor(0, { line, col })
2222+end
2323+2424+--- Assert cursor is at specific line.
2525+---@param expected_line integer Expected line number (1-indexed).
2626+---@param msg? string Optional error message.
2727+function M.assert_cursor_at(expected_line, msg)
2828+ local line = vim.api.nvim_win_get_cursor(0)[1]
2929+ msg = msg or "Expected cursor at line " .. expected_line .. ", got " .. line
3030+ assert(line == expected_line, msg)
3131+end
3232+3333+--- Wait a bit for async updates to settle.
3434+---@param ms? integer Milliseconds to wait (default 10).
3535+function M.wait_update(ms)
3636+ ms = ms or 10
3737+ vim.wait(ms, function()
3838+ return false
3939+ end)
4040+ -- Process pending events
4141+ vim.api.nvim_exec_autocmds("User", { pattern = "Wait" })
4242+end
4343+4444+--- Get buffer lines.
4545+---@param bufnr integer Buffer number.
4646+---@return string[] lines The buffer lines.
4747+function M.get_lines(bufnr)
4848+ return vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
4949+end
5050+5151+--- Clean up buffer.
5252+---@param bufnr integer Buffer number.
5353+function M.cleanup_buffer(bufnr)
5454+ if vim.api.nvim_buf_is_valid(bufnr) then
5555+ vim.api.nvim_buf_delete(bufnr, { force = true })
5656+ end
5757+end
5858+5959+return M
+11
lua/vcmarkers_tests/functional/init.lua
···11+local M = {}
22+33+local testing = require "vclib.testing"
44+55+function M.run()
66+ local test_modules = {
77+ }
88+ testing.run_tests(test_modules)
99+end
1010+1111+return M
+4
lua/vcmarkers_tests/init.lua
···1111 testing.run_tests(test_modules)
1212end
13131414+function M.run_functional()
1515+ require("vcmarkers_tests.functional").run()
1616+end
1717+1418return M