Mercurial > vim
comparison src/testdir/test_autocmd.vim @ 12750:0b6c09957b43 v8.0.1253
patch 8.0.1253: still too many old style tests
commit https://github.com/vim/vim/commit/430dc5d360166ca5bb6a73f2c87ae53e09282ecb
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 2 21:04:47 2017 +0100
patch 8.0.1253: 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 #2272)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 02 Nov 2017 21:15:05 +0100 |
parents | 03a6aeea2096 |
children | afd8a4f36301 |
comparison
equal
deleted
inserted
replaced
12749:8b706a156136 | 12750:0b6c09957b43 |
---|---|
1 " Tests for autocommands | 1 " Tests for autocommands |
2 | |
3 | 2 |
4 func! s:cleanup_buffers() abort | 3 func! s:cleanup_buffers() abort |
5 for bnr in range(1, bufnr('$')) | 4 for bnr in range(1, bufnr('$')) |
6 if bufloaded(bnr) && bufnr('%') != bnr | 5 if bufloaded(bnr) && bufnr('%') != bnr |
7 execute 'bd! ' . bnr | 6 execute 'bd! ' . bnr |
915 edit somefile | 914 edit somefile |
916 call assert_equal('', g:bname) | 915 call assert_equal('', g:bname) |
917 enew | 916 enew |
918 unlet g:bname | 917 unlet g:bname |
919 endfunc | 918 endfunc |
919 | |
920 " Test for "*Cmd" autocommands | |
921 func Test_Cmd_Autocmds() | |
922 call writefile(['start of Xxx', "\tabc2", 'end of Xxx'], 'Xxx') | |
923 | |
924 enew! | |
925 au BufReadCmd XtestA 0r Xxx|$del | |
926 edit XtestA " will read text of Xxd instead | |
927 call assert_equal('start of Xxx', getline(1)) | |
928 | |
929 au BufWriteCmd XtestA call append(line("$"), "write") | |
930 write " will append a line to the file | |
931 call assert_equal('write', getline('$')) | |
932 call assert_fails('read XtestA', 'E484') " should not read anything | |
933 call assert_equal('write', getline(4)) | |
934 | |
935 " now we have: | |
936 " 1 start of Xxx | |
937 " 2 abc2 | |
938 " 3 end of Xxx | |
939 " 4 write | |
940 | |
941 au FileReadCmd XtestB '[r Xxx | |
942 2r XtestB " will read Xxx below line 2 instead | |
943 call assert_equal('start of Xxx', getline(3)) | |
944 | |
945 " now we have: | |
946 " 1 start of Xxx | |
947 " 2 abc2 | |
948 " 3 start of Xxx | |
949 " 4 abc2 | |
950 " 5 end of Xxx | |
951 " 6 end of Xxx | |
952 " 7 write | |
953 | |
954 au FileWriteCmd XtestC '[,']copy $ | |
955 normal 4GA1 | |
956 4,5w XtestC " will copy lines 4 and 5 to the end | |
957 call assert_equal("\tabc21", getline(8)) | |
958 call assert_fails('r XtestC', 'E484') " should not read anything | |
959 call assert_equal("end of Xxx", getline(9)) | |
960 | |
961 " now we have: | |
962 " 1 start of Xxx | |
963 " 2 abc2 | |
964 " 3 start of Xxx | |
965 " 4 abc21 | |
966 " 5 end of Xxx | |
967 " 6 end of Xxx | |
968 " 7 write | |
969 " 8 abc21 | |
970 " 9 end of Xxx | |
971 | |
972 let g:lines = [] | |
973 au FileAppendCmd XtestD call extend(g:lines, getline(line("'["), line("']"))) | |
974 w >>XtestD " will add lines to 'lines' | |
975 call assert_equal(9, len(g:lines)) | |
976 call assert_fails('$r XtestD', 'E484') " should not read anything | |
977 call assert_equal(9, line('$')) | |
978 call assert_equal('end of Xxx', getline('$')) | |
979 | |
980 au BufReadCmd XtestE 0r Xxx|$del | |
981 sp XtestE " split window with test.out | |
982 call assert_equal('end of Xxx', getline(3)) | |
983 | |
984 let g:lines = [] | |
985 exe "normal 2Goasdf\<Esc>\<C-W>\<C-W>" | |
986 au BufWriteCmd XtestE call extend(g:lines, getline(0, '$')) | |
987 wall " will write other window to 'lines' | |
988 call assert_equal(4, len(g:lines), g:lines) | |
989 call assert_equal('asdf', g:lines[2]) | |
990 | |
991 au! BufReadCmd | |
992 au! BufWriteCmd | |
993 au! FileReadCmd | |
994 au! FileWriteCmd | |
995 au! FileAppendCmd | |
996 %bwipe! | |
997 call delete('Xxx') | |
998 enew! | |
999 endfunc |