Mercurial > vim
comparison src/testdir/test_autocmd.vim @ 12616:4767939d10cc v8.0.1186
patch 8.0.1186: still quite a few old style tests
commit https://github.com/vim/vim/commit/4a6fcf8047de13c7949ab2f27f7774acaec4ae4d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 12 21:29:22 2017 +0200
patch 8.0.1186: still quite a few old style tests
Problem: Still quite a few old style tests.
Solution: Convert old to new style tests. (Yegappan Lakshmanan)
Avoid ringing the bell while running tests.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 12 Oct 2017 21:30:07 +0200 |
parents | d2e367d9de1f |
children | 27a2fc398671 |
comparison
equal
deleted
inserted
replaced
12615:962b8ecbd793 | 12616:4767939d10cc |
---|---|
434 func Test_OptionSet() | 434 func Test_OptionSet() |
435 if !has("eval") || !has("autocmd") || !exists("+autochdir") | 435 if !has("eval") || !has("autocmd") || !exists("+autochdir") |
436 return | 436 return |
437 endif | 437 endif |
438 | 438 |
439 badd test_autocmd.vim | |
440 | |
439 call test_override('starting', 1) | 441 call test_override('starting', 1) |
440 set nocp | 442 set nocp |
441 au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>")) | 443 au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>")) |
442 | 444 |
443 " 1: Setting number option" | 445 " 1: Setting number option" |
527 | 529 |
528 " 15: Setting option backspace through setbufvar()" | 530 " 15: Setting option backspace through setbufvar()" |
529 let g:options=[['backup', 0, 1, 'local']] | 531 let g:options=[['backup', 0, 1, 'local']] |
530 " try twice, first time, shouldn't trigger because option name is invalid, | 532 " try twice, first time, shouldn't trigger because option name is invalid, |
531 " second time, it should trigger | 533 " second time, it should trigger |
532 call assert_fails("call setbufvar(1, '&l:bk', 1)", "E355") | 534 let bnum = bufnr('%') |
535 call assert_fails("call setbufvar(bnum, '&l:bk', 1)", "E355") | |
533 " should trigger, use correct option name | 536 " should trigger, use correct option name |
534 call setbufvar(1, '&backup', 1) | 537 call setbufvar(bnum, '&backup', 1) |
535 call assert_equal([], g:options) | 538 call assert_equal([], g:options) |
536 call assert_equal(g:opt[0], g:opt[1]) | 539 call assert_equal(g:opt[0], g:opt[1]) |
537 | 540 |
538 " 16: Setting number option using setwinvar" | 541 " 16: Setting number option using setwinvar" |
539 let g:options=[['number', 0, 1, 'local']] | 542 let g:options=[['number', 0, 1, 'local']] |
643 augroup! test_bufleavewithdelete | 646 augroup! test_bufleavewithdelete |
644 | 647 |
645 new | 648 new |
646 bwipe! Xfile1 | 649 bwipe! Xfile1 |
647 endfunc | 650 endfunc |
651 | |
652 " Test for autocommand that changes the buffer list, when doing ":ball". | |
653 func Test_Acmd_BufAll() | |
654 enew! | |
655 %bwipe! | |
656 call writefile(['Test file Xxx1'], 'Xxx1') | |
657 call writefile(['Test file Xxx2'], 'Xxx2') | |
658 call writefile(['Test file Xxx3'], 'Xxx3') | |
659 | |
660 " Add three files to the buffer list | |
661 split Xxx1 | |
662 close | |
663 split Xxx2 | |
664 close | |
665 split Xxx3 | |
666 close | |
667 | |
668 " Wipe the buffer when the buffer is opened | |
669 au BufReadPost Xxx2 bwipe | |
670 | |
671 call append(0, 'Test file Xxx4') | |
672 ball | |
673 | |
674 call assert_equal(2, winnr('$')) | |
675 call assert_equal('Xxx1', bufname(winbufnr(winnr('$')))) | |
676 wincmd t | |
677 | |
678 au! BufReadPost | |
679 %bwipe! | |
680 call delete('Xxx1') | |
681 call delete('Xxx2') | |
682 call delete('Xxx3') | |
683 enew! | only | |
684 endfunc | |
685 | |
686 " Test for autocommand that changes current buffer on BufEnter event. | |
687 " Check if modelines are interpreted for the correct buffer. | |
688 func Test_Acmd_BufEnter() | |
689 %bwipe! | |
690 call writefile(['start of test file Xxx1', | |
691 \ "\<Tab>this is a test", | |
692 \ 'end of test file Xxx1'], 'Xxx1') | |
693 call writefile(['start of test file Xxx2', | |
694 \ 'vim: set noai :', | |
695 \ "\<Tab>this is a test", | |
696 \ 'end of test file Xxx2'], 'Xxx2') | |
697 | |
698 au BufEnter Xxx2 brew | |
699 set ai modeline modelines=3 | |
700 edit Xxx1 | |
701 " edit Xxx2, autocmd will do :brew | |
702 edit Xxx2 | |
703 exe "normal G?this is a\<CR>" | |
704 " Append text with autoindent to this file | |
705 normal othis should be auto-indented | |
706 call assert_equal("\<Tab>this should be auto-indented", getline('.')) | |
707 call assert_equal(3, line('.')) | |
708 " Remove autocmd and edit Xxx2 again | |
709 au! BufEnter Xxx2 | |
710 buf! Xxx2 | |
711 exe "normal G?this is a\<CR>" | |
712 " append text without autoindent to Xxx | |
713 normal othis should be in column 1 | |
714 call assert_equal("this should be in column 1", getline('.')) | |
715 call assert_equal(4, line('.')) | |
716 | |
717 %bwipe! | |
718 call delete('Xxx1') | |
719 call delete('Xxx2') | |
720 set ai&vim modeline&vim modelines&vim | |
721 endfunc | |
722 | |
723 " Test for issue #57 | |
724 " do not move cursor on <c-o> when autoindent is set | |
725 func Test_ai_CTRL_O() | |
726 enew! | |
727 set ai | |
728 let save_fo = &fo | |
729 set fo+=r | |
730 exe "normal o# abcdef\<Esc>2hi\<CR>\<C-O>d0\<Esc>" | |
731 exe "normal o# abcdef\<Esc>2hi\<C-O>d0\<Esc>" | |
732 call assert_equal(['# abc', 'def', 'def'], getline(2, 4)) | |
733 | |
734 set ai&vim | |
735 let &fo = save_fo | |
736 enew! | |
737 endfunc | |
738 | |
739 " Test for autocommand that deletes the current buffer on BufLeave event. | |
740 " Also test deleting the last buffer, should give a new, empty buffer. | |
741 func Test_BufLeave_Wipe() | |
742 %bwipe! | |
743 let content = ['start of test file Xxx', | |
744 \ 'this is a test', | |
745 \ 'end of test file Xxx'] | |
746 call writefile(content, 'Xxx1') | |
747 call writefile(content, 'Xxx2') | |
748 | |
749 au BufLeave Xxx2 bwipe | |
750 edit Xxx1 | |
751 split Xxx2 | |
752 " delete buffer Xxx2, we should be back to Xxx1 | |
753 bwipe | |
754 call assert_equal('Xxx1', bufname('%')) | |
755 call assert_equal(1, winnr('$')) | |
756 | |
757 " Create an alternate buffer | |
758 %write! test.out | |
759 call assert_equal('test.out', bufname('#')) | |
760 " delete alternate buffer | |
761 bwipe test.out | |
762 call assert_equal('Xxx1', bufname('%')) | |
763 call assert_equal('', bufname('#')) | |
764 | |
765 au BufLeave Xxx1 bwipe | |
766 " delete current buffer, get an empty one | |
767 bwipe! | |
768 call assert_equal(1, line('$')) | |
769 call assert_equal('', bufname('%')) | |
770 call assert_equal(1, len(getbufinfo())) | |
771 | |
772 call delete('Xxx1') | |
773 call delete('Xxx2') | |
774 %bwipe | |
775 au! BufLeave | |
776 endfunc |