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 bwipe! 85 call win_gotoid(twowin) 86 bwipe! 87endfunc 88 89func Test_marks_cmd() 90 new Xone 91 call setline(1, ['aaa', 'bbb']) 92 norm! maG$mB 93 w! 94 new Xtwo 95 call setline(1, ['ccc', 'ddd']) 96 norm! $mcGmD 97 w! 98 99 b Xone 100 let a = split(execute('marks'), "\n") 101 call assert_equal(9, len(a)) 102 call assert_equal('mark line col file/text', a[0]) 103 call assert_equal(" ' 2 0 bbb", a[1]) 104 call assert_equal(' a 1 0 aaa', a[2]) 105 call assert_equal(' B 2 2 bbb', a[3]) 106 call assert_equal(' D 2 0 Xtwo', a[4]) 107 call assert_equal(' " 1 0 aaa', a[5]) 108 call assert_equal(' [ 1 0 aaa', a[6]) 109 call assert_equal(' ] 2 0 bbb', a[7]) 110 call assert_equal(' . 2 0 bbb', a[8]) 111 112 b Xtwo 113 let a = split(execute('marks'), "\n") 114 call assert_equal(9, len(a)) 115 call assert_equal('mark line col file/text', a[0]) 116 call assert_equal(" ' 1 0 ccc", a[1]) 117 call assert_equal(' c 1 2 ccc', a[2]) 118 call assert_equal(' B 2 2 Xone', a[3]) 119 call assert_equal(' D 2 0 ddd', a[4]) 120 call assert_equal(' " 2 0 ddd', a[5]) 121 call assert_equal(' [ 1 0 ccc', a[6]) 122 call assert_equal(' ] 2 0 ddd', a[7]) 123 call assert_equal(' . 2 0 ddd', a[8]) 124 125 b Xone 126 delmarks aB 127 let a = split(execute('marks aBcD'), "\n") 128 call assert_equal(2, len(a)) 129 call assert_equal('mark line col file/text', a[0]) 130 call assert_equal(' D 2 0 Xtwo', a[1]) 131 132 b Xtwo 133 delmarks cD 134 call assert_fails('marks aBcD', 'E283:') 135 136 call delete('Xone') 137 call delete('Xtwo') 138 %bwipe 139endfunc 140 141func Test_marks_cmd_multibyte() 142 new Xone 143 call setline(1, [repeat('á', &columns)]) 144 norm! ma 145 146 let a = split(execute('marks a'), "\n") 147 call assert_equal(2, len(a)) 148 let expected = ' a 1 0 ' . repeat('á', &columns - 16) 149 call assert_equal(expected, a[1]) 150 151 bwipe! 152endfunc 153 154func Test_delmarks() 155 new 156 norm mx 157 norm `x 158 delmarks x 159 call assert_fails('norm `x', 'E20:') 160 161 " Deleting an already deleted mark should not fail. 162 delmarks x 163 164 " getpos() should return all zeros after deleting a filemark. 165 norm mA 166 delmarks A 167 call assert_equal([0, 0, 0, 0], getpos("'A")) 168 169 " Test deleting a range of marks. 170 norm ma 171 norm mb 172 norm mc 173 norm mz 174 delmarks b-z 175 norm `a 176 call assert_fails('norm `b', 'E20:') 177 call assert_fails('norm `c', 'E20:') 178 call assert_fails('norm `z', 'E20:') 179 call assert_fails('delmarks z-b', 'E475:') 180 181 call assert_fails('delmarks', 'E471:') 182 call assert_fails('delmarks /', 'E475:') 183 184 " Test delmarks! 185 norm mx 186 norm `x 187 delmarks! 188 call assert_fails('norm `x', 'E20:') 189 call assert_fails('delmarks! x', 'E474:') 190 191 bwipe! 192endfunc 193 194func Test_mark_error() 195 call assert_fails('mark', 'E471:') 196 call assert_fails('mark xx', 'E488:') 197 call assert_fails('mark _', 'E191:') 198endfunc 199 200" Test for :lockmarks when pasting content 201func Test_lockmarks_with_put() 202 new 203 call append(0, repeat(['sky is blue'], 4)) 204 normal gg 205 1,2yank r 206 put r 207 normal G 208 lockmarks put r 209 call assert_equal(2, line("'[")) 210 call assert_equal(3, line("']")) 211 212 bwipe! 213endfunc 214 215" vim: shiftwidth=2 sts=2 expandtab 216