-- development/tests/test-global-shorthand.lua — Neovim client global -- shorthand: a per-wiki setting given once at the top level (setup() or -- g:nuwiki_) 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_ 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 (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 local f = assert(io.open(os.getenv('NUWIKI_GS_OUT'), 'w')) f:write(table.concat(out, '\n') .. '\n') f:close() vim.cmd('qa!')