Giter Club home page Giter Club logo

doctest.vim's Introduction

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.

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

Use :so % to test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.