From 2062b9f765ed72c8be83c7d99705cdab33c96d6b Mon Sep 17 00:00:00 2001 From: Joel Goguen Date: Sat, 2 Jul 2022 21:16:57 -0400 Subject: [PATCH] Add vader tests --- tests/run_tests.sh | 9 ++++++++ tests/suites/date_vars.vader | 26 ++++++++++++++++++++++ tests/suites/include_file.vader | 29 +++++++++++++++++++++++++ tests/suites/no_such_var.vader | 8 +++++++ tests/suites/template_static_vars.vader | 10 +++++++++ tests/test_vimrc.vim | 12 ++++++++++ tests/tmpl_vars.vader | 10 +++++++++ 7 files changed, 104 insertions(+) create mode 100755 tests/run_tests.sh create mode 100644 tests/suites/date_vars.vader create mode 100644 tests/suites/include_file.vader create mode 100644 tests/suites/no_such_var.vader create mode 100644 tests/suites/template_static_vars.vader create mode 100644 tests/test_vimrc.vim create mode 100644 tests/tmpl_vars.vader diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100755 index 0000000..b689f7b --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# vim: set filetype=sh noexpandtab ts=2 sts=2 sw=2 foldmethod=marker: +# vim: set foldmarker=[[[,]]]: + +set -e + +cd "$(dirname "${0}")" + +${VIM_BIN:-nvim} -Nu test_vimrc.vim -c 'Vader! *' diff --git a/tests/suites/date_vars.vader b/tests/suites/date_vars.vader new file mode 100644 index 0000000..79d0bed --- /dev/null +++ b/tests/suites/date_vars.vader @@ -0,0 +1,26 @@ +# Simple date +Given (date template): + <# DATE #> + +Execute (run variable replacement): + let datestr = strftime('%Y-%m-%d') + call tmpl#ExpandTmplVars() + AssertEqual getline(1), datestr + +# Year +Given (year template): + <# YEAR #> + +Execute (run variable replacement): + let datestr = strftime('%Y') + call tmpl#ExpandTmplVars() + AssertEqual getline(1), datestr + +# Time +Given (time template): + <# TIME #> + +Execute (run variable replacement): + let datestr = strftime('%H:%M:%S') + call tmpl#ExpandTmplVars() + AssertEqual getline(1), datestr diff --git a/tests/suites/include_file.vader b/tests/suites/include_file.vader new file mode 100644 index 0000000..352ab07 --- /dev/null +++ b/tests/suites/include_file.vader @@ -0,0 +1,29 @@ +Given (include MIT license): + <$ LICENSE.MIT $> + +Execute (run variable replacement): + call tmpl#ExpandIncludeVars() + $d + +Expect (MIT license): + The MIT License + + Copyright (C) <# YEAR #> by <# AUTHOR #> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. diff --git a/tests/suites/no_such_var.vader b/tests/suites/no_such_var.vader new file mode 100644 index 0000000..29e956a --- /dev/null +++ b/tests/suites/no_such_var.vader @@ -0,0 +1,8 @@ +Given (variable with no replacement): + <# I_DO_NOT_EXIST #> + +Execute (run variable replacement): + call tmpl#ExpandTmplVars() + +Expect (no change): + <# I_DO_NOT_EXIST #> diff --git a/tests/suites/template_static_vars.vader b/tests/suites/template_static_vars.vader new file mode 100644 index 0000000..9dafcc8 --- /dev/null +++ b/tests/suites/template_static_vars.vader @@ -0,0 +1,10 @@ +Given (template variables): + <# AUTHOR #> + <# WHOAMI #> + +Execute (run variable replacement): + call tmpl#ExpandTmplVars() + +Expect (replaced variables): + jgoguen + A test diff --git a/tests/test_vimrc.vim b/tests/test_vimrc.vim new file mode 100644 index 0000000..3ddc37e --- /dev/null +++ b/tests/test_vimrc.vim @@ -0,0 +1,12 @@ +filetype off +let s:tmplvim_dir = expand('%:p:h:h') +let s:vader_dir = printf('%s/../vader.vim', s:tmplvim_dir) +let &runtimepath = s:tmplvim_dir.','.&runtimepath +if isdirectory(s:vader_dir) + let &runtimepath .= ','.s:vader_dir +endif +filetype plugin indent on +syntax enable +set nomore +set noswapfile +set viminfo= diff --git a/tests/tmpl_vars.vader b/tests/tmpl_vars.vader new file mode 100644 index 0000000..02a4216 --- /dev/null +++ b/tests/tmpl_vars.vader @@ -0,0 +1,10 @@ +Before: + let g:tmplvim_author = 'jgoguen' + let g:tmplvim_template_vars = {'WHOAMI': 'A test'} + +Include (static variable tests): suites/template_static_vars.vader +Include (date variable tests): suites/date_vars.vader + +Include (file include tests): suites/include_file.vader + +Include (var does not exist): suites/no_such_var.vader