Vader.vim test blocks
From wikinotes
Vader's syntax is a bit different. There are generally 2x ways to run test.
1. Given a set-text document, run a variety of tests (either assertions, or expecting file-contents)
2. Execute a test, like a normal test
Execute
Execute a vim command. This is most similar to your standard unittest test-case. It operates on the last buffer contents defined by
Given
, if it exists.Execute [language] [(comment)]: # ... your codeExample
Execute (name of test): :e file.txt :AssertEqual 'a', getline(1)
Do/Then
Do executes a series of normal-mode keystrokes.
Then can be used following do (or execute) for assertions.
Example
Given (file.txt): a b c Do (delete line) gg dd Then (assert line1 == b) AssertEqual 'b', getline(1)
Given
Use
Given
to perform several tests using the same vim-buffer contents.Given [filetype] [(comment)]: [text]Example
# vader require 2x spaces for indentation Given (name identifying vim contents): a b c Execute (ln1 == a) # expected, result AssertEqual 'a', getline(1) Execute (ln2 == b) AssertEqual 'b', getline(2) Execute (ln3 == c) AssertEqual 'c', getline(3)
Expect
Use
Expect
to assert the contents of a vim buffer.Example
The following constitutes one test.
Given (name identifying vim contents): a b c Execute (remove line 2): :2 :delete Expect (name expectation): a c
Before, After (setup/teardown)
run code before/after each test-case.
Before: set shiftwidth=2