Files
nuwiki/development/tests/test-global-shorthand.lua
T
gffranco 0d1a73a3ba
CI / cargo fmt --check (push) Failing after 11s
CI / cargo clippy (push) Successful in 32s
CI / cargo test (push) Successful in 57s
CI / editor keymaps (push) Successful in 1m33s
feat(config): bridge setup({wikis}) to g:nuwiki_wikis for VimL plugins
A Lua-only `setup({ wikis = … })` config is invisible to the VimL side:
the buffer helpers in autoload/nuwiki/config.vim and the vimwiki compat
shim (autoload/vimwiki/vars.vim, which third-party plugins like
vimwiki-sync call via vimwiki#vars#get_wikilocal) read g:nuwiki_wikis. So
a Neovim user who migrated from g:vimwiki_list to native setup({wikis})
would break vimwiki-sync (it'd resolve the default ~/vimwiki).

setup() now publishes the resolved wiki list to g:nuwiki_wikis when the
config came from setup() opts (the only case VimL can't already see —
g:nuwiki_wikis / g:vimwiki_list configs are global and visible). Verified
vimwiki#vars#get_wikilocal('path', n) returns the right roots from a
pure-Lua setup() config. test-global-shorthand grows two bridge checks
(17). Goldens + keymap harnesses green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 01:34:24 +00:00

88 lines
3.6 KiB
Lua

-- development/tests/test-global-shorthand.lua — Neovim client global
-- shorthand: a per-wiki setting given once at the top level (setup() or
-- g:nuwiki_<key>) is folded into every wiki as a default, and a per-wiki
-- value overrides it. Mirror of the Vim test-vimwiki-compat checks.
--
-- Writes PASS/FAIL lines to $NUWIKI_GS_OUT; the wrapper fails on any FAIL.
local config = require('nuwiki.config')
local lsp = require('nuwiki.lsp')
local out = {}
local function check(desc, cond)
table.insert(out, (cond and 'PASS ' or 'FAIL ') .. desc)
end
-- ----- setup() top-level scalar folds into every wiki; per-wiki wins -----
config.apply({
toc_header_level = 2,
html_header_numbering = 2,
wikis = {
{ root = '/tmp/one', name = 'One' },
{ root = '/tmp/two', name = 'Two', toc_header_level = 3 },
},
})
local io1 = lsp.init_options()
check('w0 inherits global level', io1.wikis[1].toc_header_level == 2)
check('w0 inherits numbering', io1.wikis[1].html_header_numbering == 2)
check('w1 per-wiki override wins', io1.wikis[2].toc_header_level == 3)
check('w1 still inherits numbering', io1.wikis[2].html_header_numbering == 2)
-- The user's setup table must not be mutated by the fold.
check('no mutation of user wikis', config.user.wikis[1].toc_header_level == nil)
-- ----- built-in defaults are NOT folded (only explicit user values) -----
config.apply({
wikis = { { root = '/tmp/x', name = 'X' } },
})
local io2 = lsp.init_options()
check('default toc_header not folded', io2.wikis[1].toc_header == nil)
check('default level not folded', io2.wikis[1].toc_header_level == nil)
-- ----- g:nuwiki_<key> acts as a global too -----
config.apply({
wikis = { { root = '/tmp/y', name = 'Y' } },
})
vim.g.nuwiki_toc_header_level = 5
local io3 = lsp.init_options()
check('g:nuwiki_ global folds', io3.wikis[1].toc_header_level == 5)
vim.g.nuwiki_toc_header_level = nil
-- ----- upstream vim.g.vimwiki_list drop-in (the lazy.nvim vimwiki-swap case) --
config.apply({}) -- setup() with no native config
vim.g.vimwiki_list = {
{ path = '~/.vimwiki/personal', path_html = '~/public_html/personal', auto_export = 1 },
{ path = '~/.vimwiki/work' },
}
vim.g.vimwiki_toc_header_level = 2
local io4 = lsp.init_options()
check('vimwiki_list -> 2 wikis', io4.wikis ~= nil and #io4.wikis == 2)
check('path -> root', io4.wikis[1].root == '~/.vimwiki/personal')
check('path_html -> html_path', io4.wikis[1].html_path == '~/public_html/personal')
check('vimwiki global folds', io4.wikis[1].toc_header_level == 2)
check('w2 root', io4.wikis[2].root == '~/.vimwiki/work')
-- Buffer-side commands (<Leader>ww) resolve the same wikis.
check('wiki_list reads vimwiki_list', config.wiki_list()[1].root == '~/.vimwiki/personal')
-- Native g:nuwiki_wikis wins over g:vimwiki_list.
vim.g.nuwiki_wikis = { { root = '~/native', name = 'native' } }
local io5 = lsp.init_options()
check('native g:nuwiki_wikis wins', #io5.wikis == 1 and io5.wikis[1].root == '~/native')
vim.g.nuwiki_wikis = nil
vim.g.vimwiki_list = nil
vim.g.vimwiki_toc_header_level = nil
-- ----- setup({ wikis }) bridges the Lua config to VimL (g:nuwiki_wikis) -----
-- So buffer-side VimL helpers + the vimwiki-sync compat shim see the same
-- wikis as the LSP, even though setup() config lives only in Lua.
require('nuwiki').setup({ wikis = { { root = '/tmp/a', name = 'A' }, { root = '/tmp/b' } } })
check('setup() bridges to g:nuwiki_wikis',
vim.g.nuwiki_wikis ~= nil and #vim.g.nuwiki_wikis == 2)
check('bridged wiki root visible to VimL',
vim.g.nuwiki_wikis and vim.g.nuwiki_wikis[1].root == '/tmp/a')
vim.g.nuwiki_wikis = nil
local f = assert(io.open(os.getenv('NUWIKI_GS_OUT'), 'w'))
f:write(table.concat(out, '\n') .. '\n')
f:close()
vim.cmd('qa!')