Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | Tests 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 Moolenaar | 2d231cb | 2010-08-08 13:18:47 +0200 | [diff] [blame] | 11 | Note: This test is skipped if "gzip" is not available. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 12 | $GZIP is made empty, "-v" would cause trouble. |
| 13 | Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" being |
| 14 | modified outside of Vim (noticed on Solaris). |
| 15 | |
| 16 | STARTTEST |
| 17 | :so small.vim |
Bram Moolenaar | 2d231cb | 2010-08-08 13:18:47 +0200 | [diff] [blame] | 18 | :" 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | :let $GZIP = "" |
| 25 | :au FileChangedShell * echo "caught FileChangedShell" |
| 26 | :set bin |
| 27 | :au FileWritePre *.gz '[,']!gzip |
| 28 | :au FileWritePost *.gz undo |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 29 | :/^start of testfile/,/^end of testfile/w! Xtestfile.gz |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | :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 Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 34 | :/^start of test.c/+1,/^end of test.c/-1w! Xtest.c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 35 | :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 Moolenaar | 8c8de83 | 2008-06-24 22:58:06 +0000 | [diff] [blame] | 41 | :au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>")) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | :au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) |
| 43 | :au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r")) |
Bram Moolenaar | 8c8de83 | 2008-06-24 22:58:06 +0000 | [diff] [blame] | 44 | :au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r")) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 45 | :e! Xtestfile.gz " Edit compressed file |
| 46 | :w>>test.out " Append it to the output file |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 47 | :set shelltemp " need temp files here |
Bram Moolenaar | 8c8de83 | 2008-06-24 22:58:06 +0000 | [diff] [blame] | 48 | :au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t") |
Bram Moolenaar | 6885694 | 2014-10-09 15:37:06 +0200 | [diff] [blame] | 49 | :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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | :au FilterReadPost *.out '[,']s/x/X/g |
| 52 | :e! test.out " Edit the output file |
| 53 | :23,$!cat |
Bram Moolenaar | fa4fd1b | 2005-01-04 21:21:28 +0000 | [diff] [blame] | 54 | :23,$s/\r$// " remove CR for when sed adds them |
Bram Moolenaar | 6885694 | 2014-10-09 15:37:06 +0200 | [diff] [blame] | 55 | :au! FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>")) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 56 | :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! |
| 65 | ENDTEST |
| 66 | |
| 67 | startstart |
| 68 | start of testfile |
| 69 | line 2 Abcdefghijklmnopqrstuvwxyz |
| 70 | line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 71 | line 4 Abcdefghijklmnopqrstuvwxyz |
| 72 | line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 73 | line 6 Abcdefghijklmnopqrstuvwxyz |
| 74 | line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 75 | line 8 Abcdefghijklmnopqrstuvwxyz |
| 76 | line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 77 | line 10 Abcdefghijklmnopqrstuvwxyz |
| 78 | end of testfile |
| 79 | |
| 80 | start of test.c |
| 81 | /* |
| 82 | * Here is a new .c file |
| 83 | */ |
| 84 | end of test.c |