vim-patch:8.2.0015: not all modeline variants are tested

Problem:    Not all modeline variants are tested.
Solution:   Add modeline tests. (Dominique Pelle, closes vim/vim#5369)
e74331db4b
This commit is contained in:
Jan Edmund Lazo 2019-12-17 21:38:11 -05:00
parent 1bfccf0286
commit 74a547d340
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -5,12 +5,30 @@ func Test_modeline_invalid()
call writefile(['vi:0', 'nothing'], 'Xmodeline')
let modeline = &modeline
set modeline
call assert_fails('set Xmodeline', 'E518:')
call assert_fails('split Xmodeline', 'E518:')
" Missing end colon (ignored).
call writefile(['// vim: set ts=2'], 'Xmodeline')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
" Missing colon at beginning (ignored).
call writefile(['// vim set ts=2:'], 'Xmodeline')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
" Missing space after vim (ignored).
call writefile(['// vim:ts=2:'], 'Xmodeline')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
let &modeline = modeline
bwipe!
call delete('Xmodeline')
endfunc
endfunc
func Test_modeline_filetype()
call writefile(['vim: set ft=c :', 'nothing'], 'Xmodeline_filetype')
@ -60,8 +78,99 @@ func Test_modeline_keymap()
set keymap= iminsert=0 imsearch=-1
endfunc
func Test_modeline_version()
let modeline = &modeline
set modeline
" Test with vim:{vers}: (version {vers} or later).
call writefile(['// vim' .. v:version .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(2, &ts)
bwipe!
call writefile(['// vim' .. (v:version - 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(2, &ts)
bwipe!
call writefile(['// vim' .. (v:version + 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bw!
" Test with vim>{vers}: (version after {vers}).
call writefile(['// vim>' .. v:version .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
call writefile(['// vim>' .. (v:version - 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(2, &ts)
bwipe!
call writefile(['// vim>' .. (v:version + 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
" Test with vim<{vers}: (version before {vers}).
call writefile(['// vim<' .. v:version .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
call writefile(['// vim<' .. (v:version - 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
call writefile(['// vim<' .. (v:version + 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(2, &ts)
bwipe!
" Test with vim={vers}: (version {vers} only).
call writefile(['// vim=' .. v:version .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(2, &ts)
bwipe!
call writefile(['// vim=' .. (v:version - 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
call writefile(['// vim=' .. (v:version + 100) .. ': ts=2:'], 'Xmodeline_version')
edit Xmodeline_version
call assert_equal(8, &ts)
bwipe!
let &modeline = modeline
call delete('Xmodeline_version')
endfunc
func Test_modeline_colon()
let modeline = &modeline
set modeline
call writefile(['// vim: set showbreak=\: ts=2: sw=2'], 'Xmodeline_colon')
edit Xmodeline_colon
" backlash colon should become colon.
call assert_equal(':', &showbreak)
" 'ts' should be set.
" 'sw' should be ignored because it is after the end colon.
call assert_equal(2, &ts)
call assert_equal(8, &sw)
let &modeline = modeline
call delete('Xmodeline_colon')
endfunc
func s:modeline_fails(what, text, error)
if !exists('+' . a:what)
if !exists('+' .. a:what)
return
endif
let fname = "Xmodeline_fails_" . a:what
@ -119,7 +228,7 @@ func Test_modeline_fails_always()
call s:modeline_fails('mkspellmem', 'mkspellmem=Something()', 'E520:')
call s:modeline_fails('mzschemedll', 'mzschemedll=Something()', 'E520:')
call s:modeline_fails('mzschemegcdll', 'mzschemegcdll=Something()', 'E520:')
call s:modeline_fails('modelineexpr', 'modelineexpr=Something()', 'E520:')
call s:modeline_fails('modelineexpr', 'modelineexpr', 'E520:')
call s:modeline_fails('omnifunc', 'omnifunc=Something()', 'E520:')
call s:modeline_fails('operatorfunc', 'operatorfunc=Something()', 'E520:')
call s:modeline_fails('perldll', 'perldll=Something()', 'E520:')