From 4431caf7ff8c0eab51d1d0878fc7fb4f12f8f051 Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Wed, 12 Aug 2020 10:35:40 -0400 Subject: [PATCH] Fix: Vars.vim error in parsing: key not present (Issue #980) --- autoload/vimwiki/vars.vim | 21 +++++---- test/config_commentstring.vader | 2 +- test/config_vars.vader | 75 +++++++++++++++++++++++++++++++++ test/independent_runs/map.vader | 2 +- test/link_creation.vader | 2 +- test/link_generation.vader | 2 + test/vimrc | 29 ++++++++++--- 7 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 test/config_vars.vader diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim index 74e4ade..06373bb 100644 --- a/autoload/vimwiki/vars.vim +++ b/autoload/vimwiki/vars.vim @@ -343,8 +343,8 @@ endfunction " Populate local variable <- user & default " Called: s:vimwiki#vars#init function! s:populate_wikilocal_options() abort - " Dev: if type is dict, - " -- the default dict gets extended and not replaced: keys are not deleted + " TODO mutualise the g:vimwiki loop and the wiki_list + " -- after tests on specific cases (format_tag and list_margin) " Init local variable container let g:vimwiki_wikilocal_vars = [] @@ -415,8 +415,12 @@ function! s:populate_wikilocal_options() abort if exists('g:vimwiki_'.key) " Check type call s:check_users_value(key, g:vimwiki_{key}, default_values[key], 1) - " Update if dict - if default_values[key]['type'] == type({}) + " List margin + if key ==# 'list_margin' + let s:margin_set_by_user = 1 + endif + " Extend Tag format + if key ==# 'tag_format' let default_wiki_settings[key] = default_values[key].default call extend(default_wiki_settings[key], g:vimwiki_{key}) " Set if other var @@ -433,16 +437,17 @@ function! s:populate_wikilocal_options() abort for users_wiki_settings in g:vimwiki_list let new_wiki_settings = {} for key in keys(default_values) + " Key present if has_key(users_wiki_settings, key) call s:check_users_value(key, users_wiki_settings[key], default_values[key], 0) + " Set list margin if key ==# 'list_margin' let s:margin_set_by_user = 1 endif - " Update if dict - if default_values[key]['type'] == type({}) + " Extend Tag format + if key ==# 'tag_format' let new_wiki_settings[key] = extend({}, default_values[key].default) - let new_wiki_settings[key] = extend(new_wiki_settings.key, users_wiki_settings[key]) - " Set if other var + let new_wiki_settings[key] = extend(new_wiki_settings[key], users_wiki_settings[key]) else let new_wiki_settings[key] = users_wiki_settings[key] endif diff --git a/test/config_commentstring.vader b/test/config_commentstring.vader index a216cef..9a0aa26 100644 --- a/test/config_commentstring.vader +++ b/test/config_commentstring.vader @@ -1,5 +1,5 @@ # Test comment string PR #946 -# TODO try default +# TODO try default # TODO try editing other buffer #Execute (default commenstring, ft vimwiki): # AssertEqual &filetype[0], 't' diff --git a/test/config_vars.vader b/test/config_vars.vader new file mode 100644 index 0000000..5e36f15 --- /dev/null +++ b/test/config_vars.vader @@ -0,0 +1,75 @@ +# Test variable management (should be small) +# Issue #980 + + +Given txt (txt): + txt + +Execute (VimWei vars #980): + call CopyResources() + " Set + call UnloadVimwiki() + let wiki = {} + let wiki.name = 'ChenWei 🦊VimwikiMd @^%@!*#&^' + let wiki.path = $HOME . '/testmarkdown' + let wiki.ext = '.md' + let wiki.syntax = 'markdown' + let wiki.nested_syntaxes = {'python': 'python'} + + " Make other tests crash + "let wiki.links_space_char = '_' + "let wiki.list_margin = 0 + "let wiki.auto_toc = 1 + "let wiki.auto_tags = 1 + "let wiki.auto_generate_tags = 1 + + let g:vimwiki_list = [wiki] + let g:vimwiki_ext2syntax = {'.md': 'markdown'} + let g:vimwiki_global_ext = 1 + let g:vimwiki_autowriteall = 1 + let g:vimwiki_auto_chdir = 1 + let g:vimwiki_folding = 'expr' + call LoadVimwiki() + + " Log + Log 'Path (Current): ' . getcwd() + Log 'File: (Buffer)' . @% + Log 'List (Wiki): ' . string(g:vimwiki_list) + Log '' + Log 'Local (Vars):' + Log g:vimwiki_wikilocal_vars + + " Work + edit $HOME/testmarkdown/index.md + + " Assert + AssertEqual '/home/vimtest/testmarkdown_cwd', getcwd() . '_cwd' + AssertEqual '0_wiki_nr', vimwiki#vars#get_bufferlocal('wiki_nr') . '_wiki_nr' + AssertEqual 'markdown_syntax', vimwiki#vars#get_wikilocal('syntax') . '_syntax' + AssertEqual '0_margin', vimwiki#vars#get_wikilocal('list_margin') . '_margin' + Log 'Path (Current): ' . getcwd() + Log 'File (Buffer):' . @% + bprevious + Log 'Path (Current): ' . getcwd() + Log 'File (Buffer):' . @% + bdelete index.md + + " Clean + Log 'Clean up' + cd /testplugin + unlet g:vimwiki_list + unlet g:vimwiki_ext2syntax + unlet g:vimwiki_global_ext + unlet g:vimwiki_autowriteall + unlet g:vimwiki_auto_chdir + unlet g:vimwiki_folding + unlet wiki + Log 'Path (Current): ' . getcwd() + Log 'File (Buffer):' . @% + call ReloadVimwiki() + Log g:vimwiki_wikilocal_vars + +Expect (txt): + txt + +# vim: sw=2:foldlevel=30:foldmethod=indent: diff --git a/test/independent_runs/map.vader b/test/independent_runs/map.vader index 0057c4d..834b4ab 100644 --- a/test/independent_runs/map.vader +++ b/test/independent_runs/map.vader @@ -30,7 +30,7 @@ Execute (Configure: Set vimwiki list to markdown resource): Log "Declare my extension for temporary wiki" let g:vimwiki_ext2syntax = {'.md': 'markdown'} - Log "Reload vimwiki <- vader_setup.vader" + Log "Reload vimwiki" nmapclear " UNlet what can be diff --git a/test/link_creation.vader b/test/link_creation.vader index 46e0f57..ecab39a 100644 --- a/test/link_creation.vader +++ b/test/link_creation.vader @@ -1,6 +1,6 @@ # Link creation: my favorite (tinmarino) # You know, when pressing Enter: -# in mode normal, visual +# in mode normal, visual # in OS windows, linux # Seems easy but tests are reaaly needed here diff --git a/test/link_generation.vader b/test/link_generation.vader index cec56d4..31f957a 100644 --- a/test/link_generation.vader +++ b/test/link_generation.vader @@ -16,6 +16,8 @@ Execute (Copy Wiki's Resources): Execute (Log): Log 'Wiki Syntax' + call ReloadVimwiki() + AssertEqual '-1_margin', vimwiki#vars#get_wikilocal('list_margin') . '_margin' Given (Void): diff --git a/test/vimrc b/test/vimrc index 0a727fc..77bda57 100644 --- a/test/vimrc +++ b/test/vimrc @@ -122,33 +122,52 @@ call vimwiki#vars#set_bufferlocal('wiki_nr', 3) " Verify syntax was set correctly - Assert vimwiki#vars#get_wikilocal('syntax') ==# a:vw_syn, 'ERROR: Vimwiki syntax not set correctly.' + Assert vimwiki#vars#get_wikilocal('syntax') ==# a:vw_syn, + \ 'ERROR: Vimwiki syntax not set correctly: ' + \ . 'Want: ' . a:vw_syn . ' ' + \ . 'Have: ' . vimwiki#vars#get_wikilocal('syntax') endfunction - " Reload plugin to change settings - function! ReloadVimwiki() + function! UnloadVimwiki() " Clear mappings so plugin can be reloaded " this is needed if running manually multiple times nmapclear " UNlet what can be + " -- Note: getcompletion not present on vim7.3 for i in ['g:vimwiki_commentstring', \ 'b:did_ftplugin', \ 'g:loaded_vimwiki', \ 'g:vimwiki_global_vars', \ 'g:vimwiki_wikilocal_vars', \ 'g:vimwiki_syntax_variables', + \ 'g:vimwiki_list', \ ] if exists(i) exe 'unlet ' . i endif endfor + " Unlet ftplugin: + " -- Vader often staty in same buffer: [Vader-workbench] + if exists('b:did_ftplugin') + unlet b:did_ftplugin + endif + endfunction + + " Source plugin + function! LoadVimwiki() + runtime! plugin/vimwiki.vim + endfunction + + " Reload plugin to change settings + function! ReloadVimwiki() + call UnloadVimwiki() + " Reset list let g:vimwiki_list = g:vimwiki_list_vimrc - " Source plugin: Go - runtime! plugin/vimwiki.vim + call LoadVimwiki() endfunction function! ReloadVars()