Find file
Fetching contributors…
Cannot retrieve contributors at this time
81 lines (52 sloc) 2.35 KB
This plugin defines a command |:TAssert| that takes an expression as
argument and throws an exception if this expression evaluates to
|empty()|. You can insert these comments throughout your code whenever
something could potentially go wrong. The exception is then thrown right
where the problem occurs. You could think of it as a poor man's
design-by-contract substitute.
One goal of this plugin is to allow users to quickly switch on or off
assertions depending on the context. This can be done either by:
1. Turning assertions off so that they are not evaluated. This can
be achieved by setting g:TASSERT to 0 or by calling the command
2. Commenting out assertions in the current buffer by calling the
commmand |:TAssertComment|.
Example: >
fun! Test(a, b)
TAssertType a:a, 'string'
TAssertType a:b, 'number'
TAssert !empty(a:a)
return repeat(a:a, a:b)
NOTE: The |:TAssertType| command requires the spec.vim plugin.
TAssert also includes a few convenience commands for logging -- see
The variable g:TLOG controls where messages are written to:
echom ... Print messages in the echo area.
file ... Print messages to a file; syntax "file:FILENAME"
Decho ... Print messages via Decho (vimscript#642)
Edit the vba file and type: >
:so %
See :help vimball for details. If you have difficulties or use vim 7.0,
please make sure, you have the current version of vimball (vimscript
#1502) installed.
See also |tassert-macros|.
If you want to redistribute files containing assertions but don't want
to have people install this plugin, insert this close to the top of
your file: >
if !exists(':TAssert')
command! -nargs=* -bar -bang TAssert :
command! -nargs=* -bar -bang TAssertType :
Alternatively, use the |:TAssertComment| command.
Status: Works for me (there may be some minor quirks)
Install: See
See for related plugins.