test_jumplist.vim (5575B)
1 " Tests for the jumplist functionality 2 3 " Tests for the getjumplist() function 4 func Test_getjumplist() 5 %bwipe 6 clearjumps 7 call assert_equal([[], 0], getjumplist()) 8 call assert_equal([[], 0], getjumplist(1)) 9 call assert_equal([[], 0], getjumplist(1, 1)) 10 11 call assert_equal([], getjumplist(100)) 12 call assert_equal([], getjumplist(1, 100)) 13 14 let lines = [] 15 for i in range(1, 100) 16 call add(lines, "Line " . i) 17 endfor 18 call writefile(lines, "Xtest", 'D') 19 20 " Jump around and create a jump list 21 edit Xtest 22 let bnr = bufnr('%') 23 normal 50% 24 normal G 25 normal gg 26 27 let 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] 31 call assert_equal(expected, getjumplist()) 32 " jumplist doesn't change in between calls 33 call assert_equal(expected, getjumplist()) 34 35 " Traverse the jump list and verify the results 36 5 37 exe "normal \<C-O>" 38 call assert_equal(2, 1->getjumplist()[1]) 39 exe "normal 2\<C-O>" 40 call assert_equal(0, getjumplist(1, 1)[1]) 41 exe "normal 3\<C-I>" 42 call assert_equal(3, getjumplist()[1]) 43 exe "normal \<C-O>" 44 normal 20% 45 let 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] 50 call assert_equal(expected, getjumplist()) 51 " jumplist doesn't change in between calls 52 call assert_equal(expected, getjumplist()) 53 54 let l = getjumplist() 55 call test_garbagecollect_now() 56 call assert_equal(4, l[1]) 57 clearjumps 58 call test_garbagecollect_now() 59 call assert_equal(4, l[1]) 60 endfunc 61 62 func Test_jumplist_wipe_buf() 63 new 64 clearjumps 65 " Put some random text and fill the jump list. 66 call setline(1, ['foo', 'bar', 'baz']) 67 normal G 68 normal gg 69 setl nomodified bufhidden=wipe 70 e XXJumpListBuffer 71 " The jump list is empty as the buffer was wiped out. 72 call assert_equal([[], 0], getjumplist()) 73 let jumps = execute(':jumps') 74 call assert_equal('>', jumps[-1:]) 75 76 " Put some random text and fill the jump list. 77 call setline(1, ['foo', 'bar', 'baz']) 78 setl bufhidden=hide 79 80 " References to wiped buffer are deleted with multiple tabpages. 81 let [w1, t1] = [win_getid(), tabpagenr()] 82 clearjumps 83 normal G 84 normal gg 85 enew 86 87 split XXJumpListBuffer 88 let [w2, t2] = [win_getid(), tabpagenr()] 89 clearjumps 90 normal G 91 normal gg 92 enew 93 94 tabnew XXJumpListBuffer 95 let [w3, t3] = [win_getid(), tabpagenr()] 96 clearjumps 97 normal G 98 normal gg 99 enew 100 101 split XXJumpListBuffer 102 let [w4, t4] = [win_getid(), tabpagenr()] 103 clearjumps 104 normal G 105 normal gg 106 enew 107 108 for [w, t] in [[w1, t1], [w2, t2], [w3, t3], [w4, t4]] 109 call assert_equal(2, len(getjumplist(w, t)[0])) 110 endfor 111 112 bwipe! XXJumpListBuffer 113 114 for [w, t] in [[w1, t1], [w2, t2], [w3, t3], [w4, t4]] 115 call assert_equal(0, len(getjumplist(w, t)[0])) 116 endfor 117 118 %bwipe! 119 endfunc 120 121 " Test for '' mark in an empty buffer 122 123 func Test_empty_buffer() 124 new 125 insert 126 a 127 b 128 c 129 d 130 . 131 call assert_equal(1, line("''")) 132 bwipe! 133 endfunc 134 135 " Test for 'jumpoptions' 136 func Test_jumpoptions() 137 new 138 call setline(1, range(1, 200)) 139 clearjumps 140 set jumpoptions=stack 141 142 " Jump around to add some locations to the jump list. 143 normal 10G 144 normal 20G 145 normal 30G 146 normal 40G 147 normal 50G 148 let bnr = bufnr() 149 150 " discards the tail when navigating from the middle 151 exe "normal \<C-O>\<C-O>" 152 call 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 162 normal 90G 163 call 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 171 normal 60G 172 normal 60G 173 call 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 185 normal 10G 186 normal 20G 187 call 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 197 set jumpoptions& 198 %bw! 199 endfunc 200 201 " vim: shiftwidth=2 sts=2 expandtab