doctest.vim


Ⅰ. 插件描述

DocTest in vim

Ⅱ. 基本信息

创建日期:  2014-08-06
使用用户:  2
Github星:  4
插件作者:  顾凡

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'rykka/doctest-vim-enchanted'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

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

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'rykka/doctest-vim-enchanted'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'rykka/doctest-vim-enchanted'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

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

Ⅳ. 文档说明

doctest.vim

Besides TDD & BDD , What about DDD (Doc Driven Dev) :)

-- doctest.vim

:version: 0.95

So, Let's start a doctest::


" A simple one
" >>> let a = 3
" >>> let b = 3
" >>> echo a+b
" 6

" Catching error.
" (NOTE:use ErrorNumber like 'E100')
" >>> echom an_undefined_variable
" E121

" Multi row output
" >>> echo "3\n3"
" 3
" 3

" Define a function!
" >>> fun! TestNum(i)
" >>>   return printf("%06d",a:i)
" >>> endfun
" >>> echo TestNum(3000)
" 003000

" s:vars and s:fn()
" >>> let s:k = 5
" >>> fun! s:test(i)
" >>>   return printf("%07d",a:i+s:k)
" >>> endfun
" >>> echo s:test(3000)
" 0003005

" Timing something
" (NOTE: no s:fn function in timer)
" >>> fun! Work()
" >>>   let a = 342349.3429*123499.34239/3438923.43
" >>> endfun
" >>> call doctest#timer("Work", [], 10000)
" [TIMER]

With :DocTest, result would be::

Try::line 9        PASS!
Try::line 16       PASS!
Try::line 20       PASS!
Try::line 25       PASS!
Try::line 32       PASS!
[TIMER] line 41    
[TIMER] 0.0637 seconds for exec Work 10000 times. 
 
Total: 5 tests.
Passed:5 tests.

Total Time: 0.0658 seconds 
 

Test Passed, Great! :)

Install

Using NeoBundle or Vundle::

Bundle "Rykka/doctest.vim"

or

NeoBundle "Rykka/doctest.vim"

Configure

Command

:DocTest[!] [input_file] [output_file]

DocTest with file.

If file is empty or '%', test current file ,
If '!' is added, verbose level is 1.

Option

g:doctest_verbose_level

Default is 0.
Set it to 1 to see more info.

API

doctest#start([input_file, [output_file, [verbose_level]]])

Returns an object of test result

doctest#timer(func_name, [[func_arg_list, [exe_time]]])

Execute func_name with func_arg_list by exe_time.

Test vim file

In your file, add following code.

.. code:: vim

if expand('<sfile>:p') == expand('%:p') "{{{
    call doctest#start()
endif "}}}

Use :so % to test.

添加新评论