tAssert : Simple assertions, poor man's contracts for vim script
| script karma
Downloaded by 1129
Comments, bugs, improvements
script versions (upload new version)
|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
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
fun! Test(a, b)
TAssertType a:a, 'string'
TAssertType a:b, 'number'
return repeat(a:a, a:b)
TAssert also includes a few convenience commands for logging. 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)
|Extract the archive to ~/.vim or ~/vimfiles. If g:TASSERT is 0, the impact of
this script on startup time should be minimal.
Insert the following code in files using assertions. This defines a utility function
and makes sure that end users can still use your files without having this
plugin installed: >
command! -nargs=* -bar -bang TAssert :
command! -nargs=* -bar -bang TAssertType :
Also available via git
Click on the package to download.
ip used for rating: 220.127.116.11
||- Incompatible changes galore
- Removed :TAssertToggle, :TAssertBegin & :TAssertEnd etc. that doesn't really belong here.
- :TAssertType command (requires macros/tassert.vim)
- Moved Is*() functions to macros/tassert.vim.
||- IsA(): Can take a list of types as arguments and it provides a way to
check dictionaries againt prototypes or interface definitions.
- New log-related commands: TLogOn, TLogOff, TLogBufferOn, TLogBufferOff
- Use TAssertVal(script, expr) to evaluate an expression (as
argument to a command) in the script context.
- TAssertOn implies TLogOn
- *Comment & *Uncomment commands now take a range as argument (default:
- TAssertComment! & TAssertUncomment! (with [!]) also call
||- More convenience functions
- The convenience functions now display an explanation for a failure
- Convenience commands weren't loaded when g:TASSERT was off.
- Logging to a file & via Decho()
- TAssert! (the one with the bang) doesn't throw an error but simply
displays the failure in the log
- s:ResolveSIDs() didn't return a string if s:assertFile wasn't set.
- s:ResolveSIDs() caches scriptnames
- Moved logging code to 00tLog.vim