blob: 9e9e257c1d28f4029a4e55b79cb34e1ca0776d4f [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
Bram Moolenaar2d231cb2010-08-08 13:18:47 +020011Note: This test is skipped if "gzip" is not available.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012$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
Bram Moolenaar2d231cb2010-08-08 13:18:47 +020018:" drop out when there is no gzip program
19:if !executable("gzip")
20: e! test.ok
21: w! test.out
22: qa!
23:endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000024:let $GZIP = ""
25:au FileChangedShell * echo "caught FileChangedShell"
26:set bin
27:au FileWritePre *.gz '[,']!gzip
28:au FileWritePost *.gz undo
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000029:/^start of testfile/,/^end of testfile/w! Xtestfile.gz
Bram Moolenaar071d4272004-06-13 20:20:40 +000030:au FileReadPost *.gz '[,']!gzip -d
31:$r Xtestfile.gz " Read and decompress the testfile
32:?startstart?,$w! test.out " Write contents of this file
33:au BufNewFile *.c read Xtest.c
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000034:/^start of test.c/+1,/^end of test.c/-1w! Xtest.c
Bram Moolenaar071d4272004-06-13 20:20:40 +000035:e! foo.c " Will load Xtest.c
36:au FileAppendPre *.out '[,']s/new/NEW/
37:au FileAppendPost *.out !cat Xtest.c >>test.out
38:w>>test.out " Append it to the output file
39:au! FileAppendPre
40:" setup autocommands to decompress before reading and re-compress afterwards
Bram Moolenaar8c8de832008-06-24 22:58:06 +000041:au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000042:au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
43:au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r"))
Bram Moolenaar8c8de832008-06-24 22:58:06 +000044:au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000045:e! Xtestfile.gz " Edit compressed file
46:w>>test.out " Append it to the output file
Bram Moolenaardf177f62005-02-22 08:39:57 +000047:set shelltemp " need temp files here
Bram Moolenaar8c8de832008-06-24 22:58:06 +000048:au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t")
Bram Moolenaar68856942014-10-09 15:37:06 +020049:au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>"))
50:au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000051:au FilterReadPost *.out '[,']s/x/X/g
52:e! test.out " Edit the output file
53:23,$!cat
Bram Moolenaarfa4fd1b2005-01-04 21:21:28 +000054:23,$s/\r$// " remove CR for when sed adds them
Bram Moolenaar68856942014-10-09 15:37:06 +020055:au! FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000056:au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
57:au! FileReadPost *.gz '[,']s/l/L/
58:$r Xtestfile.gz " Read compressed file
59:w " write it, after filtering
60:au! " remove all autocommands
61:e " Edit test.out again
62:set nobin ff& " use the default fileformat for writing
63:w
64:qa!
65ENDTEST
66
67startstart
68start of testfile
69line 2 Abcdefghijklmnopqrstuvwxyz
70line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
71line 4 Abcdefghijklmnopqrstuvwxyz
72line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
73line 6 Abcdefghijklmnopqrstuvwxyz
74line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
75line 8 Abcdefghijklmnopqrstuvwxyz
76line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
77line 10 Abcdefghijklmnopqrstuvwxyz
78end of testfile
79
80start of test.c
81/*
82 * Here is a new .c file
83 */
84end of test.c