Skip to content

Commit

Permalink
Add test with vader
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Sep 28, 2022
1 parent 5804b8b commit 61bf093
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,12 @@ class Foo {
`<Leader>da` will call your documentation plugin (by default Php Documentor for vim https://github.com/tobyS/pdv) for every uncommented classes, methods, functions and properties.


## Running tests

```
bin/test
```

### How to write tests?

See https://github.com/junegunn/vader.vim
7 changes: 7 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/sh -eu

test -d vendor/vader.vim || {
git clone --depth=1 https://github.com/junegunn/vader.vim.git vendor/vader.vim
}

vim -esNu test/fixtures/vimrc -c 'Vader! test/*'
61 changes: 61 additions & 0 deletions test/extract_variable.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Given php (condition on if):
<?php

$sentence = 'Hello';

if ('foo' === $firstName) {
$sentence .= ' ' . $firstName;
}

Do (select the condition and extract variable):
/foo\<CR>
vi(
;ev
firstNameIsValid\<CR>

Expect php (variable is extracted):
<?php

$sentence = 'Hello';

$firstNameIsValid = 'foo' === $firstName;

if ($firstNameIsValid) {
$sentence .= ' ' . $firstName;
}

Given php (condition on if and on function):
<?php

function prepareSentence()
{
$sentence = 'Hello';

if ('foo' === $firstName) {
$sentence .= ' ' . $firstName;
}

return $sentence;
}

Do (select the condition and extract variable):
/foo\<CR>
vi(
;ev
firstNameIsValid\<CR>

Expect php (variable is extracted):
<?php

function prepareSentence()
{
$sentence = 'Hello';

$firstNameIsValid = 'foo' === $firstName;

if ($firstNameIsValid) {
$sentence .= ' ' . $firstName;
}

return $sentence;
}
14 changes: 14 additions & 0 deletions test/fixtures/vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
" Setup a testing environment that is isolated from the other plugins.
"
filetype off

set rtp+=vendor/vader.vim
set rtp+=.
set rtp+=after

filetype plugin on
filetype indent on

syntax enable

let mapleader = ";"

0 comments on commit 61bf093

Please sign in to comment.