Skip to content
Simple assertions/poor man's contracts for vim script
VimL
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
autoload
doc
etc
macros
plugin
.gitignore
CHANGES.TXT
README
addon-info.json

README

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 
       |:TAssertOff|.

    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)
    endf

NOTE: The |:TAssertType| command requires the spec.vim plugin.


                                                    *tAssert-logging*
Logging:~

TAssert also includes a few convenience commands for logging -- see 
|:TLog|.

                                                    *g:TLOG*
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)


                                                    *tAssert-install*
Install:~

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


                                                    *tAssert-redistribute*
Compatibility:~

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

Alternatively, use the |:TAssertComment| command.


%s


Status:  Works for me (there may be some minor quirks)
Install: See http://github.com/tomtom/vimtlib/blob/master/INSTALL.TXT
See http://github.com/tomtom for related plugins.

Something went wrong with that request. Please try again.