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