robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
a8dad46e1c
master
1" Tests for the jumplist functionality 2 3" Tests for the getjumplist() function 4func Test_getjumplist () 5 %bwipe 6clearjumps 7call assert_equal ([[], 0 ], getjumplist ()) 8call assert_equal ([[], 0 ], getjumplist ( 1 )) 9call assert_equal ([[], 0 ], getjumplist ( 1 , 1 )) 10 11call assert_equal ([], getjumplist ( 100 )) 12call assert_equal ([], getjumplist ( 1 , 100 )) 13 14let lines = [] 15for i in range ( 1 , 100 ) 16call add ( lines , "Line " . i ) 17endfor 18call writefile ( lines , "Xtest" , 'D' ) 19 20" Jump around and create a jump list 21edit Xtest 22let bnr = bufnr ( '%' ) 23normal 50% 24normal G 25normal gg 26 27let expected = [[ 28 \{ 'lnum' : 1 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 29 \{ 'lnum' : 50 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 30 \{ 'lnum' : 100 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }], 3 ] 31call assert_equal ( expected , getjumplist ()) 32" jumplist doesn't change in between calls 33call assert_equal ( expected , getjumplist ()) 34 35" Traverse the jump list and verify the results 365 37exe "normal \<C-O>" 38call assert_equal ( 2 , 1 ->getjumplist ()[ 1 ]) 39exe "normal 2\<C-O>" 40call assert_equal ( 0 , getjumplist ( 1 , 1 )[ 1 ]) 41exe "normal 3\<C-I>" 42call assert_equal ( 3 , getjumplist ()[ 1 ]) 43exe "normal \<C-O>" 44normal 20% 45let expected = [[ 46 \{ 'lnum' : 1 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 47 \{ 'lnum' : 50 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 48 \{ 'lnum' : 5 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 49 \{ 'lnum' : 100 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }], 4 ] 50call assert_equal ( expected , getjumplist ()) 51" jumplist doesn't change in between calls 52call assert_equal ( expected , getjumplist ()) 53 54let l = getjumplist () 55call test_garbagecollect_now () 56call assert_equal ( 4 , l [ 1 ]) 57clearjumps 58call test_garbagecollect_now () 59call assert_equal ( 4 , l [ 1 ]) 60endfunc 61 62func Test_jumplist_wipe_buf () 63new 64clearjumps 65" Put some random text and fill the jump list. 66call setline ( 1 , [ 'foo' , 'bar' , 'baz' ]) 67normal G 68normal gg 69setl nomodified bufhidden = wipe 70e XXJumpListBuffer 71" The jump list is empty as the buffer was wiped out. 72call assert_equal ([[], 0 ], getjumplist ()) 73let jumps = execute ( ':jumps' ) 74call assert_equal ( '>' , jumps [ -1 :]) 75 76" Put some random text and fill the jump list. 77call setline ( 1 , [ 'foo' , 'bar' , 'baz' ]) 78setl bufhidden = hide 79 80" References to wiped buffer are deleted with multiple tabpages. 81let [ w1 , t1 ] = [ win_getid (), tabpagenr ()] 82clearjumps 83normal G 84normal gg 85enew 86 87split XXJumpListBuffer 88let [ w2 , t2 ] = [ win_getid (), tabpagenr ()] 89clearjumps 90normal G 91normal gg 92enew 93 94tabnew XXJumpListBuffer 95let [ w3 , t3 ] = [ win_getid (), tabpagenr ()] 96clearjumps 97normal G 98normal gg 99enew 100 101split XXJumpListBuffer 102let [ w4 , t4 ] = [ win_getid (), tabpagenr ()] 103clearjumps 104normal G 105normal gg 106enew 107 108for [ w , t ] in [[ w1 , t1 ], [ w2 , t2 ], [ w3 , t3 ], [ w4 , t4 ]] 109call assert_equal ( 2 , len ( getjumplist ( w , t )[ 0 ])) 110endfor 111 112bwipe ! XXJumpListBuffer 113 114for [ w , t ] in [[ w1 , t1 ], [ w2 , t2 ], [ w3 , t3 ], [ w4 , t4 ]] 115call assert_equal ( 0 , len ( getjumplist ( w , t )[ 0 ])) 116endfor 117 118 %bwipe ! 119endfunc 120 121" Test for '' mark in an empty buffer 122 123func Test_empty_buffer () 124new 125insert 126a 127b 128c 129d 130. 131call assert_equal ( 1 , line ( "''" )) 132bwipe ! 133endfunc 134 135" Test for 'jumpoptions' 136func Test_jumpoptions () 137new 138call setline ( 1 , range ( 1 , 200 )) 139clearjumps 140set jumpoptions = stack 141 142" Jump around to add some locations to the jump list. 143normal 10G 144normal 20G 145normal 30G 146normal 40G 147normal 50G 148let bnr = bufnr () 149 150" discards the tail when navigating from the middle 151exe "normal \<C-O>\<C-O>" 152call assert_equal ([ 153 \[{ 'lnum' : 1 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 154 \{ 'lnum' : 10 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 155 \{ 'lnum' : 20 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 156 \{ 'lnum' : 30 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 157 \{ 'lnum' : 40 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 158 \{ 'lnum' : 50 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 } 159 \], 3 ], getjumplist ()) 160 161" new jump location is added immediately after the last one 162normal 90G 163call assert_equal ([ 164 \[{ 'lnum' : 1 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 165 \{ 'lnum' : 10 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 166 \{ 'lnum' : 20 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 167 \{ 'lnum' : 30 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 168 \], 4 ], getjumplist ()) 169 170" does not add the same location twice adjacently 171normal 60G 172normal 60G 173call assert_equal ([ 174 \[{ 'lnum' : 1 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 175 \{ 'lnum' : 10 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 176 \{ 'lnum' : 20 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 177 \{ 'lnum' : 30 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 178 \{ 'lnum' : 90 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 179"\ Nvim: avoids useless/phantom jumps 180"\ {'lnum': 60, 'bufnr': bnr, 'col': 0, 'coladd': 0}, 181"\ ], 6], getjumplist()) 182 \], 5 ], getjumplist ()) 183 184" does add the same location twice non adjacently 185normal 10G 186normal 20G 187call assert_equal ([ 188 \[{ 'lnum' : 1 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 189 \{ 'lnum' : 10 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 190 \{ 'lnum' : 20 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 191 \{ 'lnum' : 30 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 192 \{ 'lnum' : 90 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 193 \{ 'lnum' : 60 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 194 \{ 'lnum' : 10 , 'bufnr' : bnr , 'col' : 0 , 'coladd' : 0 }, 195 \], 7 ], getjumplist ()) 196 197set jumpoptions & 198 %bw ! 199endfunc 200 201" vim: shiftwidth=2 sts=2 expandtab