From 2332dc15149e52d80e89663471eeb29e575ceb32 Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Wed, 29 Jul 2020 23:29:03 -0400 Subject: [PATCH] Refactor: Test & Doc: Remove test/vader_include and move DesignNotes to doc - vader_include is declareing functions -> faster to load (parse) once in vimrc - DesignNotes is doc so goes to doc --- README.md | 2 +- DesignNotes.md => doc/DesignNotes.md | 0 test/command_generate_links.vader | 9 +- test/command_generate_tags.vader | 4 +- test/command_goto.vader | 5 +- test/command_rename_link.vader | 5 +- test/command_toc.vader | 7 +- test/convert_default_html.vader | 39 +-- test/diary_rss_feed.vader | 4 +- test/html_blockquote.vader | 4 +- test/independent_runs/map.vader | 4 - test/independent_runs/search.vader | 4 - test/issue_markdown.vader | 6 - test/link_creation.vader | 8 +- test/link_markdown_multiple_per_file.vader | 5 +- test/list_VimwikiReturn.vader | 5 +- test/list_clean.vader | 5 +- test/list_margin.vader | 4 +- test/list_todo.vader | 5 +- test/list_update.vader | 4 +- test/syntax.vader | 3 +- test/table_autoformat.vader | 4 +- test/tabnext_delay.vader | 4 +- test/vader_includes/vader_setup.vader | 119 --------- test/vader_includes/vader_teardown.vader | 6 - test/vimrc | 276 +++++++++++++++++---- 26 files changed, 260 insertions(+), 281 deletions(-) rename DesignNotes.md => doc/DesignNotes.md (100%) delete mode 100644 test/vader_includes/vader_setup.vader delete mode 100644 test/vader_includes/vader_teardown.vader diff --git a/README.md b/README.md index d53526c..e8d0b92 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ VimWiki has a lot of users but only very few recurring developers or people helping the community. Your help is therefore appreciated. Everyone can help! See [#625](https://github.com/vimwiki/vimwiki/issues/625) for information on how you can help. -Also, take a look at [CONTRIBUTING.md](https://github.com/vimwiki/vimwiki/blob/master/CONTRIBUTING.md). +Also, take a look at [CONTRIBUTING.md](https://github.com/vimwiki/vimwiki/blob/master/CONTRIBUTING.md) and [DesignNotes.md](doc/DesignNotes.md) ---- diff --git a/DesignNotes.md b/doc/DesignNotes.md similarity index 100% rename from DesignNotes.md rename to doc/DesignNotes.md diff --git a/test/command_generate_links.vader b/test/command_generate_links.vader index 79a22c1..6411746 100644 --- a/test/command_generate_links.vader +++ b/test/command_generate_links.vader @@ -1,4 +1,8 @@ -Include: vader_includes/vader_setup.vader +# Automatic link generation +# Related to: +# - wiki file discovery +# - buffer list insertion (see: vimwiki#base#update_listing_in_buffer) + Execute (Copy Wiki's Resources): Log "Start: Copy Resources" @@ -196,7 +200,4 @@ Execute (Clean): Log "End: Reset shiftwidth to the default: 8" set sw& - -Include: vader_includes/vader_teardown.vader - # vim: sw=2:foldmethod=marker:foldlevel=30:foldignore=: diff --git a/test/command_generate_tags.vader b/test/command_generate_tags.vader index b90dbd1..4005c99 100644 --- a/test/command_generate_tags.vader +++ b/test/command_generate_tags.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Tag generation Execute (Copy Wiki's Resources): Log "Start: Copy Resources" @@ -93,4 +93,4 @@ Execute (Clean Test-Tag and .vimwiki_tags): call system("rm $HOME/testmarkdown/Test-Tag.md") call DeleteHiddenBuffers() -Include: vader_includes/vader_teardown.vader +# vim: sw=2:foldlevel=30:foldmethod=indent: diff --git a/test/command_goto.vader b/test/command_goto.vader index dfca564..7e98884 100644 --- a/test/command_goto.vader +++ b/test/command_goto.vader @@ -1,9 +1,9 @@ +# VimwikiGoto +# # Note: I dont know why is inserting a Tab. # Well better than to insert a Chair, but it should trigger completion # So I used C-L -Include: vader_includes/vader_setup.vader - Execute (Copy Wiki's Resources): Log "Start: Copy Resources" @@ -80,5 +80,4 @@ Execute (Clean): Log "End: Clean" call system("rm $HOME/testmarkdown/dir1") -Include: vader_includes/vader_teardown.vader # vim: sw=2 foldmethod=indent foldlevel=30 foldignore= diff --git a/test/command_rename_link.vader b/test/command_rename_link.vader index 2d70727..3495a01 100644 --- a/test/command_rename_link.vader +++ b/test/command_rename_link.vader @@ -1,4 +1,5 @@ -Include: vader_includes/vader_setup.vader +# VimwikiRenameFile +# Related to link, file navigation # Create directories I remove at end {{{1 @@ -257,6 +258,4 @@ Execute (Clean dir1 and dir2): call system('rm -r $HOME/testmarkdown/dir2') -Include: vader_includes/vader_teardown.vader - # vim: sw=2 foldmethod=marker foldlevel=30 foldignore=# diff --git a/test/command_toc.vader b/test/command_toc.vader index b738ce9..8dc8450 100644 --- a/test/command_toc.vader +++ b/test/command_toc.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# VimwikiTOC Execute (Reset TOC header to default): let g:vimwiki_global_vars['toc_header'] = "Contents" @@ -169,7 +169,4 @@ Expect (Content prepended): # Header 2 ### Header 2.1.1 - -Include: vader_includes/vader_teardown.vader - -" vim: sw=2 foldmethod=indent foldlevel=30 foldignore= +" vim: sw=2 foldmethod=indent foldlevel=30 foldignore=# diff --git a/test/convert_default_html.vader b/test/convert_default_html.vader index 4334f73..61b80cd 100644 --- a/test/convert_default_html.vader +++ b/test/convert_default_html.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Conertion: Wiki -> Html Execute (Copy Wiki's Resources): Log "Start: Copy Resources" @@ -13,23 +13,7 @@ Given vimwiki (Table no heading {{{1): | val1 | val2 | Do (Convert): -# Note: gg"bdG = Cut -# Note: ggdG"bp = Replace file content by clipboard "b -# Fill file with a name - :let g:buf_vader = bufnr('%')\ - gg"bdG - :edit $HOME/testwiki/test_html_table.wiki\ - ggdG"bp - :call WriteMe()\ -# Convert - :Vimwiki2HTML\ -# Copy output - :edit $HOME/html/default/test_html_table.html\ - gg"bdG -# Paste output in [Vader] buffer - :execute 'buffer ' . g:buf_vader\ - ggdG"bp - + :call ConvertWiki2Html()\ # Keep only body ggd/\ @@ -87,23 +71,7 @@ Given vimwiki (Table with heading {{{1): | val4 | val5 | var6 | Do (Convert): -# Note: gg"bdG = Cut -# Note: ggdG"bp = Replace file content by clipboard "b -# Fill file with a name - :let g:buf_vader = bufnr('%')\ - gg"bdG - :edit $HOME/testwiki/test_html_table.wiki\ - ggdG"bp - :call WriteMe()\ -# Convert - :Vimwiki2HTML\ -# Copy output - :edit $HOME/html/default/test_html_table.html\ - gg"bdG -# Paste output in [Vader] buffer - :execute 'buffer ' . g:buf_vader\ - ggdG"bp - + :call ConvertWiki2Html()\ # Keep only body ggd/\ @@ -273,5 +241,4 @@ Expect (Plain Html): Execute (Delete): call DeleteFile('$HOME/testwiki/TestHtml.wiki') -Include: vader_includes/vader_teardown.vader # vim: sw=2 foldmethod=marker foldlevel=30 diff --git a/test/diary_rss_feed.vader b/test/diary_rss_feed.vader index 5991800..db6176d 100644 --- a/test/diary_rss_feed.vader +++ b/test/diary_rss_feed.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Feature to generate a diray RSS feed (PR #934) Execute (Copy Wiki's Resources): Log "Start: Copy Resources" @@ -106,5 +106,3 @@ Expect (RSS): - -Include: vader_includes/vader_teardown.vader diff --git a/test/html_blockquote.vader b/test/html_blockquote.vader index e7d7020..7d4a413 100644 --- a/test/html_blockquote.vader +++ b/test/html_blockquote.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Blockquotes in html convertion Execute (Copy Wiki's Resources): Log "Start: Copy Resources" @@ -68,4 +68,4 @@ Expect (Plain Html): -Include: vader_includes/vader_teardown.vader +# vim: sw=2:foldlevel=30:foldmethod=indent: diff --git a/test/independent_runs/map.vader b/test/independent_runs/map.vader index 21474a5..1f772e5 100644 --- a/test/independent_runs/map.vader +++ b/test/independent_runs/map.vader @@ -1,6 +1,3 @@ -Include: vader_setup - - # 0 Configure {{{1 ################## @@ -566,5 +563,4 @@ Expect (Like 'aH', but excluding the header itself): # Head2 content 2 -Include: vader_teardown # vim: foldmethod=marker foldlevel=30 sw=2 diff --git a/test/independent_runs/search.vader b/test/independent_runs/search.vader index 0cf0f66..e70fc72 100644 --- a/test/independent_runs/search.vader +++ b/test/independent_runs/search.vader @@ -1,5 +1,3 @@ -Include: vader_setup - Execute (Setup search testing wrapper): function! TestSearch(search_command, test_name) " Note: after each search, the location list of the current window (0) @@ -62,5 +60,3 @@ Execute (Search failure message): silent VimwikiSearch not_exist redir END Assert match(output, 'VimwikiSearch: No match found.') > -1, "expected custom error" - -Include: vader_teardown diff --git a/test/issue_markdown.vader b/test/issue_markdown.vader index 00b5f5c..36b8be4 100644 --- a/test/issue_markdown.vader +++ b/test/issue_markdown.vader @@ -5,9 +5,6 @@ # -Include: vader_includes/vader_setup.vader - - ################################################################################ Execute (Log): Log '#915 Vimwiki Markdown Blockquote Syntax issue' @@ -166,6 +163,3 @@ Do (No link: ): :call vimwiki#vars#set_global('markdown_create_link', 0) \\ :AssertEqual expand('%:t'), 'main.md'\ - - -Include: vader_includes/vader_teardown.vader diff --git a/test/link_creation.vader b/test/link_creation.vader index 61501bd..2c4ac6f 100644 --- a/test/link_creation.vader +++ b/test/link_creation.vader @@ -1,4 +1,9 @@ -Include: vader_includes/vader_setup.vader +# Link creation: my favorite (Tinmarino) +# You know, when pressing Enter: +# in mode normal, visual +# in OS windows, linux +# Seems easy but tests are reaaly needed here + # Link Normalisation {{{1 # And configuration @@ -363,5 +368,4 @@ Expect (Mediawiki links): [[file.md]] [[file.mw]] -Include: vader_includes/vader_teardown.vader # vim: foldmethod=marker foldlevel=30 diff --git a/test/link_markdown_multiple_per_file.vader b/test/link_markdown_multiple_per_file.vader index 480b575..34fbd6e 100644 --- a/test/link_markdown_multiple_per_file.vader +++ b/test/link_markdown_multiple_per_file.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Link internal to a file Given vimwiki (Internal links + one link to filenew): # Contents @@ -220,6 +220,3 @@ Expect (Some chars appended at self link): - [ this_is_18_chars My own file](wiki_test) - [Test1](#Test1) - [Test2](#Test2) - - -Include: vader_includes/vader_teardown.vader diff --git a/test/list_VimwikiReturn.vader b/test/list_VimwikiReturn.vader index 97dc389..b9c8126 100644 --- a/test/list_VimwikiReturn.vader +++ b/test/list_VimwikiReturn.vader @@ -4,8 +4,6 @@ # better read this file with `set list` -Include: vader_includes/vader_setup.vader - Given vimwiki (List with hard wraps): - Item 1 - Item 2 @@ -279,4 +277,5 @@ Expect (List per VimwikiReturn 3 5): 1. --- -Include: vader_includes/vader_teardown.vader + +# vim: sw=2:foldlevel=30:foldmethod=indent: diff --git a/test/list_clean.vader b/test/list_clean.vader index 931883f..3606769 100644 --- a/test/list_clean.vader +++ b/test/list_clean.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Task List with commands Given vimwiki (simple list): * [X] Done 1 @@ -194,6 +194,3 @@ Expect (only first is removed): * [X] Done 3 * [ ] Todo 2 * [X] Done 4 - - -Include: vader_includes/vader_teardown.vader diff --git a/test/list_margin.vader b/test/list_margin.vader index 2c23b1b..39d12d2 100644 --- a/test/list_margin.vader +++ b/test/list_margin.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# List indentation <= shiftwidth Execute (Create temp directory): silent execute '!mkdir -p $HOME/list_margin/' @@ -105,4 +105,4 @@ Expect (Links with margin == 5): Execute (Return to default location & cleanup): cd /testplugin -Include: vader_includes/vader_teardown.vader +# vim: sw=2:foldlevel=30:foldmethod=indent: diff --git a/test/list_todo.vader b/test/list_todo.vader index 211022b..db789cb 100644 --- a/test/list_todo.vader +++ b/test/list_todo.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Todo lists Given vimwiki (Todo list): * [ ] Chap1 @@ -247,6 +247,3 @@ Do (Toogle ): Expect (Chap1 Done): 1. [X] Chap1 2. [ ] Chap2 - - -Include: vader_includes/vader_teardown.vader diff --git a/test/list_update.vader b/test/list_update.vader index 9c5b10e..e4203e5 100644 --- a/test/list_update.vader +++ b/test/list_update.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Task list update Given vimwiki (Sample nested list, vimwiki syntax): * [ ] Top Level @@ -188,4 +188,4 @@ Expect (Sub-child toggled, parents updated): * [X] Sub-sub-child -Include: vader_includes/vader_teardown.vader +# vim: sw=2:foldlevel=30:foldmethod=indent: diff --git a/test/syntax.vader b/test/syntax.vader index b118ba6..3fdd5d6 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# Syntax and Highlight # 1 Typeface {{{1 @@ -314,5 +314,4 @@ Execute (Assert math syntax): let syntax_12 = SyntaxAt(12, 1) Assert syntax_12 == 'texStatement' || syntax_5 == 'texMathSymbol' -Include: vader_includes/vader_teardown.vader # vim: foldmethod=marker foldlevel=30 sw=2 diff --git a/test/table_autoformat.vader b/test/table_autoformat.vader index 86a7e8a..d172180 100644 --- a/test/table_autoformat.vader +++ b/test/table_autoformat.vader @@ -1,4 +1,5 @@ -Include: vader_includes/vader_setup.vader +# Table autoformating +# Very configurable: read doc/DesignNotes.md # Do not alter config {{{1 ########################## @@ -213,5 +214,4 @@ Expect (Left justified and :--- -> ----): | 2017-03-14 | Cake | -Include: vader_includes/vader_teardown.vader # vim: foldmethod=marker foldlevel=30 diff --git a/test/tabnext_delay.vader b/test/tabnext_delay.vader index b4371e0..1092d42 100644 --- a/test/tabnext_delay.vader +++ b/test/tabnext_delay.vader @@ -1,4 +1,4 @@ -Include: vader_includes/vader_setup.vader +# See Issue #580 Execute (Set fold method): let g:vimwiki_folding = 'expr:quick' @@ -28,5 +28,3 @@ Execute (Expect < 0.5 second delay: Issue #580): Execute (Reset variables): let g:vimwiki_folding = '' call ReloadVimwiki() - -Include: vader_includes/vader_teardown.vader diff --git a/test/vader_includes/vader_setup.vader b/test/vader_includes/vader_setup.vader deleted file mode 100644 index 88e6820..0000000 --- a/test/vader_includes/vader_setup.vader +++ /dev/null @@ -1,119 +0,0 @@ -Before (Define functions): - " Change the syntax using a temporary wiki - function! SetSyntax(vw_syn) - if a:vw_syn ==# 'default' - let ext = 'wiki' - elseif a:vw_syn ==# 'markdown' - let ext = 'md' - elseif a:vw_syn ==# 'media' - let ext = 'mw' - else - Log 'ERROR: Invalid syntax "' . a:vw_syn . '" in SetSyntax()' - Log 'NOTE: function only accepts "media" for setting mediawiki syntax' - return - endif - let path = expand('%:p:h') - let new_temp_wiki_settings = {'path': path, - \ 'ext': ext, - \ 'syntax': a:vw_syn, - \ } - - " Remove any temporary wikis each time this function is called. - " This is necessary to ensure syntax is properly set when running multiple tests - " NOTE: this assumes there are 3 defined wikis in the vimrc. The last wiki - " contains default settings for temporary wikis (so there are always - " num wikis in vimrc + 1) - let num_wikis = len(g:vimwiki_wikilocal_vars) - while num_wikis > 4 - call remove(g:vimwiki_wikilocal_vars, num_wikis - 1) - let num_wikis = num_wikis - 1 - endwhile - - " Add the new wiki - call vimwiki#vars#add_temporary_wiki(new_temp_wiki_settings) - 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.' - endfunction - - " Reload plugin to change settings - function! ReloadVimwiki() - " Clear mappings so plugin can be reloaded - " this is needed if running manually multiple times - nmapclear - - unlet g:loaded_vimwiki - source plugin/vimwiki.vim - endfunction - - function! ReloadVars() - " vars#init will not reload syntax varaible if not set - unlet g:vimwiki_syntax_variables - call vimwiki#vars#init() - endfunction - - " Copy wiki test resources so that vimtest user can write them - function! CopyResources() - call system('cp -r /testplugin/test/resources/* $HOME/') - " Make diary directory - call system('mkdir $HOME/testwiki/diary') - call system('mkdir $HOME/testmarkdown/diary') - endfunction - - " Delete Hidden buffer, usefull to clean - " Stole from: https://stackoverflow.com/a/8459043/2544873 - function! DeleteHiddenBuffers() - let tpbl=[] - call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))') - for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1') - if bufname(buf) =~? 'Vader' - continue - endif - silent execute 'bwipeout!' buf - endfor - endfunction - - " Write current file: helper to hide `set bt=` - function! WriteMe() - set buftype= - write % - endfunction - - function! DeleteFile(path) - let path = expand(a:path) - " Delete file - try - call delete(path) - catch | endtry - " Delete Buffer - try - execute 'bdelete! ' . path - catch | endtry - endfunction - - " Print a command output to the buffer - function! PrintCommand(cmd) - redir => message - silent execute a:cmd - redir END - if empty(message) - Log 'no output' - else - silent put=message - endif - endfunction - - " Destroy a variable is exists (unlet) - function! DestroyVar(var) - if ! exists(a:var) | return | endif - execute 'unlet ' . a:var - endfunction - - " Assert current tab is desired tab - function! AssertTab(nr) - " Vader is creating 2 tabs - AssertEqual a:nr + 2, tabpagenr() - endfunction - -# vim: ft=vim:sw=2 diff --git a/test/vader_includes/vader_teardown.vader b/test/vader_includes/vader_teardown.vader deleted file mode 100644 index 0b007cd..0000000 --- a/test/vader_includes/vader_teardown.vader +++ /dev/null @@ -1,6 +0,0 @@ -After (Cleanup): - delfunction SetSyntax - delfunction ReloadVimwiki - delfunction DeleteHiddenBuffers - delfunction WriteMe - delfunction PrintCommand diff --git a/test/vimrc b/test/vimrc index 6d109da..873a448 100644 --- a/test/vimrc +++ b/test/vimrc @@ -1,68 +1,234 @@ " Declare tipical Vim preambule -" vint: -ProhibitSetNoCompatible -set nocompatible -filetype plugin indent on -syntax enable + " vint: -ProhibitSetNoCompatible + set nocompatible + filetype plugin indent on + syntax enable + " Set chrooted virtual runtime path -let rtp=$ROOT.'/rtp.vim' -exe 'source '.rtp + let rtp=$ROOT.'/rtp.vim' + exe 'source '.rtp + " Load Vader -let vader=$ROOT.'/vader' -exe 'set runtimepath+='.vader + let vader=$ROOT.'/vader' + exe 'set runtimepath+='.vader -" Declare default syntax -let vimwiki_default = {} -let vimwiki_default.path = $HOME . '/testwiki' -let vimwiki_default.path_html = $HOME . '/html/default' -let vimwiki_default.syntax = 'default' -let vimwiki_default.ext = '.wiki' -let vimwiki_default.name = 'DefaultSyntax' -let vimwiki_default.base_url = 'https://example.com/' -" Declare markdown syntax - https://github.github.com/gfm/ -let vimwiki_markdown = {} -let vimwiki_markdown.path = $HOME . '/testmarkdown' -let vimwiki_markdown.path_html = $HOME . '/html/markdown' -let vimwiki_markdown.syntax = 'markdown' -let vimwiki_markdown.ext = '.md' -let vimwiki_markdown.name = 'MarkdownSyntax' +" Wikis configuration + " Declare default syntax + let vimwiki_default = {} + let vimwiki_default.path = $HOME . '/testwiki' + let vimwiki_default.path_html = $HOME . '/html/default' + let vimwiki_default.syntax = 'default' + let vimwiki_default.ext = '.wiki' + let vimwiki_default.name = 'DefaultSyntax' + let vimwiki_default.base_url = 'https://example.com/' + + " Declare markdown syntax - https://github.github.com/gfm/ + let vimwiki_markdown = {} + let vimwiki_markdown.path = $HOME . '/testmarkdown' + let vimwiki_markdown.path_html = $HOME . '/html/markdown' + let vimwiki_markdown.syntax = 'markdown' + let vimwiki_markdown.ext = '.md' + let vimwiki_markdown.name = 'MarkdownSyntax' + + " Declare mediawiki syntax - https://www.mediawiki.org/wiki/Help:Formatting + let vimwiki_mediawiki = {} + let vimwiki_mediawiki.path = $HOME . '/testmediawiki' + let vimwiki_mediawiki.path_html = $HOME . '/html/mediawiki' + let vimwiki_mediawiki.syntax = 'media' + let vimwiki_mediawiki.ext = '.mw' + let vimwiki_mediawiki.name = 'MediaWikiSyntax' + + " Register the 3 wikis + let g:vimwiki_list = [vimwiki_default, vimwiki_markdown, vimwiki_mediawiki] -" Declare mediawiki syntax - https://www.mediawiki.org/wiki/Help:Formatting -let vimwiki_mediawiki = {} -let vimwiki_mediawiki.path = $HOME . '/testmediawiki' -let vimwiki_mediawiki.path_html = $HOME . '/html/mediawiki' -let vimwiki_mediawiki.syntax = 'media' -let vimwiki_mediawiki.ext = '.mw' -let vimwiki_mediawiki.name = 'MediaWikiSyntax' - -" Register the 3 wikis -let g:vimwiki_list = [vimwiki_default, vimwiki_markdown, vimwiki_mediawiki] " Set basic settings -set backspace=indent,eol,start -set wildmode=longest:full,full -set wildmenu -set wildignorecase -set splitbelow -set splitright -set timeoutlen=600 -set ignorecase -set smartcase -set hidden -set laststatus=2 -set hlsearch + set backspace=indent,eol,start + set wildmode=longest:full,full + set wildmenu + set wildignorecase + set splitbelow + set splitright + set timeoutlen=600 + set ignorecase + set smartcase + set hidden + set laststatus=2 + set hlsearch -" Map ctrl-p/n for history completion instead of up/down arrows -cnoremap -cnoremap -" Map jj to go back to command mode -inoremap jj +" Map + " Map ctrl-p/n for history completion instead of up/down arrows + cnoremap + cnoremap + + " Map jj to go back to command mode + inoremap jj + + " Use to clear the highlighting of :set hlsearch and also preserve the + " default behavior of redrawing the screen + if maparg('', 'n') ==# '' + nnoremap :nohlsearch=has('diff')?'diffupdate':'' + endif -" Use to clear the highlighting of :set hlsearch and also preserve the -" default behavior of redrawing the screen -if maparg('', 'n') ==# '' - nnoremap :nohlsearch=has('diff')?'diffupdate':'' -endif +" Define functions + " Change the syntax using a temporary wiki + function! SetSyntax(vw_syn) + if a:vw_syn ==# 'default' + let ext = 'wiki' + elseif a:vw_syn ==# 'markdown' + let ext = 'md' + elseif a:vw_syn ==# 'media' + let ext = 'mw' + else + Log 'ERROR: Invalid syntax "' . a:vw_syn . '" in SetSyntax()' + Log 'NOTE: function only accepts "media" for setting mediawiki syntax' + return + endif + let path = expand('%:p:h') + let new_temp_wiki_settings = {'path': path, + \ 'ext': ext, + \ 'syntax': a:vw_syn, + \ } + + " Remove any temporary wikis each time this function is called. + " This is necessary to ensure syntax is properly set when running multiple tests + " NOTE: this assumes there are 3 defined wikis in the vimrc. The last wiki + " contains default settings for temporary wikis (so there are always + " num wikis in vimrc + 1) + let num_wikis = len(g:vimwiki_wikilocal_vars) + while num_wikis > 4 + call remove(g:vimwiki_wikilocal_vars, num_wikis - 1) + let num_wikis = num_wikis - 1 + endwhile + + " Add the new wiki + call vimwiki#vars#add_temporary_wiki(new_temp_wiki_settings) + 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.' + endfunction + + " Reload plugin to change settings + function! ReloadVimwiki() + " Clear mappings so plugin can be reloaded + " this is needed if running manually multiple times + nmapclear + + unlet g:loaded_vimwiki + source plugin/vimwiki.vim + endfunction + + function! ReloadVars() + " vars#init will not reload syntax varaible if not set + unlet g:vimwiki_syntax_variables + call vimwiki#vars#init() + endfunction + + " Copy wiki test resources so that vimtest user can write them + function! CopyResources() + call system('cp -r /testplugin/test/resources/* $HOME/') + " Make diary directory + call system('mkdir $HOME/testwiki/diary') + call system('mkdir $HOME/testmarkdown/diary') + endfunction + + " Delete Hidden buffer, usefull to clean + " Stole from: https://stackoverflow.com/a/8459043/2544873 + function! DeleteHiddenBuffers() + let tpbl=[] + call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))') + for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1') + if bufname(buf) =~? 'Vader' + continue + endif + silent execute 'bwipeout!' buf + endfor + endfunction + + " Write current file: helper to hide `set bt=` + function! WriteMe() + set buftype= + write % + endfunction + + " Delete a file <- path + function! DeleteFile(path) + let path = expand(a:path) + " Delete file + try + call delete(path) + catch | endtry + " Delete Buffer + try + execute 'bdelete! ' . path + catch | endtry + endfunction + + " Print a command output to the buffer + function! PrintCommand(cmd) + redir => message + silent execute a:cmd + redir END + if empty(message) + Log 'no output' + else + silent put=message + endif + endfunction + + " Destroy a variable is exists (unlet) + function! DestroyVar(var) + if ! exists(a:var) | return | endif + execute 'unlet ' . a:var + endfunction + + " Assert current tab is desired tab + function! AssertTab(nr) + " Vader is creating 2 tabs + AssertEqual a:nr + 2, tabpagenr() + endfunction + + " Convert current buffer: wiki -> html + " No side effect (if no bug) + function! ConvertWiki2Html() + " Save fbuffer number (to come back) + let g:buf_vader = bufnr('%') + + " Cut wiki content + let wiki_content = getline(1, '$') + 1,$delete + + " Paste to a named file + " Edit a new file in wiki_root + edit $HOME/testwiki/test_Convert2Html.wiki + " Ensure it is void + 1,$delete + " Write wiki content + call setline(1, wiki_content) + " Dump buffer to disk + call WriteMe() + + " Convert + """"""""" + Vimwiki2HTML + + " Cut output + edit $HOME/html/default/test_Convert2Html.html + let html_content = getline(1, '$') + 1,$delete + + " Paste output in [Vader] buffer + execute 'buffer ' . g:buf_vader + call setline(1, html_content) + + " Delete files + call DeleteFile('$HOME/html/default/test_Convert2Html.html') + call DeleteFile('$HOME/testwiki/test_Convert2Html.wiki') + endfunction + +" vim: ft=vim:sw=2