diff --git a/tests/README.markdown b/tests/README.markdown index 9e7f26c..98b3b2a 100644 --- a/tests/README.markdown +++ b/tests/README.markdown @@ -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: - ./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 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. 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 -and/or patches are very welcome. +a good way of collecting results. Suggestions and/or patches are very welcome. diff --git a/tests/run-tests.sh b/tests/run-tests.sh index fe4bfa2..d0d4b0d 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -2,4 +2,12 @@ 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" diff --git a/tests/test-graph.vim b/tests/test-graph.vim new file mode 100644 index 0000000..b320044 --- /dev/null +++ b/tests/test-graph.vim @@ -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 diff --git a/tests/test-toggle.vim b/tests/test-toggle.vim index 137fe95..40a6e1f 100644 --- a/tests/test-toggle.vim +++ b/tests/test-toggle.vim @@ -5,7 +5,7 @@ UTSuite [Gundo] Testing Toggling function! s:Setup()"{{{ exec 'edit test' - exec bufwinnr(bufnr('test')) . 'wincmd w' + call g:Goto('test') endfunction"}}} function! s:Teardown()"{{{ if bufwinnr(bufnr('__Gundo__')) != -1 @@ -29,9 +29,6 @@ function! s:Teardown()"{{{ exec 'bwipeout ' . bufnr('test2') endif endfunction"}}} -function! s:Goto(buffername)"{{{ - exec bufwinnr(bufnr(a:buffername)) . 'wincmd w' -endfunction"}}} function! s:TestToggleBasic()"{{{ " Make sure we're starting from scratch. @@ -72,7 +69,7 @@ function! s:TestToggleWhenMoved()"{{{ " Open Gundo GundoToggle - call s:Goto('test') + call g:Goto('test') Assert expand('%') == 'test' " Close Gundo @@ -87,7 +84,7 @@ function! s:TestToggleWhenMoved()"{{{ " Open Gundo GundoToggle - call s:Goto('__Gundo_Preview__') + call g:Goto('__Gundo_Preview__') Assert expand('%') == '__Gundo_Preview__' " Close Gundo @@ -108,7 +105,7 @@ function! s:TestToggleReturnToTarget()"{{{ Assert bufwinnr(bufnr('__Gundo_Preview__')) == -1 exec 'new test2' - call s:Goto('test') + call g:Goto('test') " Toggle Gundo GundoToggle @@ -118,7 +115,7 @@ function! s:TestToggleReturnToTarget()"{{{ Assert expand('%') == 'test' " Move to test2 - call s:Goto('test2') + call g:Goto('test2') " Toggle Gundo GundoToggle diff --git a/tests/vim_test/plugin/gundo_test_utils.vim b/tests/vim_test/plugin/gundo_test_utils.vim new file mode 100644 index 0000000..0021dd2 --- /dev/null +++ b/tests/vim_test/plugin/gundo_test_utils.vim @@ -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 . "\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"}}}