this repo has no description

Add functional test infrastructure.

Create functional test directory structure.
Implement helpers.lua with buffer and cursor utilities.

+114
+19
TESTING.md
··· 1 + # Testing 2 + 3 + There are two flavors of test. Both run inside nvim. 4 + 5 + ## Unit tests 6 + 7 + These mostly just test lua stuff, but might still require some vim specifics 8 + like vim apis and editor variables. 9 + 10 + Run using `run_tests.sh`. 11 + 12 + ## Functional tests 13 + 14 + These test more high level things and assert on things like buffer contents. 15 + These assume you have a `nvim.test` set up in the normal config location. 16 + 17 + Run using `run_functional_tests.sh`. 18 + 19 + 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
··· 1 + local M = {} 2 + 3 + local testing = require "vclib.testing" 4 + 5 + --- Create a buffer with given contents. 6 + ---@param contents string Multiline string to set in buffer. 7 + ---@return integer bufnr The buffer number. 8 + function M.create_buffer(contents) 9 + local bufnr = vim.api.nvim_create_buf(false, true) 10 + local lines = testing.dedent_into_lines(contents) 11 + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) 12 + vim.api.nvim_set_current_buf(bufnr) 13 + return bufnr 14 + end 15 + 16 + --- Set cursor position. 17 + ---@param line integer Line number (1-indexed). 18 + ---@param col? integer Column number (0-indexed), defaults to 0. 19 + function M.set_cursor(line, col) 20 + col = col or 0 21 + vim.api.nvim_win_set_cursor(0, { line, col }) 22 + end 23 + 24 + --- Assert cursor is at specific line. 25 + ---@param expected_line integer Expected line number (1-indexed). 26 + ---@param msg? string Optional error message. 27 + function M.assert_cursor_at(expected_line, msg) 28 + local line = vim.api.nvim_win_get_cursor(0)[1] 29 + msg = msg or "Expected cursor at line " .. expected_line .. ", got " .. line 30 + assert(line == expected_line, msg) 31 + end 32 + 33 + --- Wait a bit for async updates to settle. 34 + ---@param ms? integer Milliseconds to wait (default 10). 35 + function M.wait_update(ms) 36 + ms = ms or 10 37 + vim.wait(ms, function() 38 + return false 39 + end) 40 + -- Process pending events 41 + vim.api.nvim_exec_autocmds("User", { pattern = "Wait" }) 42 + end 43 + 44 + --- Get buffer lines. 45 + ---@param bufnr integer Buffer number. 46 + ---@return string[] lines The buffer lines. 47 + function M.get_lines(bufnr) 48 + return vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) 49 + end 50 + 51 + --- Clean up buffer. 52 + ---@param bufnr integer Buffer number. 53 + function M.cleanup_buffer(bufnr) 54 + if vim.api.nvim_buf_is_valid(bufnr) then 55 + vim.api.nvim_buf_delete(bufnr, { force = true }) 56 + end 57 + end 58 + 59 + return M
+11
lua/vcmarkers_tests/functional/init.lua
··· 1 + local M = {} 2 + 3 + local testing = require "vclib.testing" 4 + 5 + function M.run() 6 + local test_modules = { 7 + } 8 + testing.run_tests(test_modules) 9 + end 10 + 11 + return M
+4
lua/vcmarkers_tests/init.lua
··· 11 11 testing.run_tests(test_modules) 12 12 end 13 13 14 + function M.run_functional() 15 + require("vcmarkers_tests.functional").run() 16 + end 17 + 14 18 return M
+21
run_functional_tests.sh
··· 1 + #!/bin/bash 2 + cd "$(dirname "$0")" 3 + 4 + while [[ $# -gt 0 ]]; do 5 + case "$1" in 6 + --filter | -f) 7 + export TEST_FILTER="$2" 8 + shift 2 9 + ;; 10 + --filter=*) 11 + export TEST_FILTER="${1#*=}" 12 + shift 13 + ;; 14 + *) 15 + shift 16 + ;; 17 + esac 18 + done 19 + 20 + export NVIM_APPNAME=nvim.test 21 + nvim --headless -c "lua require('vcmarkers_tests').run_functional()" -c "q" 2>&1