guts: add the linear movement tests and fixes
author |
Steve Losh <steve@stevelosh.com> |
date |
Thu, 09 Dec 2010 21:59:57 -0500 |
parents |
b1e69c24c8f9
|
children |
8f6170ce8e3d
|
branches/tags |
(none) |
files |
plugin/gundo.vim tests/test-movement.vim |
Changes
--- a/plugin/gundo.vim Thu Dec 09 20:30:22 2010 -0500
+++ b/plugin/gundo.vim Thu Dec 09 21:59:57 2010 -0500
@@ -623,7 +623,12 @@
function! s:GundoMove(direction) range"{{{
let start_line = getline('.')
- let distance = 2 * v:count1
+ if v:count1 == 0
+ let move_count = 1
+ else
+ let move_count = v:count1
+ endif
+ let distance = 2 * move_count
" If we're in between two nodes we move by one less to get back on track.
if stridx(start_line, '[') == -1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-movement.vim Thu Dec 09 21:59:57 2010 -0500
@@ -0,0 +1,120 @@
+UTSuite [Gundo] Testing Toggling
+
+function! s:Setup()"{{{
+ exec 'edit test'
+ call g:Goto('test')
+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:TestMovementBasic()"{{{
+ " Make three linear changes
+ call g:TypeLineDone("ONE")
+ call g:TypeLineDone("TWO")
+ call g:TypeLineDone("THREE")
+
+ " Open Gundo
+ GundoToggle
+
+ " Make sure we're on the newest/current state
+ Assert g:CurrentLineContains("[3]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[2]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[1]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[0]")
+
+ " Move up
+ normal k
+ Assert g:CurrentLineContains("[1]")
+
+ " Move up
+ normal k
+ Assert g:CurrentLineContains("[2]")
+
+ " Move up
+ normal k
+ Assert g:CurrentLineContains("[3]")
+endfunction"}}}
+
+function! s:TestMovementLinear()"{{{
+ " Make four changes:
+ "
+ " o [4]
+ " |
+ " | o [3]
+ " | |
+ " o | [2]
+ " |/
+ " o [1]
+ " |
+ " o [0] (original)
+
+ call g:TypeLineDone("ONE")
+ call g:TypeLineDone("TWO")
+ silent! undo
+ call g:TypeLineDone("THREE")
+ silent! undo 2
+ call g:TypeLineDone("FOUR")
+
+ " Open Gundo
+ GundoToggle
+
+ " Make sure we're on the newest/current state
+ Assert g:CurrentLineContains("[4]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[3]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[2]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[1]")
+
+ " Move down
+ normal j
+ Assert g:CurrentLineContains("[0]")
+
+ " Move up
+ normal k
+ Assert g:CurrentLineContains("[1]")
+
+ " Move up
+ normal k
+ Assert g:CurrentLineContains("[2]")
+
+ " Move up
+ normal k
+ Assert g:CurrentLineContains("[3]")
+endfunction"}}}