blob: fb3628b273989ef02a7e18a6766c0f897a7a5e46 [file] [log] [blame]
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02001" Tests for parsing the modeline.
2
Bram Moolenaarcd96eef2018-07-23 04:49:23 +02003func Test_modeline_invalid()
Bram Moolenaar9691f822018-11-03 19:06:25 +01004 " This was reading allocated memory in the past.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005 call writefile(['vi:0', 'nothing'], 'Xmodeline')
Bram Moolenaar9691f822018-11-03 19:06:25 +01006 let modeline = &modeline
7 set modeline
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02008 call assert_fails('split Xmodeline', 'E518:')
Bram Moolenaar916a8182018-11-25 02:18:29 +01009
Bram Moolenaar9691f822018-11-03 19:06:25 +010010 let &modeline = modeline
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020011 bwipe!
Bram Moolenaar7624af02018-07-24 04:51:20 +020012 call delete('Xmodeline')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020013endfunc
Bram Moolenaar916a8182018-11-25 02:18:29 +010014
15func 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
29endfunc
30
31func 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
44endfunc
45
46func Test_modeline_keymap()
Bram Moolenaar4ace6ab2018-11-25 04:25:58 +010047 if !has('keymap')
48 return
49 endif
Bram Moolenaar916a8182018-11-25 02:18:29 +010050 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
61endfunc
62
Bram Moolenaar110289e2019-05-23 15:38:06 +020063func s:modeline_fails(what, text, error)
64 if !exists('+' .. a:what)
65 return
66 endif
Bram Moolenaar916a8182018-11-25 02:18:29 +010067 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 Moolenaar110289e2019-05-23 15:38:06 +020073 call assert_fails('split ' . fname, a:error)
Bram Moolenaar916a8182018-11-25 02:18:29 +010074 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
82endfunc
83
84func Test_modeline_filetype_fails()
Bram Moolenaar110289e2019-05-23 15:38:06 +020085 call s:modeline_fails('filetype', 'ft=evil$CMD', 'E474:')
Bram Moolenaar916a8182018-11-25 02:18:29 +010086endfunc
87
88func Test_modeline_syntax_fails()
Bram Moolenaar110289e2019-05-23 15:38:06 +020089 call s:modeline_fails('syntax', 'syn=evil$CMD', 'E474:')
Bram Moolenaar916a8182018-11-25 02:18:29 +010090endfunc
91
92func Test_modeline_keymap_fails()
Bram Moolenaar110289e2019-05-23 15:38:06 +020093 call s:modeline_fails('keymap', 'keymap=evil$CMD', 'E474:')
94endfunc
95
96func 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 Moolenaar7e800c62019-05-23 17:08:49 +0200122 call s:modeline_fails('modelineexpr', 'modelineexpr', 'E520:')
Bram Moolenaar110289e2019-05-23 15:38:06 +0200123 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 Moolenaare09244e2019-05-23 17:35:55 +0200130 call s:modeline_fails('pythonhome', 'pythonhome=Something()', 'E520:')
Bram Moolenaar110289e2019-05-23 15:38:06 +0200131 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:')
157endfunc
158
159func 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 Moolenaar916a8182018-11-25 02:18:29 +0100172endfunc