Mercurial > vim
comparison src/testdir/test_autocmd.vim @ 12662:15f0f9f16cd9 v8.0.1209
patch 8.0.1209: still too many old style tests
commit https://github.com/vim/vim/commit/53f0c962394dc6bc66d5b0762af9434e672d1b25
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 22 14:23:59 2017 +0200
patch 8.0.1209: still too many old style tests
Problem: Still too many old style tests.
Solution: Convert a few more tests to new style. (Yegappan Lakshmanan,
closes #2230)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 22 Oct 2017 14:30:07 +0200 |
parents | 0a9dacb8826a |
children | 429bf1b9292f |
comparison
equal
deleted
inserted
replaced
12661:9ee086df7d78 | 12662:15f0f9f16cd9 |
---|---|
771 let g:bufinfo = getbufinfo() | 771 let g:bufinfo = getbufinfo() |
772 call assert_equal(1, len(g:bufinfo)) | 772 call assert_equal(1, len(g:bufinfo)) |
773 | 773 |
774 call delete('Xxx1') | 774 call delete('Xxx1') |
775 call delete('Xxx2') | 775 call delete('Xxx2') |
776 call delete('test.out') | |
776 %bwipe | 777 %bwipe |
777 au! BufLeave | 778 au! BufLeave |
778 | 779 |
779 " check that bufinfo doesn't contain a pointer to freed memory | 780 " check that bufinfo doesn't contain a pointer to freed memory |
780 call test_garbagecollect_now() | 781 call test_garbagecollect_now() |
807 | 808 |
808 au! CmdlineEnter / let g:entered = expand('<afile>') | 809 au! CmdlineEnter / let g:entered = expand('<afile>') |
809 au! CmdlineLeave / let g:left = expand('<afile>') | 810 au! CmdlineLeave / let g:left = expand('<afile>') |
810 let g:entered = 0 | 811 let g:entered = 0 |
811 let g:left = 0 | 812 let g:left = 0 |
812 call feedkeys("/hello<CR>", 'xt') | 813 new |
814 call setline(1, 'hello') | |
815 call feedkeys("/hello\<CR>", 'xt') | |
813 call assert_equal('/', g:entered) | 816 call assert_equal('/', g:entered) |
814 call assert_equal('/', g:left) | 817 call assert_equal('/', g:left) |
818 bwipe! | |
815 au! CmdlineEnter | 819 au! CmdlineEnter |
816 au! CmdlineLeave | 820 au! CmdlineLeave |
817 endfunc | 821 endfunc |
822 | |
823 " Test for BufWritePre autocommand that deletes or unloads the buffer. | |
824 func Test_BufWritePre() | |
825 %bwipe | |
826 au BufWritePre Xxx1 bunload | |
827 au BufWritePre Xxx2 bwipe | |
828 | |
829 call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1') | |
830 call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2') | |
831 | |
832 edit Xtest | |
833 e! Xxx2 | |
834 bdel Xtest | |
835 e Xxx1 | |
836 " write it, will unload it and give an error msg | |
837 call assert_fails('w', 'E203') | |
838 call assert_equal('Xxx2', bufname('%')) | |
839 edit Xtest | |
840 e! Xxx2 | |
841 bwipe Xtest | |
842 " write it, will delete the buffer and give an error msg | |
843 call assert_fails('w', 'E203') | |
844 call assert_equal('Xxx1', bufname('%')) | |
845 au! BufWritePre | |
846 call delete('Xxx1') | |
847 call delete('Xxx2') | |
848 endfunc | |
849 | |
850 " Test for BufUnload autocommand that unloads all the other buffers | |
851 func Test_bufunload_all() | |
852 call writefile(['Test file Xxx1'], 'Xxx1')" | |
853 call writefile(['Test file Xxx2'], 'Xxx2')" | |
854 | |
855 let content = [ | |
856 \ "func UnloadAllBufs()", | |
857 \ " let i = 1", | |
858 \ " while i <= bufnr('$')", | |
859 \ " if i != bufnr('%') && bufloaded(i)", | |
860 \ " exe i . 'bunload'", | |
861 \ " endif", | |
862 \ " let i += 1", | |
863 \ " endwhile", | |
864 \ "endfunc", | |
865 \ "au BufUnload * call UnloadAllBufs()", | |
866 \ "au VimLeave * call writefile(['Test Finished'], 'Xout')", | |
867 \ "edit Xxx1", | |
868 \ "split Xxx2", | |
869 \ "q"] | |
870 call writefile(content, 'Xtest') | |
871 | |
872 call delete('Xout') | |
873 call system(v:progpath. ' --clean -N --not-a-term -S Xtest') | |
874 call assert_true(filereadable('Xout')) | |
875 | |
876 call delete('Xxx1') | |
877 call delete('Xxx2') | |
878 call delete('Xtest') | |
879 call delete('Xout') | |
880 endfunc | |
881 | |
882 " Some tests for buffer-local autocommands | |
883 func Test_buflocal_autocmd() | |
884 let g:bname = '' | |
885 edit xx | |
886 au BufLeave <buffer> let g:bname = expand("%") | |
887 " here, autocommand for xx should trigger. | |
888 " but autocommand shall not apply to buffer named <buffer>. | |
889 edit somefile | |
890 call assert_equal('xx', g:bname) | |
891 let g:bname = '' | |
892 " here, autocommand shall be auto-deleted | |
893 bwipe xx | |
894 " autocmd should not trigger | |
895 edit xx | |
896 call assert_equal('', g:bname) | |
897 " autocmd should not trigger | |
898 edit somefile | |
899 call assert_equal('', g:bname) | |
900 enew | |
901 unlet g:bname | |
902 endfunc |