Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 1 | " Tests for parsing the modeline. |
| 2 | |
Bram Moolenaar | cd96eef | 2018-07-23 04:49:23 +0200 | [diff] [blame] | 3 | func Test_modeline_invalid() |
Bram Moolenaar | 9691f82 | 2018-11-03 19:06:25 +0100 | [diff] [blame] | 4 | " This was reading allocated memory in the past. |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5 | call writefile(['vi:0', 'nothing'], 'Xmodeline') |
Bram Moolenaar | 9691f82 | 2018-11-03 19:06:25 +0100 | [diff] [blame] | 6 | let modeline = &modeline |
| 7 | set modeline |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 8 | call assert_fails('split Xmodeline', 'E518:') |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 9 | |
Bram Moolenaar | 9691f82 | 2018-11-03 19:06:25 +0100 | [diff] [blame] | 10 | let &modeline = modeline |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 11 | bwipe! |
Bram Moolenaar | 7624af0 | 2018-07-24 04:51:20 +0200 | [diff] [blame] | 12 | call delete('Xmodeline') |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 13 | endfunc |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 14 | |
| 15 | func Test_modeline_filetype() |
| 16 | call writefile(['vim: set ft=c :', 'nothing'], 'Xmodeline_filetype') |
| 17 | let modeline = &modeline |
| 18 | set modeline |
| 19 | filetype plugin on |
| 20 | split Xmodeline_filetype |
| 21 | call assert_equal("c", &filetype) |
| 22 | call assert_equal(1, b:did_ftplugin) |
| 23 | call assert_equal("ccomplete#Complete", &ofu) |
| 24 | |
| 25 | bwipe! |
| 26 | call delete('Xmodeline_filetype') |
| 27 | let &modeline = modeline |
| 28 | filetype plugin off |
| 29 | endfunc |
| 30 | |
| 31 | func Test_modeline_syntax() |
| 32 | call writefile(['vim: set syn=c :', 'nothing'], 'Xmodeline_syntax') |
| 33 | let modeline = &modeline |
| 34 | set modeline |
| 35 | syntax enable |
| 36 | split Xmodeline_syntax |
| 37 | call assert_equal("c", &syntax) |
| 38 | call assert_equal("c", b:current_syntax) |
| 39 | |
| 40 | bwipe! |
| 41 | call delete('Xmodeline_syntax') |
| 42 | let &modeline = modeline |
| 43 | syntax off |
| 44 | endfunc |
| 45 | |
| 46 | func Test_modeline_keymap() |
Bram Moolenaar | 4ace6ab | 2018-11-25 04:25:58 +0100 | [diff] [blame] | 47 | if !has('keymap') |
| 48 | return |
| 49 | endif |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 50 | call writefile(['vim: set keymap=greek :', 'nothing'], 'Xmodeline_keymap') |
| 51 | let modeline = &modeline |
| 52 | set modeline |
| 53 | split Xmodeline_keymap |
| 54 | call assert_equal("greek", &keymap) |
| 55 | call assert_match('greek\|grk', b:keymap_name) |
| 56 | |
| 57 | bwipe! |
| 58 | call delete('Xmodeline_keymap') |
| 59 | let &modeline = modeline |
| 60 | set keymap= iminsert=0 imsearch=-1 |
| 61 | endfunc |
| 62 | |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 63 | func s:modeline_fails(what, text, error) |
| 64 | if !exists('+' .. a:what) |
| 65 | return |
| 66 | endif |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 67 | let fname = "Xmodeline_fails_" . a:what |
| 68 | call writefile(['vim: set ' . a:text . ' :', 'nothing'], fname) |
| 69 | let modeline = &modeline |
| 70 | set modeline |
| 71 | filetype plugin on |
| 72 | syntax enable |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 73 | call assert_fails('split ' . fname, a:error) |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 74 | call assert_equal("", &filetype) |
| 75 | call assert_equal("", &syntax) |
| 76 | |
| 77 | bwipe! |
| 78 | call delete(fname) |
| 79 | let &modeline = modeline |
| 80 | filetype plugin off |
| 81 | syntax off |
| 82 | endfunc |
| 83 | |
| 84 | func Test_modeline_filetype_fails() |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 85 | call s:modeline_fails('filetype', 'ft=evil$CMD', 'E474:') |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 86 | endfunc |
| 87 | |
| 88 | func Test_modeline_syntax_fails() |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 89 | call s:modeline_fails('syntax', 'syn=evil$CMD', 'E474:') |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 90 | endfunc |
| 91 | |
| 92 | func Test_modeline_keymap_fails() |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 93 | call s:modeline_fails('keymap', 'keymap=evil$CMD', 'E474:') |
| 94 | endfunc |
| 95 | |
| 96 | func Test_modeline_fails_always() |
| 97 | call s:modeline_fails('backupdir', 'backupdir=Something()', 'E520:') |
| 98 | call s:modeline_fails('cdpath', 'cdpath=Something()', 'E520:') |
| 99 | call s:modeline_fails('charconvert', 'charconvert=Something()', 'E520:') |
| 100 | call s:modeline_fails('completefunc', 'completefunc=Something()', 'E520:') |
| 101 | call s:modeline_fails('cscopeprg', 'cscopeprg=Something()', 'E520:') |
| 102 | call s:modeline_fails('diffexpr', 'diffexpr=Something()', 'E520:') |
| 103 | call s:modeline_fails('directory', 'directory=Something()', 'E520:') |
| 104 | call s:modeline_fails('equalprg', 'equalprg=Something()', 'E520:') |
| 105 | call s:modeline_fails('errorfile', 'errorfile=Something()', 'E520:') |
| 106 | call s:modeline_fails('exrc', 'exrc=Something()', 'E520:') |
| 107 | call s:modeline_fails('formatprg', 'formatprg=Something()', 'E520:') |
| 108 | call s:modeline_fails('fsync', 'fsync=Something()', 'E520:') |
| 109 | call s:modeline_fails('grepprg', 'grepprg=Something()', 'E520:') |
| 110 | call s:modeline_fails('helpfile', 'helpfile=Something()', 'E520:') |
| 111 | call s:modeline_fails('imactivatefunc', 'imactivatefunc=Something()', 'E520:') |
| 112 | call s:modeline_fails('imstatusfunc', 'imstatusfunc=Something()', 'E520:') |
| 113 | call s:modeline_fails('imstyle', 'imstyle=Something()', 'E520:') |
| 114 | call s:modeline_fails('keywordprg', 'keywordprg=Something()', 'E520:') |
| 115 | call s:modeline_fails('langmap', 'langmap=Something()', 'E520:') |
| 116 | call s:modeline_fails('luadll', 'luadll=Something()', 'E520:') |
| 117 | call s:modeline_fails('makeef', 'makeef=Something()', 'E520:') |
| 118 | call s:modeline_fails('makeprg', 'makeprg=Something()', 'E520:') |
| 119 | call s:modeline_fails('makespellmem', 'makespellmem=Something()', 'E520:') |
| 120 | call s:modeline_fails('mzschemedll', 'mzschemedll=Something()', 'E520:') |
| 121 | call s:modeline_fails('mzschemegcdll', 'mzschemegcdll=Something()', 'E520:') |
Bram Moolenaar | 7e800c6 | 2019-05-23 17:08:49 +0200 | [diff] [blame] | 122 | call s:modeline_fails('modelineexpr', 'modelineexpr', 'E520:') |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 123 | call s:modeline_fails('omnifunc', 'omnifunc=Something()', 'E520:') |
| 124 | call s:modeline_fails('operatorfunc', 'operatorfunc=Something()', 'E520:') |
| 125 | call s:modeline_fails('perldll', 'perldll=Something()', 'E520:') |
| 126 | call s:modeline_fails('printdevice', 'printdevice=Something()', 'E520:') |
| 127 | call s:modeline_fails('patchexpr', 'patchexpr=Something()', 'E520:') |
| 128 | call s:modeline_fails('printexpr', 'printexpr=Something()', 'E520:') |
| 129 | call s:modeline_fails('pythondll', 'pythondll=Something()', 'E520:') |
Bram Moolenaar | e09244e | 2019-05-23 17:35:55 +0200 | [diff] [blame] | 130 | call s:modeline_fails('pythonhome', 'pythonhome=Something()', 'E520:') |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 131 | call s:modeline_fails('pythonthreedll', 'pythonthreedll=Something()', 'E520:') |
| 132 | call s:modeline_fails('pythonthreehome', 'pythonthreehome=Something()', 'E520:') |
| 133 | call s:modeline_fails('pyxversion', 'pyxversion=Something()', 'E520:') |
| 134 | call s:modeline_fails('rubydll', 'rubydll=Something()', 'E520:') |
| 135 | call s:modeline_fails('runtimepath', 'runtimepath=Something()', 'E520:') |
| 136 | call s:modeline_fails('secure', 'secure=Something()', 'E520:') |
| 137 | call s:modeline_fails('shell', 'shell=Something()', 'E520:') |
| 138 | call s:modeline_fails('shellcmdflag', 'shellcmdflag=Something()', 'E520:') |
| 139 | call s:modeline_fails('shellpipe', 'shellpipe=Something()', 'E520:') |
| 140 | call s:modeline_fails('shellquote', 'shellquote=Something()', 'E520:') |
| 141 | call s:modeline_fails('shellredir', 'shellredir=Something()', 'E520:') |
| 142 | call s:modeline_fails('shellxquote', 'shellxquote=Something()', 'E520:') |
| 143 | call s:modeline_fails('spellfile', 'spellfile=Something()', 'E520:') |
| 144 | call s:modeline_fails('spellsuggest', 'spellsuggest=Something()', 'E520:') |
| 145 | call s:modeline_fails('tcldll', 'tcldll=Something()', 'E520:') |
| 146 | call s:modeline_fails('titleold', 'titleold=Something()', 'E520:') |
| 147 | call s:modeline_fails('viewdir', 'viewdir=Something()', 'E520:') |
| 148 | call s:modeline_fails('viminfo', 'viminfo=Something()', 'E520:') |
| 149 | call s:modeline_fails('viminfofile', 'viminfofile=Something()', 'E520:') |
| 150 | call s:modeline_fails('winptydll', 'winptydll=Something()', 'E520:') |
| 151 | call s:modeline_fails('undodir', 'undodir=Something()', 'E520:') |
| 152 | " only check a few terminal options |
| 153 | call s:modeline_fails('t_AB', 't_AB=Something()', 'E520:') |
| 154 | call s:modeline_fails('t_ce', 't_ce=Something()', 'E520:') |
| 155 | call s:modeline_fails('t_sr', 't_sr=Something()', 'E520:') |
| 156 | call s:modeline_fails('t_8b', 't_8b=Something()', 'E520:') |
| 157 | endfunc |
| 158 | |
| 159 | func Test_modeline_fails_modelineexpr() |
| 160 | call s:modeline_fails('balloonexpr', 'balloonexpr=Something()', 'E992:') |
| 161 | call s:modeline_fails('foldexpr', 'foldexpr=Something()', 'E992:') |
| 162 | call s:modeline_fails('foldtext', 'foldtext=Something()', 'E992:') |
| 163 | call s:modeline_fails('formatexpr', 'formatexpr=Something()', 'E992:') |
| 164 | call s:modeline_fails('guitablabel', 'guitablabel=Something()', 'E992:') |
| 165 | call s:modeline_fails('iconstring', 'iconstring=Something()', 'E992:') |
| 166 | call s:modeline_fails('includeexpr', 'includeexpr=Something()', 'E992:') |
| 167 | call s:modeline_fails('indentexpr', 'indentexpr=Something()', 'E992:') |
| 168 | call s:modeline_fails('rulerformat', 'rulerformat=Something()', 'E992:') |
| 169 | call s:modeline_fails('statusline', 'statusline=Something()', 'E992:') |
| 170 | call s:modeline_fails('tabline', 'tabline=Something()', 'E992:') |
| 171 | call s:modeline_fails('titlestring', 'titlestring=Something()', 'E992:') |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 172 | endfunc |