tAssert


Ⅰ. 插件描述

Simple assertions/poor man's contracts for vim script

Ⅱ. 基本信息

创建日期:  2006-12-13
使用用户:  1
Github星:  2
插件作者:  Tom Link

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'tomtom/tassert'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'tomtom/tassert'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'tomtom/tassert'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/tomtom/tassert_vim

Ⅳ. 文档说明

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.

添加新评论