Fix: Vars.vim error in parsing: key not present (Issue #980)

This commit is contained in:
Tinmarino 2020-08-12 10:35:40 -04:00
parent 11337f5b34
commit 4431caf7ff
7 changed files with 117 additions and 16 deletions

View File

@ -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

View File

@ -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'

75
test/config_vars.vader Normal file
View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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()