# HG changeset patch # User Steve Losh # Date 1289618002 18000 # Node ID dbd4f2ec38610d46d3149170c2203caa480134b4 # Parent 754d871449f128ace768a7178ab495a8958a2cc3 Add another unit test. This is so damn painful. diff -r 754d871449f1 -r dbd4f2ec3861 tests/README.markdown --- a/tests/README.markdown Fri Nov 12 21:01:55 2010 -0500 +++ b/tests/README.markdown Fri Nov 12 22:13:22 2010 -0500 @@ -7,7 +7,7 @@ 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 @@ 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 -r 754d871449f1 -r dbd4f2ec3861 tests/run-tests.sh --- a/tests/run-tests.sh Fri Nov 12 21:01:55 2010 -0500 +++ b/tests/run-tests.sh Fri Nov 12 22:13:22 2010 -0500 @@ -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 -r 754d871449f1 -r dbd4f2ec3861 tests/test-graph.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-graph.vim Fri Nov 12 22:13:22 2010 -0500 @@ -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 -r 754d871449f1 -r dbd4f2ec3861 tests/test-toggle.vim --- a/tests/test-toggle.vim Fri Nov 12 21:01:55 2010 -0500 +++ b/tests/test-toggle.vim Fri Nov 12 22:13:22 2010 -0500 @@ -5,7 +5,7 @@ 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 @@ 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 @@ " Open Gundo GundoToggle - call s:Goto('test') + call g:Goto('test') Assert expand('%') == 'test' " Close Gundo @@ -87,7 +84,7 @@ " Open Gundo GundoToggle - call s:Goto('__Gundo_Preview__') + call g:Goto('__Gundo_Preview__') Assert expand('%') == '__Gundo_Preview__' " Close Gundo @@ -108,7 +105,7 @@ Assert bufwinnr(bufnr('__Gundo_Preview__')) == -1 exec 'new test2' - call s:Goto('test') + call g:Goto('test') " Toggle Gundo GundoToggle @@ -118,7 +115,7 @@ Assert expand('%') == 'test' " Move to test2 - call s:Goto('test2') + call g:Goto('test2') " Toggle Gundo GundoToggle diff -r 754d871449f1 -r dbd4f2ec3861 tests/vim_test/plugin/gundo_test_utils.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/vim_test/plugin/gundo_test_utils.vim Fri Nov 12 22:13:22 2010 -0500 @@ -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"}}}