Mercurial > vim
comparison src/testdir/test_autocmd.vim @ 11707:1395a3b6978d v8.0.0736
patch 8.0.0736: OptionSet not triggered when entering diff mode
commit https://github.com/vim/vim/commit/04f62f881c5743d2fdaf7324f6a715381f0d5fcf
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 19 18:18:39 2017 +0200
patch 8.0.0736: OptionSet not triggered when entering diff mode
Problem: The OptionSet autocommand event is not triggered when entering
diff mode.
Solution: use set_option_value() instead of setting the option directly.
Change the tests from old to new style. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 19 Jul 2017 18:30:03 +0200 |
parents | dbce7e03bf55 |
children | 0240e7e3d736 |
comparison
equal
deleted
inserted
replaced
11706:f4e65317cf67 | 11707:1395a3b6978d |
---|---|
1 " Tests for autocommands | 1 " Tests for autocommands |
2 | 2 |
3 set belloff=all | 3 set belloff=all |
4 | 4 |
5 function! s:cleanup_buffers() abort | 5 func! s:cleanup_buffers() abort |
6 for bnr in range(1, bufnr('$')) | 6 for bnr in range(1, bufnr('$')) |
7 if bufloaded(bnr) && bufnr('%') != bnr | 7 if bufloaded(bnr) && bufnr('%') != bnr |
8 execute 'bd! ' . bnr | 8 execute 'bd! ' . bnr |
9 endif | 9 endif |
10 endfor | 10 endfor |
11 endfunction | 11 endfunc |
12 | 12 |
13 func Test_vim_did_enter() | 13 func Test_vim_did_enter() |
14 call assert_false(v:vim_did_enter) | 14 call assert_false(v:vim_did_enter) |
15 | 15 |
16 " This script will never reach the main loop, can't check if v:vim_did_enter | 16 " This script will never reach the main loop, can't check if v:vim_did_enter |
47 au! CursorHoldI | 47 au! CursorHoldI |
48 set updatetime& | 48 set updatetime& |
49 endfunc | 49 endfunc |
50 endif | 50 endif |
51 | 51 |
52 function Test_bufunload() | 52 func Test_bufunload() |
53 augroup test_bufunload_group | 53 augroup test_bufunload_group |
54 autocmd! | 54 autocmd! |
55 autocmd BufUnload * call add(s:li, "bufunload") | 55 autocmd BufUnload * call add(s:li, "bufunload") |
56 autocmd BufDelete * call add(s:li, "bufdelete") | 56 autocmd BufDelete * call add(s:li, "bufdelete") |
57 autocmd BufWipeout * call add(s:li, "bufwipeout") | 57 autocmd BufWipeout * call add(s:li, "bufwipeout") |
78 au! test_bufunload_group | 78 au! test_bufunload_group |
79 augroup! test_bufunload_group | 79 augroup! test_bufunload_group |
80 endfunc | 80 endfunc |
81 | 81 |
82 " SEGV occurs in older versions. (At least 7.4.2005 or older) | 82 " SEGV occurs in older versions. (At least 7.4.2005 or older) |
83 function Test_autocmd_bufunload_with_tabnext() | 83 func Test_autocmd_bufunload_with_tabnext() |
84 tabedit | 84 tabedit |
85 tabfirst | 85 tabfirst |
86 | 86 |
87 augroup test_autocmd_bufunload_with_tabnext_group | 87 augroup test_autocmd_bufunload_with_tabnext_group |
88 autocmd! | 88 autocmd! |
96 augroup! test_autocmd_bufunload_with_tabnext_group | 96 augroup! test_autocmd_bufunload_with_tabnext_group |
97 tablast | 97 tablast |
98 quit | 98 quit |
99 endfunc | 99 endfunc |
100 | 100 |
101 function Test_autocmd_bufwinleave_with_tabfirst() | 101 func Test_autocmd_bufwinleave_with_tabfirst() |
102 tabedit | 102 tabedit |
103 augroup sample | 103 augroup sample |
104 autocmd! | 104 autocmd! |
105 autocmd BufWinLeave <buffer> tabfirst | 105 autocmd BufWinLeave <buffer> tabfirst |
106 augroup END | 106 augroup END |
108 edit! a.txt | 108 edit! a.txt |
109 tabclose | 109 tabclose |
110 endfunc | 110 endfunc |
111 | 111 |
112 " SEGV occurs in older versions. (At least 7.4.2321 or older) | 112 " SEGV occurs in older versions. (At least 7.4.2321 or older) |
113 function Test_autocmd_bufunload_avoiding_SEGV_01() | 113 func Test_autocmd_bufunload_avoiding_SEGV_01() |
114 split aa.txt | 114 split aa.txt |
115 let lastbuf = bufnr('$') | 115 let lastbuf = bufnr('$') |
116 | 116 |
117 augroup test_autocmd_bufunload | 117 augroup test_autocmd_bufunload |
118 autocmd! | 118 autocmd! |
126 bwipe! aa.txt | 126 bwipe! aa.txt |
127 bwipe! bb.txt | 127 bwipe! bb.txt |
128 endfunc | 128 endfunc |
129 | 129 |
130 " SEGV occurs in older versions. (At least 7.4.2321 or older) | 130 " SEGV occurs in older versions. (At least 7.4.2321 or older) |
131 function Test_autocmd_bufunload_avoiding_SEGV_02() | 131 func Test_autocmd_bufunload_avoiding_SEGV_02() |
132 setlocal buftype=nowrite | 132 setlocal buftype=nowrite |
133 let lastbuf = bufnr('$') | 133 let lastbuf = bufnr('$') |
134 | 134 |
135 augroup test_autocmd_bufunload | 135 augroup test_autocmd_bufunload |
136 autocmd! | 136 autocmd! |
349 au! BufEnter | 349 au! BufEnter |
350 endfunc | 350 endfunc |
351 | 351 |
352 " Closing a window might cause an endless loop | 352 " Closing a window might cause an endless loop |
353 " E814 for older Vims | 353 " E814 for older Vims |
354 function Test_autocmd_bufwipe_in_SessLoadPost() | 354 func Test_autocmd_bufwipe_in_SessLoadPost() |
355 tabnew | 355 tabnew |
356 set noswapfile | 356 set noswapfile |
357 mksession! | 357 mksession! |
358 | 358 |
359 let content = ['set nocp noswapfile', | 359 let content = ['set nocp noswapfile', |
378 call delete(file) | 378 call delete(file) |
379 endfor | 379 endfor |
380 endfunc | 380 endfunc |
381 | 381 |
382 " SEGV occurs in older versions. | 382 " SEGV occurs in older versions. |
383 function Test_autocmd_bufwipe_in_SessLoadPost2() | 383 func Test_autocmd_bufwipe_in_SessLoadPost2() |
384 tabnew | 384 tabnew |
385 set noswapfile | 385 set noswapfile |
386 mksession! | 386 mksession! |
387 | 387 |
388 let content = ['set nocp noswapfile', | 388 let content = ['set nocp noswapfile', |
420 endfunc | 420 endfunc |
421 | 421 |
422 func Test_empty_doau() | 422 func Test_empty_doau() |
423 doau \| | 423 doau \| |
424 endfunc | 424 endfunc |
425 | |
426 func s:AutoCommandOptionSet(match) | |
427 let item = remove(g:options, 0) | |
428 let expected = printf("Option: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", item[0], item[1], item[2], item[3]) | |
429 let actual = printf("Option: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", a:match, v:option_old, v:option_new, v:option_type) | |
430 let g:opt = [expected, actual] | |
431 "call assert_equal(expected, actual) | |
432 endfunc | |
433 | |
434 func Test_OptionSet() | |
435 if !has("eval") || !has("autocmd") || !exists("+autochdir") | |
436 return | |
437 endif | |
438 | |
439 call test_override('starting', 1) | |
440 set nocp | |
441 au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>")) | |
442 | |
443 " 1: Setting number option" | |
444 let g:options=[['number', 0, 1, 'global']] | |
445 set nu | |
446 call assert_equal([], g:options) | |
447 call assert_equal(g:opt[0], g:opt[1]) | |
448 | |
449 " 2: Setting local number option" | |
450 let g:options=[['number', 1, 0, 'local']] | |
451 setlocal nonu | |
452 call assert_equal([], g:options) | |
453 call assert_equal(g:opt[0], g:opt[1]) | |
454 | |
455 " 3: Setting global number option" | |
456 let g:options=[['number', 1, 0, 'global']] | |
457 setglobal nonu | |
458 call assert_equal([], g:options) | |
459 call assert_equal(g:opt[0], g:opt[1]) | |
460 | |
461 " 4: Setting local autoindent option" | |
462 let g:options=[['autoindent', 0, 1, 'local']] | |
463 setlocal ai | |
464 call assert_equal([], g:options) | |
465 call assert_equal(g:opt[0], g:opt[1]) | |
466 | |
467 " 5: Setting global autoindent option" | |
468 let g:options=[['autoindent', 0, 1, 'global']] | |
469 setglobal ai | |
470 call assert_equal([], g:options) | |
471 call assert_equal(g:opt[0], g:opt[1]) | |
472 | |
473 " 6: Setting global autoindent option" | |
474 let g:options=[['autoindent', 1, 0, 'global']] | |
475 set ai! | |
476 call assert_equal([], g:options) | |
477 call assert_equal(g:opt[0], g:opt[1]) | |
478 | |
479 " Should not print anything, use :noa | |
480 " 7: don't trigger OptionSet" | |
481 let g:options=[['invalid', 1, 1, 'invalid']] | |
482 noa set nonu | |
483 call assert_equal([['invalid', 1, 1, 'invalid']], g:options) | |
484 call assert_equal(g:opt[0], g:opt[1]) | |
485 | |
486 " 8: Setting several global list and number option" | |
487 let g:options=[['list', 0, 1, 'global'], ['number', 0, 1, 'global']] | |
488 set list nu | |
489 call assert_equal([], g:options) | |
490 call assert_equal(g:opt[0], g:opt[1]) | |
491 | |
492 " 9: don't trigger OptionSet" | |
493 let g:options=[['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']] | |
494 noa set nolist nonu | |
495 call assert_equal([['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']], g:options) | |
496 call assert_equal(g:opt[0], g:opt[1]) | |
497 | |
498 " 10: Setting global acd" | |
499 let g:options=[['autochdir', 0, 1, 'local']] | |
500 setlocal acd | |
501 call assert_equal([], g:options) | |
502 call assert_equal(g:opt[0], g:opt[1]) | |
503 | |
504 " 11: Setting global autoread (also sets local value)" | |
505 let g:options=[['autoread', 0, 1, 'global']] | |
506 set ar | |
507 call assert_equal([], g:options) | |
508 call assert_equal(g:opt[0], g:opt[1]) | |
509 | |
510 " 12: Setting local autoread" | |
511 let g:options=[['autoread', 1, 1, 'local']] | |
512 setlocal ar | |
513 call assert_equal([], g:options) | |
514 call assert_equal(g:opt[0], g:opt[1]) | |
515 | |
516 " 13: Setting global autoread" | |
517 let g:options=[['autoread', 1, 0, 'global']] | |
518 setglobal invar | |
519 call assert_equal([], g:options) | |
520 call assert_equal(g:opt[0], g:opt[1]) | |
521 | |
522 " 14: Setting option backspace through :let" | |
523 let g:options=[['backspace', '', 'eol,indent,start', 'global']] | |
524 let &bs="eol,indent,start" | |
525 call assert_equal([], g:options) | |
526 call assert_equal(g:opt[0], g:opt[1]) | |
527 | |
528 " 15: Setting option backspace through setbufvar()" | |
529 let g:options=[['backup', 0, 1, 'local']] | |
530 " try twice, first time, shouldn't trigger because option name is invalid, | |
531 " second time, it should trigger | |
532 call assert_fails("call setbufvar(1, '&l:bk', 1)", "E355") | |
533 " should trigger, use correct option name | |
534 call setbufvar(1, '&backup', 1) | |
535 call assert_equal([], g:options) | |
536 call assert_equal(g:opt[0], g:opt[1]) | |
537 | |
538 " 16: Setting number option using setwinvar" | |
539 let g:options=[['number', 0, 1, 'local']] | |
540 call setwinvar(0, '&number', 1) | |
541 call assert_equal([], g:options) | |
542 call assert_equal(g:opt[0], g:opt[1]) | |
543 | |
544 " 17: Setting key option, shouldn't trigger" | |
545 let g:options=[['key', 'invalid', 'invalid1', 'invalid']] | |
546 setlocal key=blah | |
547 setlocal key= | |
548 call assert_equal([['key', 'invalid', 'invalid1', 'invalid']], g:options) | |
549 call assert_equal(g:opt[0], g:opt[1]) | |
550 | |
551 " Cleanup | |
552 au! OptionSet | |
553 for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp'] | |
554 exe printf(":set %s&vi", opt) | |
555 endfor | |
556 call test_override('starting', 0) | |
557 delfunc! AutoCommandOptionSet | |
558 endfunc | |
559 | |
560 func Test_OptionSet_diffmode() | |
561 call test_override('starting', 1) | |
562 " 18: Changing an option when enetering diff mode | |
563 new | |
564 au OptionSet diff :let &l:cul=v:option_new | |
565 | |
566 call setline(1, ['buffer 1', 'line2', 'line3', 'line4']) | |
567 call assert_equal(0, &l:cul) | |
568 diffthis | |
569 call assert_equal(1, &l:cul) | |
570 | |
571 vnew | |
572 call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4']) | |
573 call assert_equal(0, &l:cul) | |
574 diffthis | |
575 call assert_equal(1, &l:cul) | |
576 | |
577 diffoff | |
578 call assert_equal(0, &l:cul) | |
579 call assert_equal(1, getwinvar(2, '&l:cul')) | |
580 bw! | |
581 | |
582 call assert_equal(1, &l:cul) | |
583 diffoff! | |
584 call assert_equal(0, &l:cul) | |
585 call assert_equal(0, getwinvar(1, '&l:cul')) | |
586 bw! | |
587 | |
588 " Cleanup | |
589 au! OptionSet | |
590 call test_override('starting', 0) | |
591 endfunc | |
592 | |
593 func Test_OptionSet_diffmode_close() | |
594 call test_override('starting', 1) | |
595 " 19: Try to close the current window when entering diff mode | |
596 " should not segfault | |
597 new | |
598 au OptionSet diff close | |
599 | |
600 call setline(1, ['buffer 1', 'line2', 'line3', 'line4']) | |
601 call assert_fails(':diffthis', 'E788') | |
602 call assert_equal(1, &diff) | |
603 vnew | |
604 call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4']) | |
605 call assert_fails(':diffthis', 'E788') | |
606 call assert_equal(1, &diff) | |
607 bw! | |
608 call assert_fails(':diffoff!', 'E788') | |
609 bw! | |
610 | |
611 " Cleanup | |
612 au! OptionSet | |
613 call test_override('starting', 0) | |
614 "delfunc! AutoCommandOptionSet | |
615 endfunc |