1 2" Test that a deleted mark is restored after delete-undo-redo-undo. 3func Test_Restore_DelMark() 4 enew! 5 call append(0, [" textline A", " textline B", " textline C"]) 6 normal! 2gg 7 set nocp viminfo+=nviminfo 8 exe "normal! i\<C-G>u\<Esc>" 9 exe "normal! maddu\<C-R>u" 10 let pos = getpos("'a") 11 call assert_equal(2, pos[1]) 12 call assert_equal(1, pos[2]) 13 enew! 14endfunc 15 16" Test that CTRL-A and CTRL-X updates last changed mark '[, ']. 17func Test_Incr_Marks() 18 enew! 19 call append(0, ["123 123 123", "123 123 123", "123 123 123"]) 20 normal! gg 21 execute "normal! \<C-A>`[v`]rAjwvjw\<C-X>`[v`]rX" 22 call assert_equal("AAA 123 123", getline(1)) 23 call assert_equal("123 XXXXXXX", getline(2)) 24 call assert_equal("XXX 123 123", getline(3)) 25 enew! 26endfunc 27 28func Test_setpos() 29 new Xone 30 let onebuf = bufnr('%') 31 let onewin = win_getid() 32 call setline(1, ['aaa', 'bbb', 'ccc']) 33 new Xtwo 34 let twobuf = bufnr('%') 35 let twowin = win_getid() 36 call setline(1, ['aaa', 'bbb', 'ccc']) 37 38 " for the cursor the buffer number is ignored 39 call setpos(".", [0, 2, 1, 0]) 40 call assert_equal([0, 2, 1, 0], getpos(".")) 41 call setpos(".", [onebuf, 3, 3, 0]) 42 call assert_equal([0, 3, 3, 0], getpos(".")) 43 44 call setpos("''", [0, 1, 3, 0]) 45 call assert_equal([0, 1, 3, 0], getpos("''")) 46 call setpos("''", [onebuf, 2, 2, 0]) 47 call assert_equal([0, 2, 2, 0], getpos("''")) 48 49 " buffer-local marks 50 for mark in ["'a", "'\"", "'[", "']", "'<", "'>"] 51 call win_gotoid(twowin) 52 call setpos(mark, [0, 2, 1, 0]) 53 call assert_equal([0, 2, 1, 0], getpos(mark), "for mark " . mark) 54 call setpos(mark, [onebuf, 1, 3, 0]) 55 call win_gotoid(onewin) 56 call assert_equal([0, 1, 3, 0], getpos(mark), "for mark " . mark) 57 endfor 58 59 " global marks 60 call win_gotoid(twowin) 61 call setpos("'N", [0, 2, 1, 0]) 62 call assert_equal([twobuf, 2, 1, 0], getpos("'N")) 63 call setpos("'N", [onebuf, 1, 3, 0]) 64 call assert_equal([onebuf, 1, 3, 0], getpos("'N")) 65 66 " try invalid column and check virtcol() 67 call win_gotoid(onewin) 68 call setpos("'a", [0, 1, 2, 0]) 69 call assert_equal([0, 1, 2, 0], getpos("'a")) 70 call setpos("'a", [0, 1, -5, 0]) 71 call assert_equal([0, 1, 2, 0], getpos("'a")) 72 call setpos("'a", [0, 1, 0, 0]) 73 call assert_equal([0, 1, 1, 0], getpos("'a")) 74 call setpos("'a", [0, 1, 4, 0]) 75 call assert_equal([0, 1, 4, 0], getpos("'a")) 76 call assert_equal(4, virtcol("'a")) 77 call setpos("'a", [0, 1, 5, 0]) 78 call assert_equal([0, 1, 5, 0], getpos("'a")) 79 call assert_equal(4, virtcol("'a")) 80 call setpos("'a", [0, 1, 21341234, 0]) 81 call assert_equal([0, 1, 21341234, 0], getpos("'a")) 82 call assert_equal(4, virtcol("'a")) 83 84 " Test with invalid buffer number, line number and column number 85 call cursor(2, 2) 86 call setpos('.', [-1, 1, 1, 0]) 87 call assert_equal([2, 2], [line('.'), col('.')]) 88 call setpos('.', [0, -1, 1, 0]) 89 call assert_equal([2, 2], [line('.'), col('.')]) 90 call setpos('.', [0, 1, -1, 0]) 91 call assert_equal([2, 2], [line('.'), col('.')]) 92 93 call assert_fails("call setpos('ab', [0, 1, 1, 0])", 'E474:') 94 95 bwipe! 96 call win_gotoid(twowin) 97 bwipe! 98endfunc 99 100func Test_marks_cmd() 101 new Xone 102 call setline(1, ['aaa', 'bbb']) 103 norm! maG$mB 104 w! 105 new Xtwo 106 call setline(1, ['ccc', 'ddd']) 107 norm! $mcGmD 108 w! 109 110 b Xone 111 let a = split(execute('marks'), "\n") 112 call assert_equal(9, len(a)) 113 call assert_equal('mark line col file/text', a[0]) 114 call assert_equal(" ' 2 0 bbb", a[1]) 115 call assert_equal(' a 1 0 aaa', a[2]) 116 call assert_equal(' B 2 2 bbb', a[3]) 117 call assert_equal(' D 2 0 Xtwo', a[4]) 118 call assert_equal(' " 1 0 aaa', a[5]) 119 call assert_equal(' [ 1 0 aaa', a[6]) 120 call assert_equal(' ] 2 0 bbb', a[7]) 121 call assert_equal(' . 2 0 bbb', a[8]) 122 123 b Xtwo 124 let a = split(execute('marks'), "\n") 125 call assert_equal(9, len(a)) 126 call assert_equal('mark line col file/text', a[0]) 127 call assert_equal(" ' 1 0 ccc", a[1]) 128 call assert_equal(' c 1 2 ccc', a[2]) 129 call assert_equal(' B 2 2 Xone', a[3]) 130 call assert_equal(' D 2 0 ddd', a[4]) 131 call assert_equal(' " 2 0 ddd', a[5]) 132 call assert_equal(' [ 1 0 ccc', a[6]) 133 call assert_equal(' ] 2 0 ddd', a[7]) 134 call assert_equal(' . 2 0 ddd', a[8]) 135 136 b Xone 137 delmarks aB 138 let a = split(execute('marks aBcD'), "\n") 139 call assert_equal(2, len(a)) 140 call assert_equal('mark line col file/text', a[0]) 141 call assert_equal(' D 2 0 Xtwo', a[1]) 142 143 b Xtwo 144 delmarks cD 145 call assert_fails('marks aBcD', 'E283:') 146 147 call delete('Xone') 148 call delete('Xtwo') 149 %bwipe 150endfunc 151 152func Test_marks_cmd_multibyte() 153 new Xone 154 call setline(1, [repeat('á', &columns)]) 155 norm! ma 156 157 let a = split(execute('marks a'), "\n") 158 call assert_equal(2, len(a)) 159 let expected = ' a 1 0 ' . repeat('á', &columns - 16) 160 call assert_equal(expected, a[1]) 161 162 bwipe! 163endfunc 164 165func Test_delmarks() 166 new 167 norm mx 168 norm `x 169 delmarks x 170 call assert_fails('norm `x', 'E20:') 171 172 " Deleting an already deleted mark should not fail. 173 delmarks x 174 175 " getpos() should return all zeros after deleting a filemark. 176 norm mA 177 delmarks A 178 call assert_equal([0, 0, 0, 0], getpos("'A")) 179 180 " Test deleting a range of marks. 181 norm ma 182 norm mb 183 norm mc 184 norm mz 185 delmarks b-z 186 norm `a 187 call assert_fails('norm `b', 'E20:') 188 call assert_fails('norm `c', 'E20:') 189 call assert_fails('norm `z', 'E20:') 190 call assert_fails('delmarks z-b', 'E475:') 191 192 call assert_fails('delmarks', 'E471:') 193 call assert_fails('delmarks /', 'E475:') 194 195 " Test delmarks! 196 norm mx 197 norm `x 198 delmarks! 199 call assert_fails('norm `x', 'E20:') 200 call assert_fails('delmarks! x', 'E474:') 201 202 bwipe! 203endfunc 204 205func Test_mark_error() 206 call assert_fails('mark', 'E471:') 207 call assert_fails('mark xx', 'E488:') 208 call assert_fails('mark _', 'E191:') 209 call assert_beeps('normal! m~') 210 211 call setpos("'k", [0, 100, 1, 0]) 212 call assert_fails("normal 'k", 'E19:') 213endfunc 214 215" Test for :lockmarks when pasting content 216func Test_lockmarks_with_put() 217 new 218 call append(0, repeat(['sky is blue'], 4)) 219 normal gg 220 1,2yank r 221 put r 222 normal G 223 lockmarks put r 224 call assert_equal(2, line("'[")) 225 call assert_equal(3, line("']")) 226 227 bwipe! 228endfunc 229 230" Test for :k command to set a mark 231func Test_marks_k_cmd() 232 new 233 call setline(1, ['foo', 'bar', 'baz', 'qux']) 234 1,3kr 235 call assert_equal([0, 3, 1, 0], getpos("'r")) 236 close! 237endfunc 238 239" Test for file marks (A-Z) 240func Test_file_mark() 241 new Xone 242 call setline(1, ['aaa', 'bbb']) 243 norm! G$mB 244 w! 245 new Xtwo 246 call setline(1, ['ccc', 'ddd']) 247 norm! GmD 248 w! 249 250 enew 251 normal! `B 252 call assert_equal('Xone', bufname()) 253 call assert_equal([2, 3], [line('.'), col('.')]) 254 normal! 'D 255 call assert_equal('Xtwo', bufname()) 256 call assert_equal([2, 1], [line('.'), col('.')]) 257 258 call delete('Xone') 259 call delete('Xtwo') 260endfunc 261 262" Test for the getmarklist() function 263func Test_getmarklist() 264 new 265 " global marks 266 delmarks A-Z 0-9 \" ^.[] 267 call assert_equal([], getmarklist()) 268 call setline(1, ['one', 'two', 'three']) 269 mark A 270 call cursor(3, 5) 271 normal mN 272 call assert_equal([{'file' : '', 'mark' : "'A", 'pos' : [bufnr(), 1, 1, 0]}, 273 \ {'file' : '', 'mark' : "'N", 'pos' : [bufnr(), 3, 5, 0]}], 274 \ getmarklist()) 275 " buffer local marks 276 delmarks! 277 call assert_equal([{'mark' : "''", 'pos' : [bufnr(), 1, 1, 0]}, 278 \ {'mark' : "'\"", 'pos' : [bufnr(), 1, 1, 0]}], getmarklist(bufnr())) 279 call cursor(2, 2) 280 normal mr 281 call assert_equal({'mark' : "'r", 'pos' : [bufnr(), 2, 2, 0]}, 282 \ bufnr()->getmarklist()[0]) 283 call assert_equal([], {}->getmarklist()) 284 close! 285endfunc 286 287" vim: shiftwidth=2 sts=2 expandtab 288