mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.1203: some autocmd tests are old style
Problem: Some autocmd tests are old style.
Solution: Turn the tests into new style. (Yegappan Lakshmanan, closes vim/vim#4295)
69ea587289
This commit is contained in:
parent
7d90b90d63
commit
18fddad48b
@ -1401,3 +1401,205 @@ func Test_autocmd_once()
|
||||
|
||||
call assert_fails('au WinNew * ++once ++once echo bad', 'E983:')
|
||||
endfunc
|
||||
|
||||
" Tests for the following autocommands:
|
||||
" - FileWritePre writing a compressed file
|
||||
" - FileReadPost reading a compressed file
|
||||
" - BufNewFile reading a file template
|
||||
" - BufReadPre decompressing the file to be read
|
||||
" - FilterReadPre substituting characters in the temp file
|
||||
" - FilterReadPost substituting characters after filtering
|
||||
" - FileReadPre set options for decompression
|
||||
" - FileReadPost decompress the file
|
||||
func Test_ReadWrite_Autocmds()
|
||||
" Run this test only on Unix-like systems and if gzip is available
|
||||
if !has('unix') || !executable("gzip")
|
||||
return
|
||||
endif
|
||||
|
||||
" Make $GZIP empty, "-v" would cause trouble.
|
||||
let $GZIP = ""
|
||||
|
||||
" Use a FileChangedShell autocommand to avoid a prompt for 'Xtestfile.gz'
|
||||
" being modified outside of Vim (noticed on Solaris).
|
||||
au FileChangedShell * echo 'caught FileChangedShell'
|
||||
|
||||
" Test for the FileReadPost, FileWritePre and FileWritePost autocmds
|
||||
augroup Test1
|
||||
au!
|
||||
au FileWritePre *.gz '[,']!gzip
|
||||
au FileWritePost *.gz undo
|
||||
au FileReadPost *.gz '[,']!gzip -d
|
||||
augroup END
|
||||
|
||||
new
|
||||
set bin
|
||||
call append(0, [
|
||||
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
||||
\ ])
|
||||
1,9write! Xtestfile.gz
|
||||
enew! | close
|
||||
|
||||
new
|
||||
" Read and decompress the testfile
|
||||
0read Xtestfile.gz
|
||||
call assert_equal([
|
||||
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
||||
\ ], getline(1, 9))
|
||||
enew! | close
|
||||
|
||||
augroup Test1
|
||||
au!
|
||||
augroup END
|
||||
|
||||
" Test for the FileAppendPre and FileAppendPost autocmds
|
||||
augroup Test2
|
||||
au!
|
||||
au BufNewFile *.c read Xtest.c
|
||||
au FileAppendPre *.out '[,']s/new/NEW/
|
||||
au FileAppendPost *.out !cat Xtest.c >> test.out
|
||||
augroup END
|
||||
|
||||
call writefile(['/*', ' * Here is a new .c file', ' */'], 'Xtest.c')
|
||||
new foo.c " should load Xtest.c
|
||||
call assert_equal(['/*', ' * Here is a new .c file', ' */'], getline(2, 4))
|
||||
w! >> test.out " append it to the output file
|
||||
|
||||
let contents = readfile('test.out')
|
||||
call assert_equal(' * Here is a NEW .c file', contents[2])
|
||||
call assert_equal(' * Here is a new .c file', contents[5])
|
||||
|
||||
call delete('test.out')
|
||||
enew! | close
|
||||
augroup Test2
|
||||
au!
|
||||
augroup END
|
||||
|
||||
" Test for the BufReadPre and BufReadPost autocmds
|
||||
augroup Test3
|
||||
au!
|
||||
" setup autocommands to decompress before reading and re-compress
|
||||
" afterwards
|
||||
au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>"))
|
||||
au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
|
||||
au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r"))
|
||||
au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r"))
|
||||
augroup END
|
||||
|
||||
e! Xtestfile.gz " Edit compressed file
|
||||
call assert_equal([
|
||||
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
||||
\ ], getline(1, 9))
|
||||
|
||||
w! >> test.out " Append it to the output file
|
||||
|
||||
augroup Test3
|
||||
au!
|
||||
augroup END
|
||||
|
||||
" Test for the FilterReadPre and FilterReadPost autocmds.
|
||||
set shelltemp " need temp files here
|
||||
augroup Test4
|
||||
au!
|
||||
au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t")
|
||||
au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>"))
|
||||
au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t'
|
||||
au FilterReadPost *.out '[,']s/x/X/g
|
||||
augroup END
|
||||
|
||||
e! test.out " Edit the output file
|
||||
1,$!cat
|
||||
call assert_equal([
|
||||
\ 'linE 2 AbcdefghijklmnopqrstuvwXyz',
|
||||
\ 'linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
\ 'linE 4 AbcdefghijklmnopqrstuvwXyz',
|
||||
\ 'linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
\ 'linE 6 AbcdefghijklmnopqrstuvwXyz',
|
||||
\ 'linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
\ 'linE 8 AbcdefghijklmnopqrstuvwXyz',
|
||||
\ 'linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
\ 'linE 10 AbcdefghijklmnopqrstuvwXyz'
|
||||
\ ], getline(1, 9))
|
||||
call assert_equal([
|
||||
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
||||
\ ], readfile('test.out'))
|
||||
|
||||
augroup Test4
|
||||
au!
|
||||
augroup END
|
||||
set shelltemp&vim
|
||||
|
||||
" Test for the FileReadPre and FileReadPost autocmds.
|
||||
augroup Test5
|
||||
au!
|
||||
au FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>"))
|
||||
au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
|
||||
au FileReadPost *.gz '[,']s/l/L/
|
||||
augroup END
|
||||
|
||||
new
|
||||
0r Xtestfile.gz " Read compressed file
|
||||
call assert_equal([
|
||||
\ 'Line 2 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'Line 4 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'Line 6 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'Line 8 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'Line 10 Abcdefghijklmnopqrstuvwxyz'
|
||||
\ ], getline(1, 9))
|
||||
call assert_equal([
|
||||
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
||||
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
||||
\ ], readfile('Xtestfile.gz'))
|
||||
|
||||
augroup Test5
|
||||
au!
|
||||
augroup END
|
||||
|
||||
au! FileChangedShell
|
||||
call delete('Xtestfile.gz')
|
||||
call delete('Xtest.c')
|
||||
call delete('test.out')
|
||||
endfunc
|
||||
|
Loading…
Reference in New Issue
Block a user