robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ff0352fd4f
master
1 2" Test that a deleted mark is restored after delete-undo-redo-undo. 3func Test_Restore_DelMark () 4enew ! 5call append ( 0 , [ " textline A" , " textline B" , " textline C" ]) 6normal ! 2gg 7set nocp viminfo += nviminfo 8exe "normal! i\<C-G>u\<Esc>" 9exe "normal! maddu\<C-R>u" 10let pos = getpos ( "'a" ) 11call assert_equal ( 2 , pos [ 1 ]) 12call assert_equal ( 1 , pos [ 2 ]) 13enew ! 14endfunc 15 16" Test that CTRL-A and CTRL-X updates last changed mark '[, ']. 17func Test_Incr_Marks () 18enew ! 19call append ( 0 , [ "123 123 123" , "123 123 123" , "123 123 123" ]) 20normal ! gg 21execute "normal! \<C-A>`[v`]rAjwvjw\<C-X>`[v`]rX" 22call assert_equal ( "AAA 123 123" , getline ( 1 )) 23call assert_equal ( "123 XXXXXXX" , getline ( 2 )) 24call assert_equal ( "XXX 123 123" , getline ( 3 )) 25enew ! 26endfunc 27 28func Test_previous_jump_mark () 29new 30call setline ( 1 , [ '' ] ->repeat ( 6 )) 31normal Ggg 32call assert_equal ( 6 , getpos ( "''" )[ 1 ]) 33normal jjjjj 34call assert_equal ( 6 , getpos ( "''" )[ 1 ]) 35bwipe ! 36endfunc 37 38func Test_setpos () 39new Xone 40let onebuf = bufnr ( '%' ) 41let onewin = win_getid () 42call setline ( 1 , [ 'aaa' , 'bbb' , 'ccc' ]) 43new Xtwo 44let twobuf = bufnr ( '%' ) 45let twowin = win_getid () 46call setline ( 1 , [ 'aaa' , 'bbb' , 'ccc' ]) 47 48" for the cursor the buffer number is ignored 49call setpos ( "." , [ 0 , 2 , 1 , 0 ]) 50call assert_equal ([ 0 , 2 , 1 , 0 ], getpos ( "." )) 51call setpos ( "." , [ onebuf , 3 , 3 , 0 ]) 52call assert_equal ([ 0 , 3 , 3 , 0 ], getpos ( "." )) 53 54call setpos ( "''" , [ 0 , 1 , 3 , 0 ]) 55call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( "''" )) 56call setpos ( "''" , [ onebuf , 2 , 2 , 0 ]) 57call assert_equal ([ 0 , 2 , 2 , 0 ], getpos ( "''" )) 58 59" buffer-local marks 60for mark in [ "'a" , "'\"" , "'[" , "']" , "'<" , "'>" ] 61call win_gotoid ( twowin ) 62call setpos ( mark , [ 0 , 2 , 1 , 0 ]) 63call assert_equal ([ 0 , 2 , 1 , 0 ], getpos ( mark ), "for mark " . mark ) 64call setpos ( mark , [ onebuf , 1 , 3 , 0 ]) 65call win_gotoid ( onewin ) 66call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( mark ), "for mark " . mark ) 67endfor 68 69" global marks 70call win_gotoid ( twowin ) 71call setpos ( "'N" , [ 0 , 2 , 1 , 0 ]) 72call assert_equal ([ twobuf , 2 , 1 , 0 ], getpos ( "'N" )) 73call setpos ( "'N" , [ onebuf , 1 , 3 , 0 ]) 74call assert_equal ([ onebuf , 1 , 3 , 0 ], getpos ( "'N" )) 75 76" try invalid column and check virtcol() 77call win_gotoid ( onewin ) 78call setpos ( "'a" , [ 0 , 1 , 2 , 0 ]) 79call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( "'a" )) 80call setpos ( "'a" , [ 0 , 1 , -5 , 0 ]) 81call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( "'a" )) 82call setpos ( "'a" , [ 0 , 1 , 0 , 0 ]) 83call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( "'a" )) 84call setpos ( "'a" , [ 0 , 1 , 4 , 0 ]) 85call assert_equal ([ 0 , 1 , 4 , 0 ], getpos ( "'a" )) 86call assert_equal ( 4 , virtcol ( "'a" )) 87call setpos ( "'a" , [ 0 , 1 , 5 , 0 ]) 88call assert_equal ([ 0 , 1 , 5 , 0 ], getpos ( "'a" )) 89call assert_equal ( 4 , virtcol ( "'a" )) 90call setpos ( "'a" , [ 0 , 1 , 21341234 , 0 ]) 91call assert_equal ([ 0 , 1 , 21341234 , 0 ], getpos ( "'a" )) 92call assert_equal ( 4 , virtcol ( "'a" )) 93 94" Test with invalid buffer number, line number and column number 95call cursor ( 2 , 2 ) 96call setpos ( '.' , [ -1 , 1 , 1 , 0 ]) 97call assert_equal ([ 2 , 2 ], [ line ( '.' ), col ( '.' )]) 98call setpos ( '.' , [ 0 , -1 , 1 , 0 ]) 99call assert_equal ([ 2 , 2 ], [ line ( '.' ), col ( '.' )]) 100call setpos ( '.' , [ 0 , 1 , -1 , 0 ]) 101call assert_equal ([ 2 , 2 ], [ line ( '.' ), col ( '.' )]) 102 103call assert_fails ( "call setpos('ab', [0, 1, 1, 0])" , 'E474:' ) 104 105bwipe ! 106call win_gotoid ( twowin ) 107bwipe ! 108endfunc 109 110func Test_marks_cmd () 111new Xone 112call setline ( 1 , [ 'aaa' , 'bbb' ]) 113norm ! maG$mB 114w ! 115new Xtwo 116call setline ( 1 , [ 'ccc' , 'ddd' ]) 117norm ! $mcGmD 118exe "norm! GVgg\<Esc>G" 119w ! 120 121b Xone 122let a = split ( execute ( 'marks' ), "\n" ) 123call assert_equal ( 9 , len ( a )) 124call assert_equal ([ 'mark line col file/text' , 125 \" ' 2 0 bbb" , 126 \' a 1 0 aaa' , 127 \' B 2 2 bbb' , 128 \' D 2 0 Xtwo' , 129 \' " 1 0 aaa' , 130 \' [ 1 0 aaa' , 131 \' ] 2 0 bbb' , 132 \' . 2 0 bbb' ], a ) 133 134b Xtwo 135let a = split ( execute ( 'marks' ), "\n" ) 136call assert_equal ( 11 , len ( a )) 137call assert_equal ([ 'mark line col file/text' , 138 \" ' 1 0 ccc" , 139 \' c 1 2 ccc' , 140 \' B 2 2 Xone' , 141 \' D 2 0 ddd' , 142 \' " 2 0 ddd' , 143 \' [ 1 0 ccc' , 144 \' ] 2 0 ddd' , 145 \' . 2 0 ddd' , 146 \' < 1 0 ccc' , 147 \' > 2 0 ddd' ], a ) 148norm ! Gdd 149w ! 150let a = split ( execute ( 'marks <>' ), "\n" ) 151call assert_equal ( 3 , len ( a )) 152call assert_equal ([ 'mark line col file/text' , 153 \' < 1 0 ccc' , 154 \' > 2 0 -invalid-' ], a ) 155 156b Xone 157delmarks aB 158let a = split ( execute ( 'marks aBcD' ), "\n" ) 159call assert_equal ( 2 , len ( a )) 160call assert_equal ( 'mark line col file/text' , a [ 0 ]) 161call assert_equal ( ' D 2 0 Xtwo' , a [ 1 ]) 162 163b Xtwo 164delmarks cD 165call assert_fails ( 'marks aBcD' , 'E283:' ) 166 167call delete ( 'Xone' ) 168call delete ( 'Xtwo' ) 169 %bwipe 170endfunc 171 172func Test_marks_cmd_multibyte () 173new Xone 174call setline ( 1 , [ repeat ( 'á' , & columns )]) 175norm ! ma 176 177let a = split ( execute ( 'marks a' ), "\n" ) 178call assert_equal ( 2 , len ( a )) 179let expected = ' a 1 0 ' . repeat ( 'á' , & columns - 16 ) 180call assert_equal ( expected , a [ 1 ]) 181 182bwipe ! 183endfunc 184 185func Test_delmarks () 186new 187norm mx 188norm `x 189delmarks x 190call assert_fails ( 'norm `x' , 'E20:' ) 191 192" Deleting an already deleted mark should not fail. 193delmarks x 194 195" getpos() should return all zeros after deleting a filemark. 196norm mA 197delmarks A 198call assert_equal ([ 0 , 0 , 0 , 0 ], getpos ( "'A" )) 199 200" Test deleting a range of marks. 201norm ma 202norm mb 203norm mc 204norm mz 205delmarks b-z 206norm `a 207call assert_fails ( 'norm `b' , 'E20:' ) 208call assert_fails ( 'norm `c' , 'E20:' ) 209call assert_fails ( 'norm `z' , 'E20:' ) 210call assert_fails ( 'delmarks z-b' , 'E475:' ) 211 212call assert_fails ( 'delmarks' , 'E471:' ) 213call assert_fails ( 'delmarks /' , 'E475:' ) 214 215" Test delmarks! 216norm mx 217norm `x 218delmarks ! 219call assert_fails ( 'norm `x' , 'E20:' ) 220call assert_fails ( 'delmarks! x' , 'E474:' ) 221 222bwipe ! 223endfunc 224 225func Test_mark_error () 226call assert_fails ( 'mark' , 'E471:' ) 227call assert_fails ( 'mark xx' , 'E488:' ) 228call assert_fails ( 'mark _' , 'E191:' ) 229call assert_beeps ( 'normal! m~' ) 230 231call setpos ( "'k" , [ 0 , 100 , 1 , 0 ]) 232call assert_fails ( "normal 'k" , 'E19:' ) 233endfunc 234 235" Test for :lockmarks when pasting content 236func Test_lockmarks_with_put () 237new 238call append ( 0 , repeat ([ 'sky is blue' ], 4 )) 239normal gg 2401 , 2 yank r 241put r 242normal G 243lockmarks put r 244call assert_equal ( 2 , line ( "'[" )) 245call assert_equal ( 3 , line ( "']" )) 246 247bwipe ! 248endfunc 249 250" Test for :k command to set a mark 251func Test_marks_k_cmd () 252new 253call setline ( 1 , [ 'foo' , 'bar' , 'baz' , 'qux' ]) 2541 , 3 kr 255call assert_equal ([ 0 , 3 , 1 , 0 ], getpos ( "'r" )) 256" whitespace before mark 2574 k f 258call assert_equal ([ 0 , 4 , 1 , 0 ], getpos ( "'f" )) 259: 2 k g 260call assert_equal ([ 0 , 2 , 1 , 0 ], getpos ( "'g" )) 261bw ! 262call assert_fails ( ':kz7' , 'E488: Trailing characters: z7' ) 263call assert_fails ( ':execute ":k^"' , 'E191: Argument must be a letter or forward/backward quote' ) 264endfunc 265 266" Test for file marks (A-Z) 267func Test_file_mark () 268new Xone 269call setline ( 1 , [ 'aaa' , 'bbb' ]) 270norm ! G$mB 271w ! 272new Xtwo 273call setline ( 1 , [ 'ccc' , 'ddd' ]) 274norm ! GmD 275w ! 276 277enew 278normal ! `B 279call assert_equal ( 'Xone' , bufname ()) 280call assert_equal ([ 2 , 3 ], [ line ( '.' ), col ( '.' )]) 281normal ! 'D 282call assert_equal ( 'Xtwo' , bufname ()) 283call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 284 285call delete ( 'Xone' ) 286call delete ( 'Xtwo' ) 287endfunc 288 289" Test for the getmarklist() function 290func Test_getmarklist () 291new 292" global marks 293delmarks A-Z 0-9 \" ^.[] 294call assert_equal ([], getmarklist ()) 295call setline ( 1 , [ 'one' , 'two' , 'three' ]) 296mark A 297call cursor ( 3 , 5 ) 298normal mN 299call assert_equal ([{ 'file' : '' , 'mark' : "'A" , 'pos' : [ bufnr (), 1 , 1 , 0 ]}, 300 \{ 'file' : '' , 'mark' : "'N" , 'pos' : [ bufnr (), 3 , 5 , 0 ]}], 301 \getmarklist ()) 302" buffer local marks 303delmarks ! 304call assert_equal ([{ 'mark' : "''" , 'pos' : [ bufnr (), 1 , 1 , 0 ]}, 305 \{ 'mark' : "'\"" , 'pos' : [ bufnr (), 1 , 1 , 0 ]}], getmarklist ( bufnr ())) 306call cursor ( 2 , 2 ) 307normal mr 308call assert_equal ({ 'mark' : "'r" , 'pos' : [ bufnr (), 2 , 2 , 0 ]}, 309 \bufnr () ->getmarklist ()[ 0 ]) 310call assert_equal ([], {} ->getmarklist ()) 311normal ! yy 312call assert_equal ([ 313 \{ 'mark' : "'[" , 'pos' : [ bufnr (), 2 , 1 , 0 ]}, 314 \{ 'mark' : "']" , 'pos' : [ bufnr (), 2 , v: maxcol , 0 ]}, 315 \], getmarklist ( bufnr ())[ -2 :]) 316bw ! 317endfunc 318 319" This was using freed memory 320func Test_jump_mark_autocmd () 321next 00 322edit 0 323sargument 324au BufEnter 0 all 325sil norm 326 327 au ! BufEnter 328bwipe ! 329endfunc 330 331func Test_mark_formatprg_on_empty () 332new 333if has ( 'win32' ) 334setl formatprg = more 335else 336setl formatprg = cat 337endif 338call assert_equal ([ 0 , 0 ], [ line ( "'[" ), col ( "'[" )]) 339call assert_equal ([ 0 , 0 ], [ line ( "']" ), col ( "']" )]) 340let v: errmsg = '' 341try 342norm ! gqG 343catch 344call assert_report ( 'gqG on empty buffer should not fail: ' .. v: exception ) 345endtry 346call assert_true ( empty ( v: errmsg )) 347" col() is 1-based, so 1 == first column (:marks shows it as 0) 348call assert_equal ([ 1 , 1 ], [ line ( "'[" ), col ( "'[" )]) 349call assert_equal ([ 1 , 1 ], [ line ( "']" ), col ( "']" )]) 350bwipe ! 351endfunc 352 353" vim: shiftwidth=2 sts=2 expandtab