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