blob: 6b296fd4e893540044968f5030c3598ed1ade561 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001Tests for autocommands:
2- FileWritePre writing a compressed file
3- FileReadPost reading a compressed file
4- BufNewFile reading a file template
5- BufReadPre decompressing the file to be read
6- FilterReadPre substituting characters in the temp file
7- FilterReadPost substituting characters after filtering
8- FileReadPre set options for decompression
9- FileReadPost decompress the file
10
11Note: This test will fail if "gzip" is not available.
12$GZIP is made empty, "-v" would cause trouble.
13Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" being
14modified outside of Vim (noticed on Solaris).
15
16STARTTEST
17:so small.vim
18:let $GZIP = ""
19:au FileChangedShell * echo "caught FileChangedShell"
20:set bin
21:au FileWritePre *.gz '[,']!gzip
22:au FileWritePost *.gz undo
23:/start of testfile/,/end of testfile/w! Xtestfile.gz
24:au FileReadPost *.gz '[,']!gzip -d
25:$r Xtestfile.gz " Read and decompress the testfile
26:?startstart?,$w! test.out " Write contents of this file
27:au BufNewFile *.c read Xtest.c
28gg/^end of testfile
29:/start of test.c/+1,/end of test.c/-1w! Xtest.c
30:e! foo.c " Will load Xtest.c
31:au FileAppendPre *.out '[,']s/new/NEW/
32:au FileAppendPost *.out !cat Xtest.c >>test.out
33:w>>test.out " Append it to the output file
34:au! FileAppendPre
35:" setup autocommands to decompress before reading and re-compress afterwards
36:au BufReadPre *.gz !gzip -d <afile>
37:au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
38:au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r"))
39:au BufReadPost *.gz !gzip <afile>:r
40:e! Xtestfile.gz " Edit compressed file
41:w>>test.out " Append it to the output file
42:au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>").".t")
43:au FilterReadPre *.out !sed s/e/E/ <afile>.t ><afile>
44:au FilterReadPre *.out !rm <afile>.t
45:au FilterReadPost *.out '[,']s/x/X/g
46:e! test.out " Edit the output file
47:23,$!cat
48:au! FileReadPre *.gz !gzip -d <afile>
49:au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
50:au! FileReadPost *.gz '[,']s/l/L/
51:$r Xtestfile.gz " Read compressed file
52:w " write it, after filtering
53:au! " remove all autocommands
54:e " Edit test.out again
55:set nobin ff& " use the default fileformat for writing
56:w
57:qa!
58ENDTEST
59
60startstart
61start of testfile
62line 2 Abcdefghijklmnopqrstuvwxyz
63line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
64line 4 Abcdefghijklmnopqrstuvwxyz
65line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
66line 6 Abcdefghijklmnopqrstuvwxyz
67line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
68line 8 Abcdefghijklmnopqrstuvwxyz
69line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
70line 10 Abcdefghijklmnopqrstuvwxyz
71end of testfile
72
73start of test.c
74/*
75 * Here is a new .c file
76 */
77end of test.c