Add another unit test. This is so damn painful.

This commit is contained in:
Steve Losh 2010-11-12 22:13:22 -05:00
parent 2562ab7ae8
commit f6e3fc5719
5 changed files with 126 additions and 12 deletions

View File

@ -7,7 +7,7 @@ Gundo bundles Luc Hermitte's [UT][] framework to make the process less painful.
To run a test, `cd` into the `tests` directory and use: To run a test, `cd` into the `tests` directory and use:
./run-tests.sh [TEST FILE].vim ./run-tests.sh [[some-test.vim] ...]
The script will run the console vim command with its own vimrc and .vim The script will run the console vim command with its own vimrc and .vim
directory, so none of your other plugins should interfere. The result of the directory, so none of your other plugins should interfere. The result of the
@ -17,5 +17,4 @@ The `q` key will be remapped to perform `:qa!` so you can close everything
quickly if it all looks good. quickly if it all looks good.
The `run-tests.sh` script is still a work in progress. I need to figure out The `run-tests.sh` script is still a work in progress. I need to figure out
a good way of running multiple tests and collecting results. Suggestions a good way of collecting results. Suggestions and/or patches are very welcome.
and/or patches are very welcome.

View File

@ -2,4 +2,12 @@
set -e set -e
vim -u vimrc_test -c ":UTRun $1" if [[ $# -eq 0 ]]
then
TESTS="`ls *.vim | tr "\n" ' '`"
else
IFS=' '
TESTS="$*"
fi
vim -u vimrc_test -c ":UTRun $TESTS"

69
tests/test-graph.vim Normal file
View File

@ -0,0 +1,69 @@
let s:cpo_save=&cpo
set cpo&vim
UTSuite [Gundo] Testing Toggling
function! s:Setup()"{{{
exec 'edit test'
call g:Goto('test')
setlocal buftype=nofile
endfunction"}}}
function! s:Teardown()"{{{
if bufwinnr(bufnr('__Gundo__')) != -1
exec bufwinnr(bufnr('__Gundo__')) . 'wincmd w'
quit
endif
if bufwinnr(bufnr('__Gundo_Preview__')) != -1
exec bufwinnr(bufnr('__Gundo_Preview__')) . 'wincmd w'
quit
endif
if bufnr('__Gundo__') != -1
exec 'bwipeout ' . bufnr('__Gundo__')
endif
if bufnr('__Gundo_Preview__') != -1
exec 'bwipeout ' . bufnr('__Gundo_Preview__')
endif
if bufnr('test') != -1
exec 'bwipeout ' . bufnr('test')
endif
if bufnr('test2') != -1
exec 'bwipeout ' . bufnr('test2')
endif
endfunction"}}}
function! s:TestToggleBasic()"{{{
call g:TypeLine("ONE")
call g:TypeLineDone("TWO")
GundoToggle
Assert g:Contains("o [0]")
Assert g:Contains("o [1]")
Assert g:Contains("@ [2]")
Assert !g:Contains("[3]")
endfunction"}}}
function! s:TestToggleBranches()"{{{
call g:TypeLineDone("ONE")
silent! undo
call g:TypeLineDone("TWO")
GundoToggle
" Make sure there is a branch next to state 2
call g:GotoLineContaining("[1]")
Assert g:CurrentLineContains("|")
" Make sure there is no branch next to states 0 and 2
call g:GotoLineContaining("[0]")
Assert !g:CurrentLineContains("|")
call g:GotoLineContaining("[2]")
Assert !g:CurrentLineContains("|")
" Make sure the branch point is directly above state 0
call g:GotoLineContaining("[0]")
call g:MoveUp()
Assert g:CurrentLineContains("|/")
endfunction"}}}
let &cpo=s:cpo_save

View File

@ -5,7 +5,7 @@ UTSuite [Gundo] Testing Toggling
function! s:Setup()"{{{ function! s:Setup()"{{{
exec 'edit test' exec 'edit test'
exec bufwinnr(bufnr('test')) . 'wincmd w' call g:Goto('test')
endfunction"}}} endfunction"}}}
function! s:Teardown()"{{{ function! s:Teardown()"{{{
if bufwinnr(bufnr('__Gundo__')) != -1 if bufwinnr(bufnr('__Gundo__')) != -1
@ -29,9 +29,6 @@ function! s:Teardown()"{{{
exec 'bwipeout ' . bufnr('test2') exec 'bwipeout ' . bufnr('test2')
endif endif
endfunction"}}} endfunction"}}}
function! s:Goto(buffername)"{{{
exec bufwinnr(bufnr(a:buffername)) . 'wincmd w'
endfunction"}}}
function! s:TestToggleBasic()"{{{ function! s:TestToggleBasic()"{{{
" Make sure we're starting from scratch. " Make sure we're starting from scratch.
@ -72,7 +69,7 @@ function! s:TestToggleWhenMoved()"{{{
" Open Gundo " Open Gundo
GundoToggle GundoToggle
call s:Goto('test') call g:Goto('test')
Assert expand('%') == 'test' Assert expand('%') == 'test'
" Close Gundo " Close Gundo
@ -87,7 +84,7 @@ function! s:TestToggleWhenMoved()"{{{
" Open Gundo " Open Gundo
GundoToggle GundoToggle
call s:Goto('__Gundo_Preview__') call g:Goto('__Gundo_Preview__')
Assert expand('%') == '__Gundo_Preview__' Assert expand('%') == '__Gundo_Preview__'
" Close Gundo " Close Gundo
@ -108,7 +105,7 @@ function! s:TestToggleReturnToTarget()"{{{
Assert bufwinnr(bufnr('__Gundo_Preview__')) == -1 Assert bufwinnr(bufnr('__Gundo_Preview__')) == -1
exec 'new test2' exec 'new test2'
call s:Goto('test') call g:Goto('test')
" Toggle Gundo " Toggle Gundo
GundoToggle GundoToggle
@ -118,7 +115,7 @@ function! s:TestToggleReturnToTarget()"{{{
Assert expand('%') == 'test' Assert expand('%') == 'test'
" Move to test2 " Move to test2
call s:Goto('test2') call g:Goto('test2')
" Toggle Gundo " Toggle Gundo
GundoToggle GundoToggle

View File

@ -0,0 +1,41 @@
function! g:Goto(buffername)"{{{
exec bufwinnr(bufnr(a:buffername)) . 'wincmd w'
endfunction"}}}
function! g:GotoLineContaining(text)"{{{
exe "silent! normal gg/\\M" . a:text . "\n"
endfunction"}}}
function! g:CurrentLineContains(text)"{{{
if stridx(getline('.'), a:text) != -1
return 1
else
return 0
endif
endfunction"}}}
function! g:Contains(text)"{{{
call g:GotoLineContaining(a:text)
return g:CurrentLineContains(a:text)
endfunction"}}}
function! g:TypeLine(text)"{{{
exe "normal i" . a:text . "\<C-g>u\n\e"
endfunction"}}}
function! g:TypeLineDone(text)"{{{
exe "normal i" . a:text . "\n\e"
endfunction"}}}
function! g:PrintTheFuckingBuffer()"{{{
echo join(getline(1, 100000), "\n")
echo "SOMETIMES I HATE YOU VIM"
endfunction"}}}
function! g:MoveUp()"{{{
call cursor(line('.') - 1, 0)
endfunction"}}}
function! g:MoveDown()"{{{
call cursor(line('.') + 1, 0)
endfunction"}}}