1" Test for reading and writing .viminfo 2 3source check.vim 4source term_util.vim 5source shared.vim 6 7function Test_viminfo_read_and_write() 8 " First clear 'history', so that "hislen" is zero. Then set it again, 9 " simulating Vim starting up. 10 set history=0 11 wviminfo Xviminfo 12 set history=1000 13 14 call histdel(':') 15 let lines = [ 16 \ '# comment line', 17 \ '*encoding=utf-8', 18 \ '~MSle0~/asdf', 19 \ '|copied as-is', 20 \ '|and one more', 21 \ ] 22 call writefile(lines, 'Xviminfo') 23 rviminfo Xviminfo 24 call assert_equal('asdf', @/) 25 26 wviminfo Xviminfo 27 let lines = readfile('Xviminfo') 28 let done = 0 29 for line in lines 30 if line[0] == '|' && line !~ '^|[234],' && line !~ '^|<' 31 if done == 0 32 call assert_equal('|1,4', line) 33 elseif done == 1 34 call assert_equal('|copied as-is', line) 35 elseif done == 2 36 call assert_equal('|and one more', line) 37 endif 38 let done += 1 39 endif 40 endfor 41 call assert_equal(3, done) 42 43 call delete('Xviminfo') 44endfunc 45 46func Test_global_vars() 47 let g:MY_GLOBAL_STRING = "Vim Editor" 48 let g:MY_GLOBAL_NUM = 345 49 let g:MY_GLOBAL_FLOAT = 3.14 50 let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000} 51 let g:MY_GLOBAL_DICT = test_dict 52 " store a really long list, so line wrapping will occur in viminfo file 53 let test_list = range(1,100) 54 let g:MY_GLOBAL_LIST = test_list 55 let test_blob = 0z00112233445566778899aabbccddeeff 56 let g:MY_GLOBAL_BLOB = test_blob 57 let test_false = v:false 58 let g:MY_GLOBAL_FALSE = test_false 59 let test_true = v:true 60 let g:MY_GLOBAL_TRUE = test_true 61 let test_null = v:null 62 let g:MY_GLOBAL_NULL = test_null 63 let test_none = v:none 64 let g:MY_GLOBAL_NONE = test_none 65 66 set viminfo='100,<50,s10,h,!,nviminfo 67 wv! Xviminfo 68 69 unlet g:MY_GLOBAL_STRING 70 unlet g:MY_GLOBAL_NUM 71 unlet g:MY_GLOBAL_FLOAT 72 unlet g:MY_GLOBAL_DICT 73 unlet g:MY_GLOBAL_LIST 74 unlet g:MY_GLOBAL_BLOB 75 unlet g:MY_GLOBAL_FALSE 76 unlet g:MY_GLOBAL_TRUE 77 unlet g:MY_GLOBAL_NULL 78 unlet g:MY_GLOBAL_NONE 79 80 rv! Xviminfo 81 call assert_equal("Vim Editor", g:MY_GLOBAL_STRING) 82 call assert_equal(345, g:MY_GLOBAL_NUM) 83 call assert_equal(3.14, g:MY_GLOBAL_FLOAT) 84 call assert_equal(test_dict, g:MY_GLOBAL_DICT) 85 call assert_equal(test_list, g:MY_GLOBAL_LIST) 86 call assert_equal(test_blob, g:MY_GLOBAL_BLOB) 87 call assert_equal(test_false, g:MY_GLOBAL_FALSE) 88 call assert_equal(test_true, g:MY_GLOBAL_TRUE) 89 call assert_equal(test_null, g:MY_GLOBAL_NULL) 90 call assert_equal(test_none, g:MY_GLOBAL_NONE) 91 92 " Test for invalid values for a blob, list, dict in a viminfo file 93 call writefile([ 94 \ "!GLOB_BLOB_1\tBLO\t123", 95 \ "!GLOB_BLOB_2\tBLO\t012", 96 \ "!GLOB_BLOB_3\tBLO\t0z1x", 97 \ "!GLOB_BLOB_4\tBLO\t0z12 ab", 98 \ "!GLOB_LIST_1\tLIS\t1 2", 99 \ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo') 100 call assert_fails('rv! Xviminfo', 'E15:') 101 call assert_equal('123', g:GLOB_BLOB_1) 102 call assert_equal(1, type(g:GLOB_BLOB_1)) 103 call assert_equal('012', g:GLOB_BLOB_2) 104 call assert_equal(1, type(g:GLOB_BLOB_2)) 105 call assert_equal('0z1x', g:GLOB_BLOB_3) 106 call assert_equal(1, type(g:GLOB_BLOB_3)) 107 call assert_equal('0z12 ab', g:GLOB_BLOB_4) 108 call assert_equal(1, type(g:GLOB_BLOB_4)) 109 call assert_equal('1 2', g:GLOB_LIST_1) 110 call assert_equal(1, type(g:GLOB_LIST_1)) 111 call assert_equal('1 2', g:GLOB_DICT_1) 112 call assert_equal(1, type(g:GLOB_DICT_1)) 113 114 call delete('Xviminfo') 115 set viminfo-=! 116endfunc 117 118func Test_global_vars_with_circular_reference() 119 let g:MY_GLOBAL_LIST = [] 120 call add(g:MY_GLOBAL_LIST, g:MY_GLOBAL_LIST) 121 let g:MY_GLOBAL_DICT = {} 122 let g:MY_GLOBAL_DICT['self'] = g:MY_GLOBAL_DICT 123 124 set viminfo='100,<50,s10,h,!,nviminfo 125 wv! Xviminfo 126 call assert_equal(v:errmsg, '') 127 128 unlet g:MY_GLOBAL_LIST 129 unlet g:MY_GLOBAL_DICT 130 131 rv! Xviminfo 132 call assert_equal(v:errmsg, '') 133 call assert_true(!exists('g:MY_GLOBAL_LIST')) 134 call assert_true(!exists('g:MY_GLOBAL_DICT')) 135 136 call delete('Xviminfo') 137 set viminfo-=! 138endfunc 139 140func Test_cmdline_history() 141 call histdel(':') 142 call test_settime(11) 143 call histadd(':', "echo 'one'") 144 call test_settime(12) 145 " split into two lines 146 let long800 = repeat(" 'eight'", 100) 147 call histadd(':', "echo " . long800) 148 call test_settime(13) 149 " split into three lines 150 let long1400 = repeat(" 'fourteeeeen'", 100) 151 call histadd(':', "echo " . long1400) 152 wviminfo Xviminfo 153 let lines = readfile('Xviminfo') 154 let done_colon = 0 155 let done_bar = 0 156 let lnum = 0 157 while lnum < len(lines) 158 let line = lines[lnum] | let lnum += 1 159 if line[0] == ':' 160 if done_colon == 0 161 call assert_equal(":\x161408", line) 162 let line = lines[lnum] | let lnum += 1 163 call assert_equal('<echo ' . long1400, line) 164 elseif done_colon == 1 165 call assert_equal(":\x16808", line) 166 let line = lines[lnum] | let lnum += 1 167 call assert_equal("<echo " . long800, line) 168 elseif done_colon == 2 169 call assert_equal(":echo 'one'", line) 170 endif 171 let done_colon += 1 172 elseif line[0:4] == '|2,0,' 173 if done_bar == 0 174 call assert_equal("|2,0,13,,>1407", line) 175 let line = lines[lnum] | let lnum += 1 176 call assert_equal('|<"echo ' . long1400[0:484], line) 177 let line = lines[lnum] | let lnum += 1 178 call assert_equal('|<' . long1400[485:974], line) 179 let line = lines[lnum] | let lnum += 1 180 call assert_equal('|<' . long1400[975:] . '"', line) 181 elseif done_bar == 1 182 call assert_equal('|2,0,12,,>807', line) 183 let line = lines[lnum] | let lnum += 1 184 call assert_equal('|<"echo ' . long800[0:484], line) 185 let line = lines[lnum] | let lnum += 1 186 call assert_equal('|<' . long800[485:] . '"', line) 187 elseif done_bar == 2 188 call assert_equal("|2,0,11,,\"echo 'one'\"", line) 189 endif 190 let done_bar += 1 191 endif 192 endwhile 193 call assert_equal(3, done_colon) 194 call assert_equal(3, done_bar) 195 196 call histdel(':') 197 rviminfo Xviminfo 198 call assert_equal("echo " . long1400, histget(':', -1)) 199 call assert_equal("echo " . long800, histget(':', -2)) 200 call assert_equal("echo 'one'", histget(':', -3)) 201 202 call delete('Xviminfo') 203endfunc 204 205func Test_cmdline_history_order() 206 call histdel(':') 207 call test_settime(11) 208 call histadd(':', "echo '11'") 209 call test_settime(22) 210 call histadd(':', "echo '22'") 211 call test_settime(33) 212 call histadd(':', "echo '33'") 213 wviminfo Xviminfo 214 215 call histdel(':') 216 " items go in between 217 call test_settime(15) 218 call histadd(':', "echo '15'") 219 call test_settime(27) 220 call histadd(':', "echo '27'") 221 222 rviminfo Xviminfo 223 call assert_equal("echo '33'", histget(':', -1)) 224 call assert_equal("echo '27'", histget(':', -2)) 225 call assert_equal("echo '22'", histget(':', -3)) 226 call assert_equal("echo '15'", histget(':', -4)) 227 call assert_equal("echo '11'", histget(':', -5)) 228 229 call histdel(':') 230 " items go before and after 231 eval 8->test_settime() 232 call histadd(':', "echo '8'") 233 call test_settime(39) 234 call histadd(':', "echo '39'") 235 236 rviminfo Xviminfo 237 call assert_equal("echo '39'", histget(':', -1)) 238 call assert_equal("echo '33'", histget(':', -2)) 239 call assert_equal("echo '22'", histget(':', -3)) 240 call assert_equal("echo '11'", histget(':', -4)) 241 call assert_equal("echo '8'", histget(':', -5)) 242 243 " Check sorting works when writing with merge. 244 call histdel(':') 245 call test_settime(8) 246 call histadd(':', "echo '8'") 247 call test_settime(15) 248 call histadd(':', "echo '15'") 249 call test_settime(27) 250 call histadd(':', "echo '27'") 251 call test_settime(39) 252 call histadd(':', "echo '39'") 253 wviminfo Xviminfo 254 255 call histdel(':') 256 rviminfo Xviminfo 257 call assert_equal("echo '39'", histget(':', -1)) 258 call assert_equal("echo '33'", histget(':', -2)) 259 call assert_equal("echo '27'", histget(':', -3)) 260 call assert_equal("echo '22'", histget(':', -4)) 261 call assert_equal("echo '15'", histget(':', -5)) 262 call assert_equal("echo '11'", histget(':', -6)) 263 call assert_equal("echo '8'", histget(':', -7)) 264 265 call delete('Xviminfo') 266endfunc 267 268func Test_viminfo_registers() 269 call test_settime(8) 270 call setreg('a', "eight", 'c') 271 call test_settime(20) 272 call setreg('b', ["twenty", "again"], 'l') 273 call test_settime(40) 274 call setreg('c', ["four", "agai"], 'b4') 275 let l = [] 276 set viminfo='100,<600,s10,h,!,nviminfo 277 for i in range(500) 278 call add(l, 'something') 279 endfor 280 call setreg('d', l, 'l') 281 call setreg('e', "abc\<C-V>xyz") 282 wviminfo Xviminfo 283 284 call test_settime(10) 285 call setreg('a', '', 'b10') 286 call test_settime(15) 287 call setreg('b', 'drop') 288 call test_settime(50) 289 call setreg('c', 'keep', 'l') 290 call test_settime(30) 291 call setreg('d', 'drop', 'l') 292 call setreg('e', 'drop') 293 rviminfo Xviminfo 294 295 call assert_equal("", getreg('a')) 296 call assert_equal("\<C-V>10", getregtype('a')) 297 call assert_equal("twenty\nagain\n", getreg('b')) 298 call assert_equal("V", getregtype('b')) 299 call assert_equal("keep\n", getreg('c')) 300 call assert_equal("V", getregtype('c')) 301 call assert_equal(l, getreg('d', 1, 1)) 302 call assert_equal("V", getregtype('d')) 303 call assert_equal("abc\<C-V>xyz", getreg('e')) 304 305 " Length around 440 switches to line continuation. 306 let len = 434 307 while len < 445 308 let s = repeat('a', len) 309 call setreg('"', s) 310 wviminfo Xviminfo 311 call setreg('"', '') 312 rviminfo Xviminfo 313 call assert_equal(s, getreg('"'), 'wrong register at length: ' . len) 314 315 let len += 1 316 endwhile 317 318 call delete('Xviminfo') 319endfunc 320 321func Test_viminfo_marks() 322 sp bufa 323 let bufa = bufnr('%') 324 sp bufb 325 let bufb = bufnr('%') 326 327 call test_settime(8) 328 call setpos("'A", [bufa, 1, 1, 0]) 329 call test_settime(20) 330 call setpos("'B", [bufb, 9, 1, 0]) 331 call setpos("'C", [bufa, 7, 1, 0]) 332 333 delmark 0-9 334 call test_settime(25) 335 call setpos("'1", [bufb, 12, 1, 0]) 336 call test_settime(35) 337 call setpos("'0", [bufa, 11, 1, 0]) 338 339 call test_settime(45) 340 wviminfo Xviminfo 341 342 " Writing viminfo inserts the '0 mark. 343 call assert_equal([bufb, 1, 1, 0], getpos("'0")) 344 call assert_equal([bufa, 11, 1, 0], getpos("'1")) 345 call assert_equal([bufb, 12, 1, 0], getpos("'2")) 346 347 call test_settime(4) 348 call setpos("'A", [bufa, 9, 1, 0]) 349 call test_settime(30) 350 call setpos("'B", [bufb, 2, 3, 0]) 351 delmark C 352 353 delmark 0-9 354 call test_settime(30) 355 call setpos("'1", [bufb, 22, 1, 0]) 356 call test_settime(55) 357 call setpos("'0", [bufa, 21, 1, 0]) 358 359 rviminfo Xviminfo 360 361 call assert_equal([bufa, 1, 1, 0], getpos("'A")) 362 call assert_equal([bufb, 2, 3, 0], getpos("'B")) 363 call assert_equal([bufa, 7, 1, 0], getpos("'C")) 364 365 " numbered marks are merged 366 call assert_equal([bufa, 21, 1, 0], getpos("'0")) " time 55 367 call assert_equal([bufb, 1, 1, 0], getpos("'1")) " time 45 368 call assert_equal([bufa, 11, 1, 0], getpos("'2")) " time 35 369 call assert_equal([bufb, 22, 1, 0], getpos("'3")) " time 30 370 call assert_equal([bufb, 12, 1, 0], getpos("'4")) " time 25 371 372 " deleted file marks are removed from viminfo 373 delmark C 374 wviminfo Xviminfo 375 rviminfo Xviminfo 376 call assert_equal([0, 0, 0, 0], getpos("'C")) 377 378 " deleted file marks stay in viminfo if defined in another vim later 379 call test_settime(70) 380 call setpos("'D", [bufb, 8, 1, 0]) 381 wviminfo Xviminfo 382 call test_settime(65) 383 delmark D 384 call assert_equal([0, 0, 0, 0], getpos("'D")) 385 call test_settime(75) 386 rviminfo Xviminfo 387 call assert_equal([bufb, 8, 1, 0], getpos("'D")) 388 389 call delete('Xviminfo') 390 exe 'bwipe ' . bufa 391 exe 'bwipe ' . bufb 392endfunc 393 394func Test_viminfo_jumplist() 395 split testbuf 396 clearjumps 397 call setline(1, ['time 05', 'time 10', 'time 15', 'time 20', 'time 30', 'last pos']) 398 call cursor(2, 1) 399 call test_settime(10) 400 exe "normal /20\r" 401 call test_settime(20) 402 exe "normal /30\r" 403 call test_settime(30) 404 exe "normal /last pos\r" 405 wviminfo Xviminfo 406 407 clearjumps 408 call cursor(1, 1) 409 call test_settime(5) 410 exe "normal /15\r" 411 call test_settime(15) 412 exe "normal /last pos\r" 413 call test_settime(40) 414 exe "normal ?30\r" 415 rviminfo Xviminfo 416 417 call assert_equal('time 30', getline('.')) 418 exe "normal \<C-O>" 419 call assert_equal('last pos', getline('.')) 420 exe "normal \<C-O>" 421 " duplicate for 'time 30' was removed 422 call assert_equal('time 20', getline('.')) 423 exe "normal \<C-O>" 424 call assert_equal('time 15', getline('.')) 425 exe "normal \<C-O>" 426 call assert_equal('time 10', getline('.')) 427 exe "normal \<C-O>" 428 call assert_equal('time 05', getline('.')) 429 430 clearjumps 431 call cursor(1, 1) 432 call test_settime(5) 433 exe "normal /15\r" 434 call test_settime(15) 435 exe "normal /last pos\r" 436 call test_settime(40) 437 exe "normal ?30\r" 438 " Test merge when writing 439 wviminfo Xviminfo 440 clearjumps 441 rviminfo Xviminfo 442 443 let last_line = line('.') 444 exe "normal \<C-O>" 445 call assert_equal('time 30', getline('.')) 446 exe "normal \<C-O>" 447 call assert_equal('last pos', getline('.')) 448 exe "normal \<C-O>" 449 " duplicate for 'time 30' was removed 450 call assert_equal('time 20', getline('.')) 451 exe "normal \<C-O>" 452 call assert_equal('time 15', getline('.')) 453 exe "normal \<C-O>" 454 call assert_equal('time 10', getline('.')) 455 exe "normal \<C-O>" 456 call assert_equal('time 05', getline('.')) 457 458 " Test with jumplist full. 459 clearjumps 460 call setline(1, repeat(['match here'], 101)) 461 call cursor(1, 1) 462 call test_settime(10) 463 for i in range(100) 464 exe "normal /here\r" 465 endfor 466 rviminfo Xviminfo 467 468 " must be newest mark that comes from viminfo. 469 exe "normal \<C-O>" 470 call assert_equal(last_line, line('.')) 471 472 bwipe! 473 call delete('Xviminfo') 474endfunc 475 476func Test_viminfo_encoding() 477 set enc=latin1 478 call histdel(':') 479 call histadd(':', "echo '\xe9'") 480 wviminfo Xviminfo 481 482 set fencs=utf-8,latin1 483 set enc=utf-8 484 sp Xviminfo 485 call assert_equal('latin1', &fenc) 486 close 487 488 call histdel(':') 489 rviminfo Xviminfo 490 call assert_equal("echo 'é'", histget(':', -1)) 491 492 call delete('Xviminfo') 493endfunc 494 495func Test_viminfo_bad_syntax() 496 let lines = [] 497 call add(lines, '|<') " empty continuation line 498 call add(lines, '|234234234234234324,nothing') 499 call add(lines, '|1+"no comma"') 500 call add(lines, '|1,2,3,4,5,6,7') " too many items 501 call add(lines, '|1,"string version"') 502 call add(lines, '|1,>x') " bad continuation line 503 call add(lines, '|1,"x') " missing quote 504 call add(lines, '|1,"x\') " trailing backslash 505 call add(lines, '|1,,,,') "trailing comma 506 call add(lines, '|1,>234') " trailing continuation line 507 call writefile(lines, 'Xviminfo') 508 rviminfo Xviminfo 509 510 call delete('Xviminfo') 511endfunc 512 513func Test_viminfo_file_marks() 514 silent! bwipe test_viminfo.vim 515 silent! bwipe Xviminfo 516 517 call test_settime(10) 518 edit ten 519 call test_settime(25) 520 edit again 521 call test_settime(30) 522 edit thirty 523 wviminfo Xviminfo 524 525 call test_settime(20) 526 edit twenty 527 call test_settime(35) 528 edit again 529 call test_settime(40) 530 edit fourty 531 wviminfo Xviminfo 532 533 sp Xviminfo 534 1 535 for name in ['fourty', 'again', 'thirty', 'twenty', 'ten'] 536 /^> 537 call assert_equal(name, substitute(getline('.'), '.*/', '', '')) 538 endfor 539 close 540 541 call delete('Xviminfo') 542endfunc 543 544func Test_viminfo_file_mark_tabclose() 545 tabnew Xtestfileintab 546 call setline(1, ['a','b','c','d','e']) 547 4 548 q! 549 wviminfo Xviminfo 550 sp Xviminfo 551 /^> .*Xtestfileintab 552 let lnum = line('.') 553 while 1 554 if lnum == line('$') 555 call assert_report('mark not found in Xtestfileintab') 556 break 557 endif 558 let lnum += 1 559 let line = getline(lnum) 560 if line == '' 561 call assert_report('mark not found in Xtestfileintab') 562 break 563 endif 564 if line =~ "^\t\"" 565 call assert_equal('4', substitute(line, ".*\"\t\\(\\d\\).*", '\1', '')) 566 break 567 endif 568 endwhile 569 570 call delete('Xviminfo') 571 silent! bwipe Xtestfileintab 572endfunc 573 574func Test_viminfo_file_mark_zero_time() 575 let lines = [ 576 \ '# Viminfo version', 577 \ '|1,4', 578 \ '', 579 \ '*encoding=utf-8', 580 \ '', 581 \ '# File marks:', 582 \ "'B 1 0 /tmp/nothing", 583 \ '|4,66,1,0,0,"/tmp/nothing"', 584 \ "", 585 \ ] 586 call writefile(lines, 'Xviminfo') 587 delmark B 588 rviminfo Xviminfo 589 call delete('Xviminfo') 590 call assert_equal(1, line("'B")) 591 delmark B 592endfunc 593 594" Test for saving and restoring file marks in unloaded buffers 595func Test_viminfo_file_mark_unloaded_buf() 596 let save_viminfo = &viminfo 597 set viminfo&vim 598 call writefile(repeat(['vim'], 10), 'Xfile1') 599 %bwipe 600 edit! Xfile1 601 call setpos("'u", [0, 3, 1, 0]) 602 call setpos("'v", [0, 5, 1, 0]) 603 enew 604 wviminfo Xviminfo 605 %bwipe 606 edit Xfile1 607 rviminfo! Xviminfo 608 call assert_equal([0, 3, 1, 0], getpos("'u")) 609 call assert_equal([0, 5, 1, 0], getpos("'v")) 610 %bwipe 611 call delete('Xfile1') 612 call delete('Xviminfo') 613 let &viminfo = save_viminfo 614endfunc 615 616func Test_viminfo_oldfiles() 617 let v:oldfiles = [] 618 let lines = [ 619 \ '# comment line', 620 \ '*encoding=utf-8', 621 \ '', 622 \ ':h viminfo', 623 \ '?/session', 624 \ '=myvar', 625 \ '@123', 626 \ '', 627 \ "'E 2 0 /tmp/nothing", 628 \ '', 629 \ "> /tmp/file_one.txt", 630 \ "\t\"\t11\t0", 631 \ "", 632 \ "> /tmp/file_two.txt", 633 \ "\t\"\t11\t0", 634 \ "", 635 \ "> /tmp/another.txt", 636 \ "\t\"\t11\t0", 637 \ "", 638 \ ] 639 call writefile(lines, 'Xviminfo') 640 delmark E 641 edit /tmp/file_two.txt 642 rviminfo! Xviminfo 643 call delete('Xviminfo') 644 645 call assert_equal('h viminfo', histget(':')) 646 call assert_equal('session', histget('/')) 647 call assert_equal('myvar', histget('=')) 648 call assert_equal('123', histget('@')) 649 call assert_equal(2, line("'E")) 650 call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt', '3: /tmp/another.txt'], filter(split(execute('oldfiles'), "\n"), {i, v -> v =~ '/tmp/'})) 651 call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('filter file_ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'})) 652 call assert_equal(['3: /tmp/another.txt'], filter(split(execute('filter /another/ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'})) 653 654 new 655 call feedkeys("3\<CR>", 't') 656 browse oldfiles 657 call assert_equal("/tmp/another.txt", expand("%")) 658 bwipe 659 delmark E 660endfunc 661 662" Test for storing and restoring buffer list in 'viminfo' 663func Test_viminfo_bufferlist() 664 " If there are arguments, then :rviminfo doesn't read the buffer list. 665 " Need to delete all the arguments for :rviminfo to work. 666 %argdelete 667 668 edit Xfile1 669 edit Xfile2 670 set viminfo-=% 671 wviminfo Xviminfo 672 %bwipe 673 rviminfo Xviminfo 674 call assert_equal(1, len(getbufinfo())) 675 676 edit Xfile1 677 edit Xfile2 678 set viminfo^=% 679 wviminfo Xviminfo 680 %bwipe 681 rviminfo Xviminfo 682 let l = getbufinfo() 683 call assert_equal(3, len(l)) 684 call assert_equal('Xfile1', bufname(l[1].bufnr)) 685 call assert_equal('Xfile2', bufname(l[2].bufnr)) 686 687 call delete('Xviminfo') 688 %bwipe 689 set viminfo-=% 690endfunc 691 692" Test for errors in a viminfo file 693func Test_viminfo_error() 694 " Non-existing viminfo files 695 call assert_fails('rviminfo xyz', 'E195:') 696 697 " Illegal starting character 698 call writefile(["a 123"], 'Xviminfo') 699 call assert_fails('rv Xviminfo', 'E575:') 700 701 " Illegal register name in the viminfo file 702 call writefile(['"@ LINE 0'], 'Xviminfo') 703 call assert_fails('rv Xviminfo', 'E577:') 704 705 " Invalid file mark line 706 call writefile(['>', '@'], 'Xviminfo') 707 call assert_fails('rv Xviminfo', 'E576:') 708 709 " Too many errors in viminfo file 710 call writefile(repeat(["a 123"], 15), 'Xviminfo') 711 call assert_fails('rv Xviminfo', 'E575:') 712 713 call writefile(['>'] + repeat(['@'], 10), 'Xviminfo') 714 call assert_fails('rv Xviminfo', 'E576:') 715 716 call writefile(repeat(['"@'], 15), 'Xviminfo') 717 call assert_fails('rv Xviminfo', 'E577:') 718 719 call delete('Xviminfo') 720endfunc 721 722" Test for saving and restoring last substitute string in viminfo 723func Test_viminfo_lastsub() 724 enew 725 call append(0, "blue blue blue") 726 call cursor(1, 1) 727 s/blue/green/ 728 wviminfo Xviminfo 729 s/blue/yellow/ 730 rviminfo! Xviminfo 731 & 732 call assert_equal("green yellow green", getline(1)) 733 enew! 734 call delete('Xviminfo') 735endfunc 736 737" Test saving and restoring the register values using the older method 738func Test_viminfo_registers_old() 739 let lines = [ 740 \ '# Viminfo version', 741 \ '|1,1', 742 \ '', 743 \ '*encoding=utf-8', 744 \ '', 745 \ '# Registers:', 746 \ '""0 CHAR 0', 747 \ ' Vim', 748 \ '"a CHAR 0', 749 \ ' red', 750 \ '"m@ CHAR 0', 751 \ " :echo 'Hello'\<CR>", 752 \ "", 753 \ ] 754 call writefile(lines, 'Xviminfo') 755 let @a = 'one' 756 let @b = 'two' 757 let @m = 'three' 758 let @" = 'four' 759 let @t = ":echo 'Unix'\<CR>" 760 silent! normal @t 761 rviminfo! Xviminfo 762 call assert_equal('red', getreg('a')) 763 call assert_equal('two', getreg('b')) 764 call assert_equal(":echo 'Hello'\<CR>", getreg('m')) 765 call assert_equal('Vim', getreg('"')) 766 call assert_equal("\nHello", execute('normal @@')) 767 call delete('Xviminfo') 768 let @" = '' 769endfunc 770 771" Test for saving and restoring large number of lines in a register 772func Test_viminfo_large_register() 773 let save_viminfo = &viminfo 774 set viminfo&vim 775 set viminfo-=<50 776 set viminfo+=<200 777 let lines = ['"r CHAR 0'] 778 call extend(lines, repeat(["\tsun is rising"], 200)) 779 call writefile(lines, 'Xviminfo') 780 let @r = '' 781 rviminfo! Xviminfo 782 call assert_equal(join(repeat(["sun is rising"], 200), "\n"), @r) 783 call delete('Xviminfo') 784 let @r = '' 785 let &viminfo = save_viminfo 786endfunc 787 788" Test for setting 'viminfofile' to NONE 789func Test_viminfofile_none() 790 let save_vif = &viminfofile 791 set viminfofile=NONE 792 wviminfo Xviminfo 793 call assert_false(filereadable('Xviminfo')) 794 call writefile([''], 'Xviminfo') 795 call assert_fails('rviminfo Xviminfo', 'E195:') 796 call delete('Xviminfo') 797 let &viminfofile = save_vif 798endfunc 799 800" Test for an unwritable and unreadble 'viminfo' file 801func Test_viminfo_perm() 802 CheckUnix 803 CheckNotRoot 804 call writefile([''], 'Xviminfo') 805 call setfperm('Xviminfo', 'r-x------') 806 call assert_fails('wviminfo Xviminfo', 'E137:') 807 call setfperm('Xviminfo', '--x------') 808 call assert_fails('rviminfo Xviminfo', 'E195:') 809 call delete('Xviminfo') 810 811 " Try to write the viminfo to a directory 812 call mkdir('Xdir') 813 call assert_fails('wviminfo Xdir', 'E137:') 814 call delete('Xdir', 'rf') 815endfunc 816 817" Test for writing to an existing viminfo file merges the file marks 818func XTest_viminfo_marks_merge() 819 let save_viminfo = &viminfo 820 set viminfo&vim 821 set viminfo^=% 822 enew 823 %argdelete 824 %bwipe 825 826 call writefile(repeat(['editor'], 10), 'Xbufa') 827 call writefile(repeat(['Vim'], 10), 'Xbufb') 828 829 " set marks in buffers 830 call test_settime(10) 831 edit Xbufa 832 4mark a 833 wviminfo Xviminfo 834 edit Xbufb 835 4mark b 836 wviminfo Xviminfo 837 %bwipe 838 839 " set marks in buffers again 840 call test_settime(20) 841 edit Xbufb 842 6mark b 843 wviminfo Xviminfo 844 edit Xbufa 845 6mark a 846 wviminfo Xviminfo 847 %bwipe 848 849 " Load the buffer and check the marks 850 edit Xbufa 851 rviminfo! Xviminfo 852 call assert_equal(6, line("'a")) 853 edit Xbufb 854 rviminfo! Xviminfo 855 call assert_equal(6, line("'b")) 856 857 " cleanup 858 %bwipe 859 call delete('Xviminfo') 860 call delete('Xbufa') 861 call delete('Xbufb') 862 call test_settime(0) 863 let &viminfo=save_viminfo 864endfunc 865 866" Test for errors in setting 'viminfo' 867func Test_viminfo_option_error() 868 " Missing number 869 call assert_fails('set viminfo=\"', 'E526:') 870 for c in split("'/:<@s", '\zs') 871 call assert_fails('set viminfo=' .. c, 'E526:') 872 endfor 873 874 " Missing comma 875 call assert_fails('set viminfo=%10!', 'E527:') 876 call assert_fails('set viminfo=!%10', 'E527:') 877 call assert_fails('set viminfo=h%10', 'E527:') 878 call assert_fails('set viminfo=c%10', 'E527:') 879 call assert_fails('set viminfo=:10%10', 'E527:') 880 881 " Missing ' setting 882 call assert_fails('set viminfo=%10', 'E528:') 883endfunc 884 885func Test_viminfo_oldfiles_newfile() 886 CheckRunVimInTerminal 887 888 let save_viminfo = &viminfo 889 let save_viminfofile = &viminfofile 890 set viminfo&vim 891 let v:oldfiles = [] 892 let commands =<< trim [CODE] 893 set viminfofile=Xviminfofile 894 set viminfo&vim 895 w! Xnew-file.txt 896 qall 897 [CODE] 898 call writefile(commands, 'Xviminfotest') 899 let buf = RunVimInTerminal('-S Xviminfotest', #{wait_for_ruler: 0}) 900 call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))}) 901 902 let &viminfofile = 'Xviminfofile' 903 rviminfo! Xviminfofile 904 call assert_match('Xnew-file.txt$', v:oldfiles[0]) 905 call assert_equal(1, len(v:oldfiles)) 906 call delete('Xviminfofile') 907 call delete('Xviminfotest') 908 call delete('Xnew-file.txt') 909 let &viminfo = save_viminfo 910 let &viminfofile = save_viminfofile 911endfunc 912 913" vim: shiftwidth=2 sts=2 expandtab 914