Files

1175 lines
44 KiB
Lua
Raw Permalink Normal View History

-- development/tests/test-keymaps.lua — driven by development/tests/test-keymaps.sh.
--
-- Headless Neovim harness for the buffer-local keymaps registered by
-- `ftplugin/vimwiki.vim` + `lua/nuwiki/keymaps.lua`. Each case sets up
-- the buffer, places the cursor, fires the key sequence via
-- `nvim_feedkeys`, waits for any LSP round-trip, and asserts the
-- expected post-state.
--
-- Pass/fail summary is written to the path passed as argv[1] so the
-- shell wrapper can read + render it without trying to capture nvim's
-- TUI output.
local OUT = vim.env.NUWIKI_KEYMAP_RESULTS or '/tmp/nuwiki-keymap-results.txt'
local out_lines = {}
local pass = 0
local fail = 0
local function record(ok, name, detail)
local suffix = (detail and detail ~= '') and ('' .. detail) or ''
table.insert(out_lines, (ok and 'PASS' or 'FAIL') .. ' ' .. name .. suffix)
if ok then pass = pass + 1 else fail = fail + 1 end
end
local function set_buf(lines)
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
end
local function get_lines()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end
local function get_line(n)
return vim.api.nvim_buf_get_lines(0, n - 1, n, false)[1] or ''
end
local function send(keys)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'x', false)
end
local function sleep(ms)
vim.cmd('sleep ' .. ms .. 'm')
end
--- Run one case: lines + cursor (1-based) + key sequence + expected
--- post-state. `wait_ms` defaults to 800 (enough for an LSP
--- executeCommand round-trip on a hot server).
local function run(name, opts)
local ok, err = pcall(function()
set_buf(opts.lines)
vim.api.nvim_win_set_cursor(0, opts.cursor or { 1, 0 })
send(opts.keys)
sleep(opts.wait_ms or 800)
local actual_lines = get_lines()
if opts.expect_lines then
if not vim.deep_equal(actual_lines, opts.expect_lines) then
error(string.format('lines mismatch\n expected: %s\n actual: %s',
vim.inspect(opts.expect_lines), vim.inspect(actual_lines)))
end
end
if opts.expect_line and opts.expect_at then
local got = get_line(opts.expect_at)
if got ~= opts.expect_line then
error(string.format('line %d mismatch\n expected: %q\n actual: %q',
opts.expect_at, opts.expect_line, got))
end
end
if opts.expect_cursor_line then
local lnum = vim.api.nvim_win_get_cursor(0)[1]
if lnum ~= opts.expect_cursor_line then
error(string.format('cursor line mismatch — expected %d, got %d',
opts.expect_cursor_line, lnum))
end
end
if opts.expect_buf_path then
local got = vim.api.nvim_buf_get_name(0)
if not got:find(opts.expect_buf_path, 1, true) then
error(string.format('buffer path mismatch\n expected substring: %q\n actual: %q',
opts.expect_buf_path, got))
end
end
end)
record(ok, name, ok and '' or tostring(err))
end
local function get_lsp_clients(opts)
local fn = vim.lsp.get_clients or vim.lsp.get_active_clients
if not fn then return {} end
return fn(opts)
end
local function wait_for_lsp(timeout_ms)
local deadline = vim.loop.now() + (timeout_ms or 5000)
while vim.loop.now() < deadline do
local clients = get_lsp_clients({ name = 'nuwiki', bufnr = 0 })
if #clients > 0 and clients[1].server_capabilities
and clients[1].server_capabilities.executeCommandProvider then
return clients[1]
end
sleep(100)
end
return nil
end
-- ===== Capture server log_message events =====
local server_log = {}
local orig_handler = vim.lsp.handlers['window/logMessage']
vim.lsp.handlers['window/logMessage'] = function(err, result, ctx, cfg)
if result and result.message then
table.insert(server_log, '[' .. tostring(result.type) .. '] ' .. result.message)
end
if orig_handler then return orig_handler(err, result, ctx, cfg) end
end
-- ===== Smoke: LSP attached =====
vim.defer_fn(function()
local client = wait_for_lsp()
if not client then
record(false, 'lsp.attached', 'no nuwiki client after 5s')
vim.fn.writefile(out_lines, OUT)
vim.cmd('qall!')
return
end
record(true, 'lsp.attached', 'client=' .. client.name)
-- ===== Documented command surface =====
-- Every command must be reachable in BOTH the canonical :Nuwiki* form
-- and the vimwiki-compatible :Vimwiki* form. The suffixes below are the
-- command list minus the prefix. :NuwikiInstall is the one exception — a
-- nuwiki-only maintenance command with no :Vimwiki* alias.
local both_forms = {
'Index', 'TabIndex', 'UISelect', 'Goto', 'FollowLink', 'Backlinks',
'SplitLink', 'VSplitLink', 'TabnewLink', 'TabDropLink', 'GoBackLink',
'NextLink', 'PrevLink', 'BaddLink', 'RenameFile', 'DeleteFile',
'MakeDiaryNote', 'TabMakeDiaryNote', 'MakeYesterdayDiaryNote',
'MakeTomorrowDiaryNote',
'DiaryIndex', 'DiaryGenerateLinks', 'DiaryNextDay', 'DiaryPrevDay',
'TOC', 'GenerateLinks', 'CheckLinks', 'SearchTags', 'GenerateTagLinks',
'RebuildTags', '2HTML', '2HTMLBrowse', 'All2HTML', 'Rss',
'NormalizeLink', 'RenumberList', 'RenumberAllLists',
'ListToggle', 'IncrementListItem', 'DecrementListItem',
'CatUrl', 'ShowVersion', 'Return', 'Var', 'Search',
}
for _, suffix in ipairs(both_forms) do
for _, prefix in ipairs({ 'Nuwiki', 'Vimwiki' }) do
local cmd = prefix .. suffix
local exists = vim.fn.exists(':' .. cmd) == 2
record(exists, 'surface.' .. cmd, exists and '' or (':' .. cmd .. ' not registered'))
end
end
do
local exists = vim.fn.exists(':NuwikiInstall') == 2
record(exists, 'surface.NuwikiInstall',
exists and '' or ':NuwikiInstall not registered')
end
-- Asymmetric / compat-only spellings: the canonical :Nuwiki* name differs
-- from the upstream :Vimwiki* name (or has no canonical counterpart because
-- nuwiki already exposes it under a clearer name).
local extra_surface = {
'NuwikiTableAlign', 'VimwikiTableAlignQ', 'VimwikiTableAlignW',
'NuwikiChangeSymbol', 'VimwikiChangeSymbolTo', 'VimwikiListChangeSymbolI',
'NuwikiChangeSymbolInList', 'VimwikiChangeSymbolInListTo',
'VimwikiDeleteLink', 'VimwikiRenameLink', 'VimwikiGenerateTags',
'NuwikiRemoveCheckbox', 'VimwikiRemoveSingleCB',
'NuwikiRemoveCheckboxInList', 'VimwikiRemoveCBInList',
}
for _, cmd in ipairs(extra_surface) do
local exists = vim.fn.exists(':' .. cmd) == 2
record(exists, 'surface.' .. cmd, exists and '' or (':' .. cmd .. ' not registered'))
end
do
local callable = type(require('nuwiki.commands').follow_link_drop) == 'function'
record(callable, 'direct.follow_link_drop_callable',
callable and '' or 'nuwiki.commands.follow_link_drop is not a function')
end
-- ===== Pure-Lua command invocation (cursor movement) =====
-- :NuwikiNextLink / :NuwikiPrevLink wrap the link-search motion and run
-- without the LSP, so we can assert exact cursor movement here.
do
local ok, err = pcall(function()
set_buf({ 'intro [[A]] more [[B]] end' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.cmd('NuwikiNextLink')
local c1 = vim.api.nvim_win_get_cursor(0)[2]
if c1 ~= 6 then error('NextLink #1 col=' .. c1 .. ' want 6') end
vim.cmd('NuwikiNextLink')
local c2 = vim.api.nvim_win_get_cursor(0)[2]
if c2 ~= 17 then error('NextLink #2 col=' .. c2 .. ' want 17') end
vim.cmd('VimwikiPrevLink')
local c3 = vim.api.nvim_win_get_cursor(0)[2]
if c3 ~= 6 then error('PrevLink col=' .. c3 .. ' want 6') end
end)
record(ok, 'invoke.next_prev_link_cursor_movement', ok and '' or tostring(err))
end
-- ===== Documented mapping surface =====
-- Every documented mapping must resolve to a buffer-local mapping in
-- the mode(s) the doc lists it under. `modes` is a string of mode
-- letters: n/x/o/i. The mouse group is opt-in — the harness enables it
-- via setup({ mappings = { mouse = true } }).
local function has_map(lhs, mode)
local d = vim.fn.maparg(lhs, mode, false, true)
return next(d) ~= nil and d.buffer == 1
end
local mapping_surface = {
-- Links
{ '<CR>', 'n' }, { '<S-CR>', 'n' }, { '<C-CR>', 'n' }, { '<C-S-CR>', 'n' },
{ '<M-CR>', 'n' }, { '<D-CR>', 'n' },
{ '<BS>', 'n' }, { '<Tab>', 'n' }, { '<S-Tab>', 'n' }, { '+', 'nx' },
{ '<CR>', 'x' }, -- visual normalize-link (== visual `+`)
-- Lists
{ '<C-Space>', 'nx' }, { '<C-@>', 'nx' }, { '<Nul>', 'nx' },
{ 'gnt', 'n' }, { 'gln', 'nx' }, { 'glp', 'nx' }, { 'glx', 'nx' },
{ 'glh', 'n' }, { 'gll', 'n' }, { 'gLh', 'n' }, { 'gLl', 'n' },
-- Upstream case-variant aliases of gLh/gLl/gLr.
{ 'gLH', 'n' }, { 'gLL', 'n' }, { 'gLR', 'n' },
{ 'glr', 'n' }, { 'gLr', 'n' }, { 'gl', 'n' }, { 'gL', 'n' },
{ 'gl-', 'n' }, { 'gL-', 'n' }, { 'gl*', 'n' }, { 'gL*', 'n' },
{ 'gl#', 'n' }, { 'gL#', 'n' }, { 'gl1', 'n' }, { 'gL1', 'n' },
{ 'gli', 'n' }, { 'gLi', 'n' }, { 'glI', 'n' }, { 'gLI', 'n' },
{ 'gla', 'n' }, { 'gLa', 'n' }, { 'glA', 'n' }, { 'gLA', 'n' },
{ 'o', 'n' }, { 'O', 'n' },
-- Headers
{ '=', 'n' }, { '-', 'n' }, { ']]', 'n' }, { '[[', 'n' },
{ ']=', 'n' }, { '[=', 'n' }, { ']u', 'n' }, { '[u', 'n' },
-- Tables
{ 'gqq', 'n' }, { 'gq1', 'n' }, { 'gww', 'n' }, { 'gw1', 'n' },
{ '<A-Left>', 'n' }, { '<A-Right>', 'n' },
-- Wiki / diary / export
{ '<Leader>ww', 'n' }, { '<Leader>ws', 'n' }, { '<Leader>wi', 'n' },
{ '<Leader>w<Leader>w', 'n' }, { '<Leader>w<Leader>y', 'n' },
{ '<Leader>w<Leader>t', 'n' }, { '<Leader>w<Leader>m', 'n' },
{ '<Leader>w<Leader>i', 'n' },
{ '<Leader>wn', 'n' }, { '<Leader>wd', 'n' }, { '<Leader>wr', 'n' },
{ '<Leader>wh', 'n' }, { '<Leader>whh', 'n' }, { '<Leader>wha', 'n' },
{ '<Leader>wc', 'nx' }, { '<C-Down>', 'n' }, { '<C-Up>', 'n' },
-- Mouse (opt-in)
{ '<2-LeftMouse>', 'n' }, { '<S-2-LeftMouse>', 'n' }, { '<C-2-LeftMouse>', 'n' },
{ '<MiddleMouse>', 'n' }, { '<RightMouse>', 'n' },
-- Text objects (operator-pending + visual)
{ 'ah', 'ox' }, { 'ih', 'ox' }, { 'aH', 'ox' }, { 'iH', 'ox' },
{ 'al', 'ox' }, { 'il', 'ox' }, { 'a\\', 'ox' }, { 'i\\', 'ox' },
{ 'ac', 'ox' }, { 'ic', 'ox' },
-- Insert-mode
{ '<CR>', 'i' }, { '<S-CR>', 'i' }, { '<Tab>', 'i' }, { '<S-Tab>', 'i' },
{ '<C-D>', 'i' }, { '<C-T>', 'i' },
{ '<C-L><C-J>', 'i' }, { '<C-L><C-K>', 'i' }, { '<C-L><C-M>', 'i' },
}
for _, entry in ipairs(mapping_surface) do
local lhs, modes = entry[1], entry[2]
for m in modes:gmatch('.') do
local ok = has_map(lhs, m)
record(ok, 'map[' .. m .. '].' .. lhs,
ok and '' or (lhs .. ' (' .. m .. ') not mapped buffer-local'))
end
end
-- ===== Config-driven buffer behaviors =====
-- autowriteall (default on) mirrors into Vim's global 'autowriteall' while
-- the wiki buffer is current.
record(vim.o.autowriteall == true, 'config.autowriteall_applied',
vim.o.autowriteall and '' or 'autowriteall not set on the wiki buffer')
-- table_auto_fmt wiring: with the option enabled, attaching a buffer
-- registers a buffer-local InsertLeave autocmd. (It's off in the harness
-- setup so the async re-align doesn't perturb the table-nav cases below, so
-- verify on a throwaway scratch buffer in its own window.)
do
local cfg = require('nuwiki.config')
cfg.options.table_auto_fmt = true
vim.cmd('new')
local sbuf = vim.api.nvim_get_current_buf()
require('nuwiki.ftplugin').attach(sbuf)
local found = false
for _, a in ipairs(vim.api.nvim_get_autocmds({ event = 'InsertLeave', buffer = sbuf })) do
if a.group_name and a.group_name:match('^nuwiki_taf_') then
found = true
break
end
end
record(found, 'config.table_auto_fmt_autocmd',
found and '' or 'attach did not register the InsertLeave autocmd when enabled')
cfg.options.table_auto_fmt = false
vim.cmd('bwipeout!')
end
-- :VimwikiVar key val sets the in-memory option.
do
vim.cmd('VimwikiVar testkey hello')
local v = require('nuwiki.config').options.testkey
record(v == 'hello', 'cmd.VimwikiVar_sets_option', 'options.testkey=' .. tostring(v))
end
-- Index / TabIndex / Var / ShowVersion are global (work outside a wiki
-- buffer). Open a throwaway scratch buffer and confirm they're visible.
do
vim.cmd('enew')
vim.bo.buftype = 'nofile'
local ok = vim.fn.exists(':VimwikiIndex') == 2
and vim.fn.exists(':VimwikiTabIndex') == 2
and vim.fn.exists(':VimwikiVar') == 2
and vim.fn.exists(':VimwikiShowVersion') == 2
record(ok, 'cmd.global_entry_points',
ok and '' or 'a global command is not visible outside a wiki buffer')
vim.cmd('bwipeout!')
end
-- auto_header: the function inserts `= Stem =` on an empty new wiki buffer,
-- and skips the wiki index page. Operate on dedicated buffer handles so the
-- harness's own buffer is untouched.
do
local wroot = require('nuwiki.config').wiki_cfg(0).root
local root = vim.fn.fnamemodify(vim.fn.expand(wroot), ':p')
if root:sub(-1) ~= '/' then root = root .. '/' end
local function ah_line(name)
local buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_buf_set_name(buf, name)
require('nuwiki.commands').auto_header(buf)
local line = vim.api.nvim_buf_get_lines(buf, 0, 1, false)[1] or ''
vim.api.nvim_buf_delete(buf, { force = true })
return line
end
-- A normal page (outside any wiki root) → header inserted.
local got = ah_line('/tmp/nuwiki-ah-plain/MyNewPage.wiki')
record(got == '= MyNewPage =', 'cmd.auto_header_inserts', 'line1=' .. got)
-- The diary index page → skipped (no header). (The wiki index itself is the
-- harness's open buffer, so use the diary index to avoid an E95 collision.)
local c = require('nuwiki.config').wiki_cfg(0)
local idx_line = ah_line(root .. c.diary_rel .. '/' .. c.diary_idx .. '.wiki')
record(idx_line == '', 'cmd.auto_header_skips_diary_index', 'line1=' .. idx_line)
end
-- ===== Lists =====
run('list.toggle_via_C-Space', {
lines = { '= test =', '- [ ] task' },
cursor = { 2, 0 },
keys = '<C-Space>',
expect_line = '- [X] task',
expect_at = 2,
})
run('list.toggle_via_C-@', {
lines = { '= test =', '- [ ] task' },
cursor = { 2, 0 },
keys = '<C-@>',
expect_line = '- [X] task',
expect_at = 2,
})
run('list.toggle_via_Nul', {
lines = { '= test =', '- [ ] task' },
cursor = { 2, 0 },
keys = '<Nul>',
expect_line = '- [X] task',
expect_at = 2,
})
run('list.cycle_via_gln', {
lines = { '- [ ] task' },
cursor = { 1, 0 },
keys = 'gln',
expect_line = '- [.] task',
expect_at = 1,
})
run('list.reject_via_glx', {
lines = { '- [ ] task' },
cursor = { 1, 0 },
keys = 'glx',
expect_line = '- [-] task',
expect_at = 1,
})
run('list.toggle_round_trip', {
lines = { '- [X] done' },
cursor = { 1, 0 },
keys = '<C-Space>',
expect_line = '- [ ] done',
expect_at = 1,
})
-- `glp` must cycle BACKWARD (regression for the glp==gln bug). From
-- `[.]` the backward step lands on `[ ]`, whereas `gln` would advance
-- to `[o]`.
run('list.cycle_back_via_glp', {
lines = { '- [.] task' },
cursor = { 1, 0 },
keys = 'glp',
expect_line = '- [ ] task',
expect_at = 1,
})
run('list.cycle_back_via_glp_wraps', {
-- `[ ]` backward wraps to the top of the progression (`[X]`).
lines = { '- [ ] task' },
cursor = { 1, 0 },
keys = 'glp',
expect_line = '- [X] task',
expect_at = 1,
})
-- ===== Change level (glh/gll) =====
run('list.indent_via_gll', {
lines = { '- item' },
cursor = { 1, 0 },
keys = 'gll',
expect_line = ' - item',
expect_at = 1,
})
run('list.dedent_via_glh', {
lines = { ' - item' },
cursor = { 1, 2 },
keys = 'glh',
expect_line = '- item',
expect_at = 1,
})
-- ===== Renumber (glr / gLr) =====
run('list.renumber_via_glr', {
lines = { '5. one', '9. two', '2. three' },
cursor = { 1, 0 },
keys = 'glr',
expect_lines = { '1. one', '2. two', '3. three' },
})
-- ===== Remove checkbox (bare gl item / gL whole list) =====
-- Bare `gl` strips the checkbox from the cursor's item, keeping the text.
run('list.remove_checkbox_item_via_gl', {
lines = { '= test =', '- [ ] task', '- [X] done' },
cursor = { 2, 0 },
keys = 'gl',
expect_line = '- task',
expect_at = 2,
})
-- Bare `gL` strips the checkbox from every item in the cursor's list.
run('list.remove_checkbox_list_via_gL', {
lines = { '- [ ] a', '- [X] b', '- [ ] c' },
cursor = { 1, 0 },
keys = 'gL',
expect_lines = { '- a', '- b', '- c' },
})
-- ===== Remove done (command-only: :NuwikiRemoveDone[!]) =====
-- `:NuwikiRemoveDone` removes done items from the cursor's list only; the
-- second list's done item survives.
run('list.remove_done_current_list_via_command', {
lines = {
'- [X] done a', '- [ ] todo a', '',
'paragraph', '',
'- [ ] todo b', '- [X] done b',
},
cursor = { 1, 0 },
keys = ':NuwikiRemoveDone<CR>',
expect_lines = {
'- [ ] todo a', '',
'paragraph', '',
'- [ ] todo b', '- [X] done b',
},
})
-- `:NuwikiRemoveDone!` sweeps the whole buffer regardless of cursor position.
run('list.remove_done_whole_buffer_via_command_bang', {
lines = {
'- [X] done a', '- [ ] todo a', '',
'paragraph', '',
'- [ ] todo b', '- [X] done b',
},
cursor = { 1, 0 },
keys = ':NuwikiRemoveDone!<CR>',
expect_lines = {
'- [ ] todo a', '',
'paragraph', '',
'- [ ] todo b',
},
})
-- ===== Next task (gnt) =====
run('list.gnt_jumps_to_unfinished', {
lines = { '- [X] done', '- [ ] todo', '- [ ] later' },
cursor = { 1, 0 },
keys = 'gnt',
expect_cursor_line = 2,
wait_ms = 600,
})
-- ===== Heading levels =====
run('heading.add_level_with_=', {
lines = { '= H1 =' },
cursor = { 1, 0 },
keys = '=',
expect_line = '== H1 ==',
expect_at = 1,
})
run('heading.remove_level_with_-', {
lines = { '== H2 ==' },
cursor = { 1, 0 },
keys = '-',
expect_line = '= H2 =',
expect_at = 1,
})
run('heading.add_level_clamps_at_6', {
lines = { '====== H6 ======' },
cursor = { 1, 0 },
keys = '=',
expect_line = '====== H6 ======', -- unchanged
expect_at = 1,
})
-- ===== Header nav (pure Lua, no LSP) =====
run('headers.]]_jumps_to_next', {
lines = { '= One =', 'body', '== Two ==', 'body', '= Three =' },
cursor = { 1, 0 },
keys = ']]',
expect_cursor_line = 3,
wait_ms = 100,
})
run('headers.[[_jumps_to_prev', {
lines = { '= One =', 'body', '== Two ==', 'body', '= Three =' },
cursor = { 5, 0 },
keys = '[[',
expect_cursor_line = 3,
wait_ms = 100,
})
run('headers.]u_jumps_to_parent', {
lines = { '= Parent =', '== Child ==', 'body' },
cursor = { 3, 0 },
keys = ']u',
expect_cursor_line = 1,
wait_ms = 100,
})
-- ===== Link nav (pure Lua) =====
run('links.<Tab>_jumps_to_next_wikilink', {
lines = { 'intro [[A]] more [[B]] end' },
cursor = { 1, 0 },
keys = '<Tab>',
expect_cursor_line = 1,
wait_ms = 100,
})
-- ===== <CR> two-step =====
run('cr.wraps_bare_word_first_press', {
lines = { 'MyPage rest' },
cursor = { 1, 3 },
keys = '<CR>',
expect_line = '[[MyPage]] rest',
expect_at = 1,
wait_ms = 200,
})
-- ===== Link helpers (Cluster C) =====
run('links.normalize_via_+', {
lines = { 'MyPage rest' },
cursor = { 1, 3 },
keys = '+',
expect_line = '[[MyPage]] rest',
expect_at = 1,
wait_ms = 200,
})
-- ===== Bullet continuation (o/O) =====
run('lists.o_continues_list_marker', {
lines = { '- first' },
cursor = { 1, 0 },
keys = 'o<Esc>',
expect_lines = { '- first', '- ' },
wait_ms = 100,
})
run('lists.o_continues_checkbox', {
lines = { '- [ ] first' },
cursor = { 1, 0 },
keys = 'o<Esc>',
expect_lines = { '- [ ] first', '- [ ] ' },
wait_ms = 100,
})
run('lists.O_continues_above', {
lines = { '- second' },
cursor = { 1, 0 },
keys = 'O<Esc>',
expect_lines = { '- ', '- second' },
wait_ms = 100,
})
-- ===== Insert-mode list bindings (Cluster 2) =====
run('insert.C-L_C-M_adds_checkbox', {
lines = { '- task' },
cursor = { 1, 0 },
keys = 'A<C-L><C-M><Esc>',
expect_line = '- [ ] task',
expect_at = 1,
wait_ms = 200,
})
run('insert.C-L_C-M_toggles_existing_checkbox', {
lines = { '- [ ] task' },
cursor = { 1, 0 },
keys = 'A<C-L><C-M><Esc>',
expect_line = '- [X] task',
expect_at = 1,
})
-- End-to-end regression for changeSymbol over LSP — direct call
-- (no keymap) so we can spot a stale `bin/nuwiki-ls` or a dispatch
-- error fast. Toggle has separate coverage above via `<C-Space>`.
do
local ok, err = pcall(function()
set_buf({ '- [ ] item', '- [ ] two' })
sleep(200)
vim.api.nvim_win_set_cursor(0, { 1, 0 })
require('nuwiki.commands').list_change_symbol('*', false)
sleep(1500)
local got = get_line(1)
if got ~= '* [ ] item' then
error(string.format('change_symbol failed: got %q', got))
end
end)
record(ok, 'direct.list_change_symbol_via_lsp', ok and '' or tostring(err))
end
run('insert.C-L_C-J_cycles_marker_forward', {
lines = { '- item' },
cursor = { 1, 0 },
keys = 'A<C-L><C-J><Esc>',
expect_line = '* item',
expect_at = 1,
wait_ms = 1500,
})
run('insert.C-L_C-K_cycles_marker_backward', {
-- From `-` going backward wraps to the end of the order (`I)`).
lines = { '- item' },
cursor = { 1, 0 },
keys = 'A<C-L><C-K><Esc>',
expect_line = 'I) item',
expect_at = 1,
wait_ms = 1500,
})
-- ===== Text objects (Cluster 3) =====
-- Exercise the pure helpers directly (cell ranges, heading block,
-- table bounds). The visual-mode integration is verified in a single
-- end-to-end case via mark inspection, which exercises the full
-- operator-pending path.
local function tobj_case(name, fn)
local ok, err = pcall(fn)
record(ok, name, ok and '' or tostring(err))
end
tobj_case('textobj.heading_block_section_only', function()
set_buf({ '= h1 =', 'a', '== h2 ==', 'b', '== h3 ==', 'c' })
local s, e = require('nuwiki.textobjects')._heading_block(1, false)
if not (s == 1 and e == 2) then
error(string.format('section_only: got (%s,%s) want (1,2)', s, e))
end
end)
tobj_case('textobj.heading_block_subtree', function()
set_buf({ '= h1 =', 'a', '== h2 ==', 'b', '== h3 ==', 'c' })
local s, e = require('nuwiki.textobjects')._heading_block(1, true)
if not (s == 1 and e == 6) then
error(string.format('subtree: got (%s,%s) want (1,6)', s, e))
end
end)
tobj_case('textobj.cell_ranges_three_cells', function()
local r = require('nuwiki.textobjects')._cell_ranges('| a | b | c |')
if #r ~= 3 then error('want 3 cells, got ' .. #r) end
-- Inside each cell, content includes the surrounding spaces.
if not (r[1][1] == 2 and r[2][1] > r[1][2] and r[3][1] > r[2][2]) then
error('cell ordering broken: ' .. vim.inspect(r))
end
end)
tobj_case('textobj.current_cell_picks_middle', function()
-- `| a | b | c |` cursor on the `b` (1-based col 8).
local idx = require('nuwiki.textobjects')._current_cell_for_line(
'| a | b | c |', 8)
if idx ~= 2 then error('expected cell 2, got ' .. tostring(idx)) end
end)
tobj_case('textobj.table_bounds_walks_contig_block', function()
set_buf({ 'before', '| a | b |', '| c | d |', '', 'after' })
vim.api.nvim_win_set_cursor(0, { 2, 0 })
local s, e = require('nuwiki.textobjects')._table_bounds(2)
if not (s == 2 and e == 3) then
error(string.format('want (2,3) got (%s,%s)', s, e))
end
end)
-- One end-to-end: operator-pending `dah` should delete the heading
-- section. This avoids the visual-mode `'<`/`'>` mark dance and
-- relies on Vim's actual operator pipeline to verify the keymap is
-- correctly wired into `omap`.
tobj_case('textobj.dah_deletes_heading_section', function()
set_buf({ '= h1 =', 'body', '= h2 =', 'rest' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
send('dah')
sleep(100)
local got = get_lines()
-- After deleting heading section (lines 1-2), buffer should be the
-- remaining two lines. There may be a trailing empty line depending
-- on linewise delete semantics; allow both shapes.
if not (vim.deep_equal(got, { '= h2 =', 'rest' })
or vim.deep_equal(got, { '', '= h2 =', 'rest' })) then
error('dah result: ' .. vim.inspect(got))
end
end)
-- ===== Smart <CR> (Cluster 5) =====
run('cr.continues_list_marker', {
lines = { '- first' },
cursor = { 1, 7 }, -- end of line
keys = 'A<CR>second<Esc>',
expect_lines = { '- first', '- second' },
wait_ms = 100,
})
run('cr.continues_checkbox', {
lines = { '- [ ] first' },
cursor = { 1, 11 },
keys = 'A<CR>second<Esc>',
expect_lines = { '- [ ] first', '- [ ] second' },
wait_ms = 100,
})
run('cr.breaks_on_empty_list_line', {
lines = { '- ' },
cursor = { 1, 2 },
keys = 'A<CR>plain<Esc>',
expect_lines = { '', 'plain' },
wait_ms = 100,
})
run('cr.adds_new_table_row', {
lines = { '| a | b |' },
cursor = { 1, 4 }, -- inside `a`
keys = 'A<CR>x<Esc>',
-- New row inserted below with empty cells; cursor jumps to first.
expect_lines = { '| a | b |', '|x | |' },
wait_ms = 100,
})
run('cr.table_link_cell_pipe_not_a_separator', {
-- Regression: the `|` inside `[[u|t]]` must NOT split the cell, so the
-- link stays intact and the row keeps its 2 columns (a 2-col fresh row,
-- not the mangled 3-col one the old naive `|` scan produced).
lines = { '| a | [[u|t]] |' },
cursor = { 1, 4 },
keys = 'A<CR>x<Esc>',
expect_lines = { '| a | [[u|t]] |', '|x | |' },
wait_ms = 100,
})
-- ===== Insert-mode table navigation (Cluster 6) =====
run('tab.next_cell_in_table', {
lines = { '| a | b |' },
cursor = { 1, 2 }, -- inside cell `a`
keys = 'A<Tab>x<Esc>',
-- After A: cursor at end. <Tab>: no cell-start strictly after end
-- so creates new row. Try cursor on inside-first-cell case below.
-- Here cursor at end has no next cell so a new row is added.
expect_lines = { '| a | b |', '|x | |' },
wait_ms = 100,
})
run('tab.from_first_cell_moves_to_second', {
lines = { '| a | b |' },
cursor = { 1, 0 },
keys = 'lli<Tab>x<Esc>',
-- `ll` from col 0 → col 2 (on `a`). `i` enters insert. `<Tab>`
-- jumps to col after next `|`. `x` types in second cell.
expect_lines = { '| a |x b |' },
wait_ms = 100,
})
run('tab.cycles_to_next_row_when_not_last', {
lines = { '| a | b |', '|---|---|', '| c | d |' },
cursor = { 1, 6 }, -- inside last cell of header row
keys = 'i<Tab>x<Esc>',
-- Past the final cell of row 1: skip separator, land in first cell of row 3.
expect_lines = { '| a | b |', '|---|---|', '|x c | d |' },
wait_ms = 100,
})
run('tab.inserts_row_only_when_on_last_row', {
lines = { '| a | b |', '|---|---|', '| c | d |' },
cursor = { 3, 6 }, -- inside last cell of last data row
keys = 'i<Tab>x<Esc>',
expect_lines = { '| a | b |', '|---|---|', '| c | d |', '|x | |' },
wait_ms = 100,
})
run('shift_tab.prev_cell_in_table', {
lines = { '| a | b |' },
cursor = { 1, 6 }, -- inside cell `b`
keys = 'i<S-Tab>x<Esc>',
-- Cursor lands just after the previous cell's `|`; typing `x`
-- inserts at col 2 (before the leading space inside cell 1).
expect_lines = { '|x a | b |' },
wait_ms = 100,
})
run('tab.outside_table_passes_through', {
lines = { 'plain text' },
cursor = { 1, 0 },
keys = 'i<Tab>x<Esc>',
-- Default Tab inserts a literal tab.
expect_lines = { '\tx' .. 'plain text' },
wait_ms = 100,
})
-- ===== Diary nav =====
-- Tested via the LSP open-* responses; can't fully validate without
-- a populated diary, but at least confirm the maps fire without
-- error.
-- ===== Colorize commands pass their {color} arg (regression) =====
-- :VimwikiColorize / :NuwikiColorize are -nargs=1; the Neovim defs used to
-- call colorize() without <q-args>, silently dropping the colour and
-- prompting instead. Run the real commands and assert the colour lands.
tobj_case('cmd.VimwikiColorize_uses_arg', function()
set_buf({ 'word here' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.cmd('VimwikiColorize red')
local got = vim.api.nvim_get_current_line()
if got ~= '<span style="color:red">word</span> here' then
error('VimwikiColorize dropped its arg: ' .. got)
end
end)
tobj_case('cmd.NuwikiColorize_uses_arg', function()
set_buf({ 'second word' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.cmd('NuwikiColorize #00ff00')
local got = vim.api.nvim_get_current_line()
if got ~= '<span style="color:#00ff00">second</span> word' then
error('NuwikiColorize dropped its arg: ' .. got)
end
end)
-- Establish a stale visual selection, then confirm the normal-mode command
-- still wraps the cword (not the leftover selection) — the visualmode()
-- heuristic regression.
tobj_case('cmd.Colorize_ignores_stale_visual_selection', function()
set_buf({ 'alpha beta gamma' })
vim.cmd('normal! 0vee\27') -- select 'alpha beta', leave marks behind
vim.api.nvim_win_set_cursor(0, { 1, 11 }) -- on 'gamma'
vim.cmd('VimwikiColorize blue')
local got = vim.api.nvim_get_current_line()
if got ~= 'alpha beta <span style="color:blue">gamma</span>' then
error('command wrapped stale selection instead of cword: ' .. got)
end
end)
-- The visual mapping path (explicit visual=true) wraps the selection.
tobj_case('colorize.visual_wraps_selection', function()
set_buf({ 'one two three' })
vim.cmd('normal! 0wviw\27') -- visually select 'two', marks set on exit
require('nuwiki.commands').colorize('red', true)
local got = vim.api.nvim_get_current_line()
if got ~= 'one <span style="color:red">two</span> three' then
error('visual colorize did not wrap selection: ' .. got)
end
end)
-- Invoking the command with a range (`:'<,'>VimwikiColorize`, as Vim builds
-- it when you select then type the command) must not error (-range) and
-- wraps the selection.
tobj_case('cmd.Colorize_range_wraps_selection', function()
set_buf({ 'pick this word' })
vim.cmd('normal! 0wviw\27') -- select 'this'
vim.cmd("'<,'>VimwikiColorize orange")
local got = vim.api.nvim_get_current_line()
if got ~= 'pick <span style="color:orange">this</span> word' then
error('ranged command did not wrap selection: ' .. got)
end
end)
-- Colour spans are concealed down to their coloured text. Put the span on a
-- non-cursor line so concealcursor (=c) doesn't reveal it, then refresh.
tobj_case('colorize.conceal_hides_tags_shows_text', function()
set_buf({ 'plain line', '<span style="color:red">word</span> tail' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.fn['nuwiki#colors#refresh']()
local l = vim.fn.getline(2)
local wcol = (l:find('word')) -- 1-based
local open = vim.fn.synconcealed(2, 1)[1]
local close = vim.fn.synconcealed(2, (l:find('</span>')))[1]
local word = vim.fn.synconcealed(2, wcol)[1]
local grp = vim.fn.synIDattr(vim.fn.synID(2, wcol, 1), 'name')
if not (open == 1 and close == 1 and word == 0 and grp == 'nuwikiColorSpan_red') then
error(string.format('open=%s close=%s word=%s grp=%s', open, close, word, grp))
end
end)
-- ===== Visual-range list commands + normalize-visual (regression) =====
-- :N,MVimwikiToggleListItem toggles every checkbox in the range (server,
-- one request per line; wait for the edits to land).
tobj_case('cmd.toggle_list_item_range', function()
set_buf({ '- [ ] a', '- [ ] b', '- [ ] c' })
vim.cmd('1,3VimwikiToggleListItem')
local done = vim.wait(2000, function()
for _, l in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
if not l:match('%[[xX]%]') then return false end
end
return true
end, 30)
if not done then
error('range toggle incomplete: ' .. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false)))
end
end)
-- `:1,3VimwikiToggleRejectedListItem` — now -range (was bare → E481 on a
-- ranged invocation, and cursor-only). Each line should gain a rejected
-- checkbox `[-]`.
tobj_case('cmd.reject_list_item_range', function()
set_buf({ '- [ ] a', '- [ ] b', '- [ ] c' })
vim.cmd('1,3VimwikiToggleRejectedListItem')
local done = vim.wait(2000, function()
for _, l in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
if not l:match('%[%-%]') then return false end
end
return true
end, 30)
if not done then
error('range reject incomplete: ' .. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false)))
end
end)
-- `:1,2VimwikiRemoveDone` — now -range (was -bang only → E481 on a ranged
-- invocation). Only done items within the range are removed; line-2 `[X]`
-- (0-indexed) outside [0,1] survives.
tobj_case('cmd.remove_done_range', function()
set_buf({ '- [X] a', '- [ ] b', '- [X] c' })
vim.cmd('1,2VimwikiRemoveDone')
local done = vim.wait(2000, function()
local ls = vim.api.nvim_buf_get_lines(0, 0, -1, false)
-- line-0 done item gone (2 lines left), line-2 done item still present.
return #ls == 2 and ls[#ls]:match('%[X%] c')
end, 30)
if not done then
error('ranged remove-done wrong: ' .. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false)))
end
end)
-- `:VimwikiTable {cols} [rows]` — now -nargs=* (was -nargs=1, which dropped
-- the args entirely). A 4-col table has 5 pipes per row; 3 data rows give
-- header + separator + 3 = 5 table lines.
tobj_case('cmd.VimwikiTable_passes_cols_and_rows', function()
set_buf({ '' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.cmd('VimwikiTable 4 3')
local tbl = {}
local done = vim.wait(2000, function()
tbl = {}
for _, l in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
if l:find('|', 1, true) then tbl[#tbl + 1] = l end
end
return #tbl >= 5
end, 30)
if not done then
error('table not inserted: ' .. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false)))
end
local pipes = select(2, tbl[1]:gsub('|', ''))
if pipes ~= 5 then
error('want 4 cols (5 pipes), got ' .. pipes .. ': ' .. tbl[1])
end
if #tbl ~= 5 then
error('want 5 table lines (hdr+sep+3 rows), got ' .. #tbl)
end
end)
-- The Neovim :Vimwiki*Link Ex-commands used to dispatch to raw
-- vim.lsp.buf.definition(), bypassing the bare-word → [[link]] wrap that the
-- Vim branch and the <CR> mapping do. They now route through
-- follow_link_or_create; the wrap is a pure client-side buffer edit (no LSP),
-- so it's the headlessly-reliable observable.
tobj_case('cmd.VimwikiFollowLink_wraps_bare_word', function()
set_buf({ 'word here' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.cmd('VimwikiFollowLink')
local got = vim.api.nvim_get_current_line()
if got ~= '[[word]] here' then
error('VimwikiFollowLink did not wrap bare word: ' .. got)
end
end)
tobj_case('cmd.VimwikiSplitLink_wraps_bare_word', function()
set_buf({ 'word here' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.cmd('VimwikiSplitLink')
local got = vim.api.nvim_get_current_line()
vim.cmd('only') -- drop the split this command opened
if got ~= '[[word]] here' then
error('VimwikiSplitLink did not wrap bare word: ' .. got)
end
end)
-- `:[range]VimwikiListChangeLvl {dir} [plus_children]` — now -range -nargs=+
-- (was -nargs=?, range-less). A 1,3 range with `increase` must indent the
-- items that have somewhere to nest (the 2nd item under the 1st).
tobj_case('cmd.ListChangeLvl_range_indents', function()
set_buf({ '- a', '- b', '- c' })
vim.cmd('1,3VimwikiListChangeLvl increase 0')
local done = vim.wait(2000, function()
local l = vim.api.nvim_buf_get_lines(0, 0, -1, false)
return l[2] ~= nil and l[2]:match('^%s%s*%-') ~= nil
end, 30)
if not done then
error('range list-change-lvl did not indent: '
.. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false)))
end
end)
-- `:[range]VimwikiChangeSymbolTo {sym}` — now -range -nargs=1. A 1,3 range
-- must set every item's marker to the given symbol.
tobj_case('cmd.ChangeSymbolTo_range_sets_marker', function()
set_buf({ '- a', '- b', '- c' })
vim.cmd('1,3VimwikiChangeSymbolTo *')
local done = vim.wait(2000, function()
local l = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for _, ln in ipairs(l) do
if not ln:match('^%*%s') then return false end
end
return true
end, 30)
if not done then
error('range change-symbol did not set all markers: '
.. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false)))
end
end)
-- `:VimwikiGenerateLinks [rel_path]` — now -nargs=? (was bare; an arg raised
-- E488). Both forms must dispatch without a Vim-level command error.
tobj_case('cmd.GenerateLinks_accepts_optional_path', function()
set_buf({ '= page =' })
local ok1 = pcall(vim.cmd, 'VimwikiGenerateLinks')
local ok2 = pcall(vim.cmd, 'VimwikiGenerateLinks subdir')
if not (ok1 and ok2) then
error('GenerateLinks rejected an arg: ok1=' .. tostring(ok1) .. ' ok2=' .. tostring(ok2))
end
end)
-- :NuwikiGenerateTags alias must exist (parity with :VimwikiGenerateTags).
tobj_case('cmd.NuwikiGenerateTags_exists', function()
if vim.fn.exists(':NuwikiGenerateTags') ~= 2 then
error(':NuwikiGenerateTags not defined')
end
end)
-- Diary-note family carries -count=0 (vimwiki's wiki selector), so
-- `:2VimwikiMakeDiaryNote` selects wiki #2 instead of raising E481.
tobj_case('cmd.VimwikiMakeDiaryNote_has_count', function()
local c = vim.api.nvim_buf_get_commands(0, {}).VimwikiMakeDiaryNote
if not c then error(':VimwikiMakeDiaryNote not defined') end
if c.count == nil or c.count == false then
error('VimwikiMakeDiaryNote missing -count: ' .. vim.inspect(c))
end
end)
-- `:VimwikiNormalizeLink 1` (the arg is upstream's visual flag; the command
-- is -nargs=? not -range, so no `'<,'>`) wraps the last visual selection.
tobj_case('cmd.normalize_link_visual_wraps_selection', function()
set_buf({ 'one two three' })
vim.cmd('normal! 0wviw\27') -- select 'two', leave visual (sets '<,'> marks)
vim.cmd('VimwikiNormalizeLink 1')
local got = vim.api.nvim_get_current_line()
if got ~= 'one [[two]] three' then
error('visual normalize did not wrap selection: ' .. got)
end
end)
-- Visual <CR> mapping wraps the selection (upstream parity with visual `+`).
-- Select via `normal!` (sets the '<,'> marks reliably), then `gv` reselects
-- and the fed <CR> fires the x-mode mapping.
tobj_case('map.visual_cr_wraps_selection', function()
set_buf({ 'alpha beta gamma' })
vim.cmd('normal! 0wviw\27') -- select 'beta', leave visual → marks set
send('gv<CR>')
local got = vim.api.nvim_get_current_line()
if got ~= 'alpha [[beta]] gamma' then
error('visual <CR> did not wrap selection: ' .. got)
end
end)
-- Insert <S-CR> continues a list item with no marker, aligned under the text.
-- Test the `<expr>` handler directly — `<S-CR>` doesn't round-trip through
-- headless feedkeys, but the handler is what the mapping invokes.
tobj_case('map.insert_shift_cr_multiline', function()
local cr = vim.api.nvim_replace_termcodes('<CR>', true, false, true)
set_buf({ '- item' }) -- "- " is 2 cols → continuation aligns at column 2
local got = require('nuwiki.commands').smart_shift_return()
if got ~= cr .. ' ' then
error('S-CR (bullet) wrong: ' .. vim.inspect(got))
end
set_buf({ '- [ ] item' }) -- "- [ ] " is 6 cols
got = require('nuwiki.commands').smart_shift_return()
if got ~= cr .. ' ' then
error('S-CR (checkbox) wrong: ' .. vim.inspect(got))
end
set_buf({ 'plain text' }) -- not a list → plain <CR>
got = require('nuwiki.commands').smart_shift_return()
if got ~= cr then
error('S-CR (non-list) should be plain CR: ' .. vim.inspect(got))
end
end)
-- ===== Configurable map_prefix (vimwiki g:vimwiki_map_prefix) =====
-- Overriding map_prefix must relocate the whole <prefix>* family. We attach
-- to a throwaway scratch buffer with a custom prefix and assert the new
-- bindings exist there while the default <Leader>w* ones do not.
tobj_case('map_prefix.relocates_wiki_family', function()
local config = require('nuwiki.config')
local keymaps = require('nuwiki.keymaps')
local saved = config.options.map_prefix
config.options.map_prefix = '<Leader>n'
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_current_buf(buf)
local ok, err = pcall(function()
keymaps.attach(buf, { enabled = true, wiki_prefix = true, links = true, html_export = true })
local function bmap(lhs)
local d = vim.fn.maparg(lhs, 'n', false, true)
return not vim.tbl_isempty(d) and d.buffer == 1
end
for _, lhs in ipairs({
'<Leader>nw', '<Leader>nt', '<Leader>n<Leader>w', '<Leader>nr', '<Leader>nh', '<Leader>nha',
}) do
if not bmap(lhs) then error('relocated map missing: ' .. lhs) end
end
if bmap('<Leader>ww') then error('<Leader>ww still bound under custom prefix') end
end)
-- Always restore global state so later cases see the default prefix.
config.options.map_prefix = saved
vim.api.nvim_buf_delete(buf, { force = true })
if not ok then error(err) end
end)
-- ===== Global (non-buffer) entry-point diary maps =====
-- init.lua _setup_global_mappings ran during setup(). Regression guard for
-- the audit-found bug: <prefix><Leader>t must be today-in-a-tab and
-- <prefix><Leader>m must be tomorrow (matching the Vim global side +
-- upstream), not the old wiring that dropped `m` and bound `t` to tomorrow.
-- Query in a scratch (non-vimwiki) buffer so the buffer-local maps don't
-- shadow the globals.
tobj_case('global_maps.diary_tab_and_tomorrow_targets', function()
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_current_buf(buf)
local function gdesc(lhs)
local d = vim.fn.maparg(lhs, 'n', false, true)
if vim.tbl_isempty(d) then return nil end
return d.desc or ''
end
local ok, err = pcall(function()
local t = gdesc('<Leader>w<Leader>t')
local m = gdesc('<Leader>w<Leader>m')
if not t then error('<Leader>w<Leader>t global map missing') end
if not m then error('<Leader>w<Leader>m global map missing (tomorrow)') end
if not t:find('tab') then error('<Leader>w<Leader>t should be today-in-tab, desc=' .. t) end
if not m:find('tomorrow') then error('<Leader>w<Leader>m should be tomorrow, desc=' .. m) end
end)
vim.api.nvim_buf_delete(buf, { force = true })
if not ok then error(err) end
end)
-- ===== Wiki picker (config-driven, no LSP) =====
-- The picker must build its list from config so it works from any buffer
-- before the server attaches.
tobj_case('wiki_select.config_list_reads_g_var', function()
vim.g.nuwiki_wikis = {
{ name = 'Personal', root = '/tmp/nuwiki-a' },
{ name = 'Work', root = '/tmp/nuwiki-b', file_extension = 'md' },
}
local list = require('nuwiki.config').wiki_list()
vim.g.nuwiki_wikis = nil
if #list ~= 2 then error('want 2 wikis, got ' .. #list) end
if list[1].name ~= 'Personal' or list[2].name ~= 'Work' then
error('names/order broken: ' .. vim.inspect(list))
end
if list[2].ext ~= '.md' then
error('per-wiki extension not honoured: ' .. tostring(list[2].ext))
end
end)
-- ===== Wrap up =====
table.insert(out_lines, '')
-- Dump captured server log_messages only on failure — useful for
-- diagnosing dispatch errors that the LSP swallows into log_message.
if fail > 0 and #server_log > 0 then
table.insert(out_lines, '--- server log_messages ---')
for _, l in ipairs(server_log) do
table.insert(out_lines, l)
end
table.insert(out_lines, '')
end
table.insert(out_lines, string.format('SUMMARY: %d passed, %d failed', pass, fail))
vim.fn.writefile(out_lines, OUT)
vim.cmd(fail == 0 and 'qall!' or 'cquit!')
end, 1500)