1" Test :setfiletype
2
3func Test_detection()
4  filetype on
5  augroup filetypedetect
6    au BufNewFile,BufRead *	call assert_equal(1, did_filetype())
7  augroup END
8  new something.vim
9  call assert_equal('vim', &filetype)
10
11  bwipe!
12  filetype off
13endfunc
14
15func Test_conf_type()
16  filetype on
17  call writefile(['# some comment', 'must be conf'], 'Xfile')
18  augroup filetypedetect
19    au BufNewFile,BufRead *	call assert_equal(0, did_filetype())
20  augroup END
21  split Xfile
22  call assert_equal('conf', &filetype)
23
24  bwipe!
25  call delete('Xfile')
26  filetype off
27endfunc
28
29func Test_other_type()
30  filetype on
31  augroup filetypedetect
32    au BufNewFile,BufRead *	call assert_equal(0, did_filetype())
33    au BufNewFile,BufRead Xfile	setf testfile
34    au BufNewFile,BufRead *	call assert_equal(1, did_filetype())
35  augroup END
36  call writefile(['# some comment', 'must be conf'], 'Xfile')
37  split Xfile
38  call assert_equal('testfile', &filetype)
39
40  bwipe!
41  call delete('Xfile')
42  filetype off
43endfunc
44
45" Filetypes detected just from matching the file name.
46let s:filename_checks = {
47    \ '8th': ['file.8th'],
48    \ 'a2ps': ['/etc/a2ps.cfg', '/etc/a2ps/file.cfg', 'a2psrc', '.a2psrc'],
49    \ 'a65': ['file.a65'],
50    \ 'aap': ['file.aap'],
51    \ 'abap': ['file.abap'],
52    \ 'abc': ['file.abc'],
53    \ 'abel': ['file.abl'],
54    \ 'acedb': ['file.wrm'],
55    \ 'ada': ['file.adb', 'file.ads', 'file.ada', 'file.gpr'],
56    \ 'ahdl': ['file.tdf'],
57    \ 'alsaconf': ['.asoundrc', '/usr/share/alsa/alsa.conf', '/etc/asound.conf'],
58    \ 'aml': ['file.aml'],
59    \ 'ampl': ['file.run'],
60    \ 'ant': ['build.xml'],
61    \ 'apache': ['.htaccess', '/etc/httpd/file.conf', '/etc/apache2/sites-2/file.com', '/etc/apache2/some.config', '/etc/apache2/conf.file/conf', '/etc/apache2/mods-some/file', '/etc/apache2/sites-some/file', '/etc/httpd/conf.d/file.config'],
62    \ 'apachestyle': ['/etc/proftpd/file.config,/etc/proftpd/conf.file/file'],
63    \ 'applescript': ['file.scpt'],
64    \ 'aptconf': ['apt.conf', '/.aptitude/config'],
65    \ 'arch': ['.arch-inventory'],
66    \ 'arduino': ['file.ino', 'file.pde'],
67    \ 'art': ['file.art'],
68    \ 'asciidoc': ['file.asciidoc', 'file.adoc'],
69    \ 'asn': ['file.asn', 'file.asn1'],
70    \ 'atlas': ['file.atl', 'file.as'],
71    \ 'autohotkey': ['file.ahk'],
72    \ 'autoit': ['file.au3'],
73    \ 'automake': ['GNUmakefile.am'],
74    \ 'ave': ['file.ave'],
75    \ 'awk': ['file.awk'],
76    \ 'b': ['file.mch', 'file.ref', 'file.imp'],
77    \ 'bc': ['file.bc'],
78    \ 'bdf': ['file.bdf'],
79    \ 'bib': ['file.bib'],
80    \ 'bindzone': ['named.root'],
81    \ 'blank': ['file.bl'],
82    \ 'bsdl': ['file.bsd', 'file.bsdl'],
83    \ 'bst': ['file.bst'],
84    \ 'bzr': ['bzr_log.any'],
85    \ 'c': ['enlightenment/file.cfg', 'file.qc', 'file.c'],
86    \ 'cabal': ['file.cabal'],
87    \ 'calendar': ['calendar'],
88    \ 'catalog': ['catalog', 'sgml.catalogfile'],
89    \ 'cdl': ['file.cdl'],
90    \ 'cdrdaoconf': ['/etc/cdrdao.conf', '/etc/defaults/cdrdao', '/etc/default/cdrdao', '.cdrdao'],
91    \ 'cdrtoc': ['file.toc'],
92    \ 'cf': ['file.cfm', 'file.cfi', 'file.cfc'],
93    \ 'cfengine': ['cfengine.conf'],
94    \ 'cfg': ['file.cfg', 'file.hgrc', 'filehgrc'],
95    \ 'ch': ['file.chf'],
96    \ 'chaiscript': ['file.chai'],
97    \ 'chaskell': ['file.chs'],
98    \ 'chill': ['file..ch'],
99    \ 'chordpro': ['file.chopro', 'file.crd', 'file.cho', 'file.crdpro', 'file.chordpro'],
100    \ 'cl': ['file.eni'],
101    \ 'clean': ['file.dcl', 'file.icl'],
102    \ 'clojure': ['file.clj', 'file.cljs', 'file.cljx', 'file.cljc'],
103    \ 'cmake': ['CMakeLists.txt', 'file.cmake', 'file.cmake.in'],
104    \ 'cmusrc': ['any/.cmus/autosave', 'any/.cmus/rc', 'any/.cmus/command-history', 'any/.cmus/file.theme', 'any/cmus/rc', 'any/cmus/file.theme'],
105    \ 'cobol': ['file.cbl', 'file.cob', 'file.lib'],
106    \ 'coco': ['file.atg'],
107    \ 'conaryrecipe': ['file.recipe'],
108    \ 'conf': ['auto.master'],
109    \ 'config': ['configure.in', 'configure.ac', 'Pipfile'],
110    \ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi'],
111    \ 'cpp': ['file.cxx', 'file.c++', 'file.hh', 'file.hxx', 'file.hpp', 'file.ipp', 'file.moc', 'file.tcc', 'file.inl', 'file.tlh'],
112    \ 'crm': ['file.crm'],
113    \ 'cs': ['file.cs'],
114    \ 'csc': ['file.csc'],
115    \ 'csdl': ['file.csdl'],
116    \ 'csp': ['file.csp', 'file.fdr'],
117    \ 'css': ['file.css'],
118    \ 'cterm': ['file.con'],
119    \ 'cucumber': ['file.feature'],
120    \ 'cuda': ['file.cu'],
121    \ 'cupl': ['file.pld'],
122    \ 'cuplsim': ['file.si'],
123    \ 'cvs': ['cvs123'],
124    \ 'cvsrc': ['.cvsrc'],
125    \ 'cynpp': ['file.cyn'],
126    \ 'dart': ['file.dart', 'file.drt'],
127    \ 'datascript': ['file.ds'],
128    \ 'dcd': ['file.dcd'],
129    \ 'debcontrol': ['/debian/control'],
130    \ 'debsources': ['/etc/apt/sources.list', '/etc/apt/sources.list.d/file.list'],
131    \ 'def': ['file.def'],
132    \ 'denyhosts': ['denyhosts.conf'],
133    \ 'desc': ['file.desc'],
134    \ 'desktop': ['file.desktop', '.directory', 'file.directory'],
135    \ 'dictconf': ['dict.conf', '.dictrc'],
136    \ 'dictdconf': ['dictd.conf'],
137    \ 'diff': ['file.diff', 'file.rej'],
138    \ 'dircolors': ['.dir_colors', '.dircolors', '/etc/DIR_COLORS'],
139    \ 'dnsmasq': ['/etc/dnsmasq.conf'],
140    \ 'dockerfile': ['Containerfile', 'Dockerfile', 'file.Dockerfile'],
141    \ 'dosbatch': ['file.bat', 'file.sys'],
142    \ 'dosini': ['.editorconfig', '/etc/yum.conf', 'file.ini'],
143    \ 'dot': ['file.dot', 'file.gv'],
144    \ 'dracula': ['file.drac', 'file.drc', 'filelvs', 'filelpe'],
145    \ 'dsl': ['file.dsl'],
146    \ 'dtd': ['file.dtd'],
147    \ 'dts': ['file.dts', 'file.dtsi'],
148    \ 'dylan': ['file.dylan'],
149    \ 'dylanintr': ['file.intr'],
150    \ 'dylanlid': ['file.lid'],
151    \ 'ecd': ['file.ecd'],
152    \ 'edif': ['file.edf', 'file.edif', 'file.edo'],
153    \ 'elinks': ['/etc/elinks.conf', '/.elinks/elinks.conf'],
154    \ 'elm': ['file.elm'],
155    \ 'elmfilt': ['filter-rules'],
156    \ 'erlang': ['file.erl', 'file.hrl', 'file.yaws'],
157    \ 'eruby': ['file.erb', 'file.rhtml'],
158    \ 'esmtprc': ['anyesmtprc'],
159    \ 'esqlc': ['file.ec', 'file.EC'],
160    \ 'esterel': ['file.strl'],
161    \ 'eterm': ['anyEterm/file.cfg'],
162    \ 'exim': ['exim.conf'],
163    \ 'expect': ['file.exp'],
164    \ 'exports': ['exports'],
165    \ 'factor': ['file.factor'],
166    \ 'falcon': ['file.fal'],
167    \ 'fan': ['file.fan', 'file.fwt'],
168    \ 'fetchmail': ['.fetchmailrc'],
169    \ 'fgl': ['file.4gl', 'file.4gh', 'file.m4gl'],
170    \ 'focexec': ['file.fex', 'file.focexec'],
171    \ 'forth': ['file.fs', 'file.ft', 'file.fth'],
172    \ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'],
173    \ 'framescript': ['file.fsl'],
174    \ 'freebasic': ['file.fb', 'file.bi'],
175    \ 'fstab': ['fstab', 'mtab'],
176    \ 'gdb': ['.gdbinit'],
177    \ 'gdmo': ['file.mo', 'file.gdmo'],
178    \ 'gedcom': ['file.ged', 'lltxxxxx.txt'],
179    \ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG'],
180    \ 'gitconfig': ['file.git/config', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig'],
181    \ 'gitolite': ['gitolite.conf'],
182    \ 'gitrebase': ['git-rebase-todo'],
183    \ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'],
184    \ 'gkrellmrc': ['gkrellmrc', 'gkrellmrc_x'],
185    \ 'gnash': ['gnashrc', '.gnashrc', 'gnashpluginrc', '.gnashpluginrc'],
186    \ 'gnuplot': ['file.gpi'],
187    \ 'go': ['file.go'],
188    \ 'gp': ['file.gp', '.gprc'],
189    \ 'gpg': ['/.gnupg/options', '/.gnupg/gpg.conf', '/usr/any/gnupg/options.skel'],
190    \ 'grads': ['file.gs'],
191    \ 'gretl': ['file.gretl'],
192    \ 'groovy': ['file.gradle', 'file.groovy'],
193    \ 'group': ['any/etc/group', 'any/etc/group-', 'any/etc/group.edit', 'any/etc/gshadow', 'any/etc/gshadow-', 'any/etc/gshadow.edit', 'any/var/backups/group.bak', 'any/var/backups/gshadow.bak'],
194    \ 'grub': ['/boot/grub/menu.lst', '/boot/grub/grub.conf', '/etc/grub.conf'],
195    \ 'gsp': ['file.gsp'],
196    \ 'gtkrc': ['.gtkrc', 'gtkrc'],
197    \ 'haml': ['file.haml'],
198    \ 'hamster': ['file.hsc', 'file.hsm'],
199    \ 'haskell': ['file.hs', 'file.hs-boot'],
200    \ 'haste': ['file.ht'],
201    \ 'hastepreproc': ['file.htpp'],
202    \ 'hb': ['file.hb'],
203    \ 'hercules': ['file.vc', 'file.ev', 'file.sum', 'file.errsum'],
204    \ 'hex': ['file.hex', 'file.h32'],
205    \ 'hgcommit': ['hg-editor-file.txt'],
206    \ 'hog': ['file.hog', 'snort.conf', 'vision.conf'],
207    \ 'hollywood': ['file.hws'],
208    \ 'hostconf': ['/etc/host.conf'],
209    \ 'hostsaccess': ['/etc/hosts.allow', '/etc/hosts.deny'],
210    \ 'template': ['file.tmpl'],
211    \ 'htmlm4': ['file.html.m4'],
212    \ 'httest': ['file.htt', 'file.htb'],
213    \ 'ibasic': ['file.iba', 'file.ibi'],
214    \ 'icemenu': ['/.icewm/menu'],
215    \ 'icon': ['file.icn'],
216    \ 'indent': ['.indent.pro', 'indentrc'],
217    \ 'inform': ['file.inf', 'file.INF'],
218    \ 'initng': ['/etc/initng/any/file.i', 'file.ii'],
219    \ 'inittab': ['inittab'],
220    \ 'ipfilter': ['ipf.conf', 'ipf6.conf', 'ipf.rules'],
221    \ 'iss': ['file.iss'],
222    \ 'ist': ['file.ist', 'file.mst'],
223    \ 'j': ['file.ijs'],
224    \ 'jal': ['file.jal', 'file.JAL'],
225    \ 'jam': ['file.jpl', 'file.jpr'],
226    \ 'java': ['file.java', 'file.jav'],
227    \ 'javacc': ['file.jj', 'file.jjt'],
228    \ 'javascript': ['file.js', 'file.javascript', 'file.es', 'file.mjs', 'file.cjs'],
229    \ 'javascriptreact': ['file.jsx'],
230    \ 'jess': ['file.clp'],
231    \ 'jgraph': ['file.jgr'],
232    \ 'jovial': ['file.jov', 'file.j73', 'file.jovial'],
233    \ 'jproperties': ['file.properties', 'file.properties_xx', 'file.properties_xx_xx'],
234    \ 'json': ['file.json', 'file.jsonp', 'file.webmanifest', 'Pipfile.lock'],
235    \ 'jsp': ['file.jsp'],
236    \ 'kconfig': ['Kconfig', 'Kconfig.debug'],
237    \ 'kivy': ['file.kv'],
238    \ 'kix': ['file.kix'],
239    \ 'kotlin': ['file.kt', 'file.ktm', 'file.kts'],
240    \ 'kscript': ['file.ks'],
241    \ 'kwt': ['file.k'],
242    \ 'lace': ['file.ace', 'file.ACE'],
243    \ 'latte': ['file.latte', 'file.lte'],
244    \ 'ld': ['file.ld'],
245    \ 'ldif': ['file.ldif'],
246    \ 'less': ['file.less'],
247    \ 'lex': ['file.lex', 'file.l', 'file.lxx', 'file.l++'],
248    \ 'lftp': ['lftp.conf', '.lftprc', 'anylftp/rc'],
249    \ 'lhaskell': ['file.lhs'],
250    \ 'libao': ['/etc/libao.conf', '/.libao'],
251    \ 'lifelines': ['file.ll'],
252    \ 'lilo': ['lilo.conf'],
253    \ 'limits': ['/etc/limits', '/etc/anylimits.conf', '/etc/anylimits.d/file.conf'],
254    \ 'liquid': ['file.liquid'],
255    \ 'lisp': ['file.lsp', 'file.lisp', 'file.el', 'file.cl', '.emacs', '.sawfishrc', 'sbclrc', '.sbclrc'],
256    \ 'lite': ['file.lite', 'file.lt'],
257    \ 'litestep': ['/LiteStep/any/file.rc'],
258    \ 'loginaccess': ['/etc/login.access'],
259    \ 'logindefs': ['/etc/login.defs'],
260    \ 'logtalk': ['file.lgt'],
261    \ 'lotos': ['file.lot', 'file.lotos'],
262    \ 'lout': ['file.lou', 'file.lout'],
263    \ 'lprolog': ['file.sig'],
264    \ 'lsl': ['file.lsl'],
265    \ 'lss': ['file.lss'],
266    \ 'lua': ['file.lua', 'file.rockspec', 'file.nse'],
267    \ 'lynx': ['lynx.cfg'],
268    \ 'm4': ['file.at'],
269    \ 'mail': ['snd.123', '.letter', '.letter.123', '.followup', '.article', '.article.123', 'pico.123', 'mutt-xx-xxx', 'muttng-xx-xxx', 'ae123.txt', 'file.eml'],
270    \ 'mailaliases': ['/etc/mail/aliases', '/etc/aliases'],
271    \ 'mailcap': ['.mailcap', 'mailcap'],
272    \ 'make': ['file.mk', 'file.mak', 'file.dsp'],
273    \ 'mallard': ['file.page'],
274    \ 'man': ['file.man'],
275    \ 'manconf': ['/etc/man.conf', 'man.config'],
276    \ 'map': ['file.map'],
277    \ 'maple': ['file.mv', 'file.mpl', 'file.mws'],
278    \ 'markdown': ['file.markdown', 'file.mdown', 'file.mkd', 'file.mkdn', 'file.mdwn', 'file.md'],
279    \ 'mason': ['file.mason', 'file.mhtml', 'file.comp'],
280    \ 'master': ['file.mas', 'file.master'],
281    \ 'mel': ['file.mel'],
282    \ 'meson': ['meson.build', 'meson_options.txt'],
283    \ 'messages': ['/log/auth', '/log/cron', '/log/daemon', '/log/debug', '/log/kern', '/log/lpr', '/log/mail', '/log/messages', '/log/news/news', '/log/syslog', '/log/user',
284    \     '/log/auth.log', '/log/cron.log', '/log/daemon.log', '/log/debug.log', '/log/kern.log', '/log/lpr.log', '/log/mail.log', '/log/messages.log', '/log/news/news.log', '/log/syslog.log', '/log/user.log',
285    \     '/log/auth.err', '/log/cron.err', '/log/daemon.err', '/log/debug.err', '/log/kern.err', '/log/lpr.err', '/log/mail.err', '/log/messages.err', '/log/news/news.err', '/log/syslog.err', '/log/user.err',
286    \      '/log/auth.info', '/log/cron.info', '/log/daemon.info', '/log/debug.info', '/log/kern.info', '/log/lpr.info', '/log/mail.info', '/log/messages.info', '/log/news/news.info', '/log/syslog.info', '/log/user.info',
287    \      '/log/auth.warn', '/log/cron.warn', '/log/daemon.warn', '/log/debug.warn', '/log/kern.warn', '/log/lpr.warn', '/log/mail.warn', '/log/messages.warn', '/log/news/news.warn', '/log/syslog.warn', '/log/user.warn',
288    \      '/log/auth.crit', '/log/cron.crit', '/log/daemon.crit', '/log/debug.crit', '/log/kern.crit', '/log/lpr.crit', '/log/mail.crit', '/log/messages.crit', '/log/news/news.crit', '/log/syslog.crit', '/log/user.crit',
289    \      '/log/auth.notice', '/log/cron.notice', '/log/daemon.notice', '/log/debug.notice', '/log/kern.notice', '/log/lpr.notice', '/log/mail.notice', '/log/messages.notice', '/log/news/news.notice', '/log/syslog.notice', '/log/user.notice'],
290    \ 'mf': ['file.mf'],
291    \ 'mgl': ['file.mgl'],
292    \ 'mgp': ['file.mgp'],
293    \ 'mib': ['file.mib', 'file.my'],
294    \ 'mix': ['file.mix', 'file.mixal'],
295    \ 'mma': ['file.nb'],
296    \ 'mmp': ['file.mmp'],
297    \ 'modconf': ['/etc/modules.conf', '/etc/modules', '/etc/conf.modules'],
298    \ 'modula2': ['file.m2', 'file.mi'],
299    \ 'monk': ['file.isc', 'file.monk', 'file.ssc', 'file.tsc'],
300    \ 'moo': ['file.moo'],
301    \ 'mp': ['file.mp'],
302    \ 'mplayerconf': ['mplayer.conf', '/.mplayer/config'],
303    \ 'mrxvtrc': ['mrxvtrc', '.mrxvtrc'],
304    \ 'msidl': ['file.odl', 'file.mof'],
305    \ 'msql': ['file.msql'],
306    \ 'mupad': ['file.mu'],
307    \ 'mush': ['file.mush'],
308    \ 'muttrc': ['Muttngrc', 'Muttrc'],
309    \ 'mysql': ['file.mysql'],
310    \ 'n1ql': ['file.n1ql', 'file.nql'],
311    \ 'named': ['namedfile.conf', 'rndcfile.conf'],
312    \ 'nanorc': ['/etc/nanorc', 'file.nanorc'],
313    \ 'ncf': ['file.ncf'],
314    \ 'netrc': ['.netrc'],
315    \ 'ninja': ['file.ninja'],
316    \ 'nqc': ['file.nqc'],
317    \ 'nroff': ['file.tr', 'file.nr', 'file.roff', 'file.tmac', 'file.mom'],
318    \ 'nsis': ['file.nsi', 'file.nsh'],
319    \ 'obj': ['file.obj'],
320    \ 'ocaml': ['file.ml', 'file.mli', 'file.mll', 'file.mly', '.ocamlinit'],
321    \ 'occam': ['file.occ'],
322    \ 'omnimark': ['file.xom', 'file.xin'],
323    \ 'openroad': ['file.or'],
324    \ 'ora': ['file.ora'],
325    \ 'pamconf': ['/etc/pam.conf'],
326    \ 'pamenv': ['/etc/security/pam_env.conf', '/home/user/.pam_environment'],
327    \ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'],
328    \ 'pascal': ['file.pas', 'file.dpr'],
329    \ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak'],
330    \ 'pccts': ['file.g'],
331    \ 'pdf': ['file.pdf'],
332    \ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc'],
333    \ 'perl6': ['file.p6', 'file.pm6', 'file.pl6', 'file.raku', 'file.rakumod'],
334    \ 'pf': ['pf.conf'],
335    \ 'pfmain': ['main.cf'],
336    \ 'php': ['file.php', 'file.php9', 'file.phtml', 'file.ctp'],
337    \ 'lpc': ['file.lpc', 'file.ulpc'],
338    \ 'pike': ['file.pike', 'file.pmod'],
339    \ 'cmod': ['file.cmod'],
340    \ 'pilrc': ['file.rcp'],
341    \ 'pine': ['.pinerc', 'pinerc', '.pinercex', 'pinercex'],
342    \ 'pinfo': ['/etc/pinforc', '/.pinforc'],
343    \ 'pli': ['file.pli', 'file.pl1'],
344    \ 'plm': ['file.plm', 'file.p36', 'file.pac'],
345    \ 'plp': ['file.plp'],
346    \ 'plsql': ['file.pls', 'file.plsql'],
347    \ 'po': ['file.po', 'file.pot'],
348    \ 'pod': ['file.pod'],
349    \ 'pod6': ['file.pod6'],
350    \ 'postscr': ['file.ps', 'file.pfa', 'file.afm', 'file.eps', 'file.epsf', 'file.epsi', 'file.ai'],
351    \ 'pov': ['file.pov'],
352    \ 'povini': ['.povrayrc'],
353    \ 'ppd': ['file.ppd'],
354    \ 'ppwiz': ['file.it', 'file.ih'],
355    \ 'privoxy': ['file.action'],
356    \ 'proc': ['file.pc'],
357    \ 'procmail': ['.procmail', '.procmailrc'],
358    \ 'prolog': ['file.pdb'],
359    \ 'promela': ['file.pml'],
360    \ 'proto': ['file.proto'],
361    \ 'protocols': ['/etc/protocols'],
362    \ 'psf': ['file.psf'],
363    \ 'pyrex': ['file.pyx', 'file.pxd'],
364    \ 'python': ['file.py', 'file.pyw', '.pythonstartup', '.pythonrc', 'file.ptl', 'file.pyi', 'SConstruct'],
365    \ 'quake': ['anybaseq2/file.cfg', 'anyid1/file.cfg', 'quake3/file.cfg'],
366    \ 'radiance': ['file.rad', 'file.mat'],
367    \ 'ratpoison': ['.ratpoisonrc', 'ratpoisonrc'],
368    \ 'rc': ['file.rc', 'file.rch'],
369    \ 'rcs': ['file,v'],
370    \ 'readline': ['.inputrc', 'inputrc'],
371    \ 'remind': ['.reminders', 'file.remind', 'file.rem'],
372    \ 'rego': ['file.rego'],
373    \ 'resolv': ['resolv.conf'],
374    \ 'reva': ['file.frt'],
375    \ 'rexx': ['file.rex', 'file.orx', 'file.rxo', 'file.rxj', 'file.jrexx', 'file.rexxj', 'file.rexx', 'file.testGroup', 'file.testUnit'],
376    \ 'rib': ['file.rib'],
377    \ 'rnc': ['file.rnc'],
378    \ 'rng': ['file.rng'],
379    \ 'robots': ['robots.txt'],
380    \ 'rpcgen': ['file.x'],
381    \ 'rpl': ['file.rpl'],
382    \ 'rst': ['file.rst'],
383    \ 'rtf': ['file.rtf'],
384    \ 'ruby': ['.irbrc', 'irbrc', 'file.rb', 'file.rbw', 'file.gemspec', 'file.ru', 'Gemfile', 'file.builder', 'file.rxml', 'file.rjs', 'file.rant', 'file.rake'],
385    \ 'rust': ['file.rs'],
386    \ 'samba': ['smb.conf'],
387    \ 'sas': ['file.sas'],
388    \ 'sass': ['file.sass'],
389    \ 'sather': ['file.sa'],
390    \ 'sbt': ['file.sbt'],
391    \ 'scala': ['file.scala'],
392    \ 'scheme': ['file.scm', 'file.ss', 'file.rkt'],
393    \ 'scilab': ['file.sci', 'file.sce'],
394    \ 'screen': ['.screenrc', 'screenrc'],
395    \ 'scss': ['file.scss'],
396    \ 'sd': ['file.sd'],
397    \ 'sdc': ['file.sdc'],
398    \ 'sdl': ['file.sdl', 'file.pr'],
399    \ 'sed': ['file.sed'],
400    \ 'sensors': ['/etc/sensors.conf', '/etc/sensors3.conf'],
401    \ 'services': ['/etc/services'],
402    \ 'setserial': ['/etc/serial.conf'],
403    \ 'sh': ['/etc/udev/cdsymlinks.conf'],
404    \ 'sieve': ['file.siv', 'file.sieve'],
405    \ 'simula': ['file.sim'],
406    \ 'sinda': ['file.sin', 'file.s85'],
407    \ 'sisu': ['file.sst', 'file.ssm', 'file.ssi', 'file.-sst', 'file._sst', 'file.sst.meta', 'file.-sst.meta', 'file._sst.meta'],
408    \ 'skill': ['file.il', 'file.ils', 'file.cdf'],
409    \ 'slang': ['file.sl'],
410    \ 'slice': ['file.ice'],
411    \ 'slpconf': ['/etc/slp.conf'],
412    \ 'slpreg': ['/etc/slp.reg'],
413    \ 'slpspi': ['/etc/slp.spi'],
414    \ 'slrnrc': ['.slrnrc'],
415    \ 'slrnsc': ['file.score'],
416    \ 'sm': ['sendmail.cf'],
417    \ 'smarty': ['file.tpl'],
418    \ 'smcl': ['file.hlp', 'file.ihlp', 'file.smcl'],
419    \ 'smith': ['file.smt', 'file.smith'],
420    \ 'sml': ['file.sml'],
421    \ 'snobol4': ['file.sno', 'file.spt'],
422    \ 'spec': ['file.spec'],
423    \ 'spice': ['file.sp', 'file.spice'],
424    \ 'spup': ['file.speedup', 'file.spdata', 'file.spd'],
425    \ 'spyce': ['file.spy', 'file.spi'],
426    \ 'sql': ['file.tyb', 'file.typ', 'file.tyc', 'file.pkb', 'file.pks'],
427    \ 'sqlj': ['file.sqlj'],
428    \ 'sqr': ['file.sqr', 'file.sqi'],
429    \ 'squid': ['squid.conf'],
430    \ 'srec': ['file.s19', 'file.s28', 'file.s37', 'file.mot', 'file.srec'],
431    \ 'sshconfig': ['ssh_config', '/.ssh/config', '/etc/ssh/ssh_config.d/file.conf', 'any/etc/ssh/ssh_config.d/file.conf'],
432    \ 'sshdconfig': ['sshd_config', '/etc/ssh/sshd_config.d/file.conf', 'any/etc/ssh/sshd_config.d/file.conf'],
433    \ 'st': ['file.st'],
434    \ 'stata': ['file.ado', 'file.do', 'file.imata', 'file.mata'],
435    \ 'stp': ['file.stp'],
436    \ 'sudoers': ['any/etc/sudoers', 'sudoers.tmp'],
437    \ 'svg': ['file.svg'],
438    \ 'svn': ['svn-commitfile.tmp'],
439    \ 'swift': ['file.swift'],
440    \ 'swiftgyb': ['file.swift.gyb'],
441    \ 'sil': ['file.sil'],
442    \ 'sysctl': ['/etc/sysctl.conf', '/etc/sysctl.d/file.conf'],
443    \ 'systemd': ['any/systemd/file.automount', 'any/systemd/file.mount', 'any/systemd/file.path', 'any/systemd/file.service', 'any/systemd/file.socket', 'any/systemd/file.swap', 'any/systemd/file.target', 'any/systemd/file.timer', '/etc/systemd/system/some.d/file.conf', '/etc/systemd/system/some.d/.#file', '/etc/systemd/system/.#otherfile', '/home/user/.config/systemd/user/some.d/mine.conf', '/home/user/.config/systemd/user/some.d/.#file', '/home/user/.config/systemd/user/.#otherfile'],
444    \ 'systemverilog': ['file.sv', 'file.svh'],
445    \ 'tags': ['tags'],
446    \ 'tak': ['file.tak'],
447    \ 'taskdata': ['pending.data', 'completed.data', 'undo.data'],
448    \ 'taskedit': ['file.task'],
449    \ 'tcl': ['file.tcl', 'file.tk', 'file.itcl', 'file.itk', 'file.jacl'],
450    \ 'teraterm': ['file.ttl'],
451    \ 'terminfo': ['file.ti'],
452    \ 'tex': ['file.latex', 'file.sty', 'file.dtx', 'file.ltx', 'file.bbl'],
453    \ 'texinfo': ['file.texinfo', 'file.texi', 'file.txi'],
454    \ 'texmf': ['texmf.cnf'],
455    \ 'text': ['file.text', 'README'],
456    \ 'tf': ['file.tf', '.tfrc', 'tfrc'],
457    \ 'tidy': ['.tidyrc', 'tidyrc'],
458    \ 'tilde': ['file.t.html'],
459    \ 'tli': ['file.tli'],
460    \ 'tmux': ['tmuxfile.conf', '.tmuxfile.conf'],
461    \ 'tpp': ['file.tpp'],
462    \ 'treetop': ['file.treetop'],
463    \ 'trustees': ['trustees.conf'],
464    \ 'tsalt': ['file.slt'],
465    \ 'tsscl': ['file.tsscl'],
466    \ 'tssgm': ['file.tssgm'],
467    \ 'tssop': ['file.tssop'],
468    \ 'twig': ['file.twig'],
469    \ 'typescript': ['file.ts'],
470    \ 'typescriptreact': ['file.tsx'],
471    \ 'uc': ['file.uc'],
472    \ 'udevconf': ['/etc/udev/udev.conf'],
473    \ 'udevperm': ['/etc/udev/permissions.d/file.permissions'],
474    \ 'uil': ['file.uit', 'file.uil'],
475    \ 'updatedb': ['/etc/updatedb.conf'],
476    \ 'upstart': ['/usr/share/upstart/file.conf', '/usr/share/upstart/file.override', '/etc/init/file.conf', '/etc/init/file.override', '/.init/file.conf', '/.init/file.override', '/.config/upstart/file.conf', '/.config/upstart/file.override'],
477    \ 'upstreamdat': ['upstream.dat', 'UPSTREAM.DAT', 'upstream.file.dat', 'UPSTREAM.FILE.DAT', 'file.upstream.dat', 'FILE.UPSTREAM.DAT'],
478    \ 'upstreaminstalllog': ['upstreaminstall.log', 'UPSTREAMINSTALL.LOG', 'upstreaminstall.file.log', 'UPSTREAMINSTALL.FILE.LOG', 'file.upstreaminstall.log', 'FILE.UPSTREAMINSTALL.LOG'],
479    \ 'upstreamlog': ['fdrupstream.log', 'upstream.log', 'UPSTREAM.LOG', 'upstream.file.log', 'UPSTREAM.FILE.LOG', 'file.upstream.log', 'FILE.UPSTREAM.LOG', 'UPSTREAM-file.log', 'UPSTREAM-FILE.LOG'],
480    \ 'usserverlog': ['usserver.log', 'USSERVER.LOG', 'usserver.file.log', 'USSERVER.FILE.LOG', 'file.usserver.log', 'FILE.USSERVER.LOG'],
481    \ 'usw2kagtlog': ['usw2kagt.log', 'USW2KAGT.LOG', 'usw2kagt.file.log', 'USW2KAGT.FILE.LOG', 'file.usw2kagt.log', 'FILE.USW2KAGT.LOG'],
482    \ 'vb': ['file.sba', 'file.vb', 'file.vbs', 'file.dsm', 'file.ctl'],
483    \ 'vera': ['file.vr', 'file.vri', 'file.vrh'],
484    \ 'verilog': ['file.v'],
485    \ 'verilogams': ['file.va', 'file.vams'],
486    \ 'vgrindefs': ['vgrindefs'],
487    \ 'vhdl': ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst', 'file.vhdl_123', 'file.vho'],
488    \ 'vim': ['file.vim', 'file.vba', '.exrc', '_exrc'],
489    \ 'viminfo': ['.viminfo', '_viminfo'],
490    \ 'vmasm': ['file.mar'],
491    \ 'voscm': ['file.cm'],
492    \ 'vrml': ['file.wrl'],
493    \ 'vroom': ['file.vroom'],
494    \ 'vue': ['file.vue'],
495    \ 'wast': ['file.wast', 'file.wat'],
496    \ 'webmacro': ['file.wm'],
497    \ 'wget': ['.wgetrc', 'wgetrc'],
498    \ 'winbatch': ['file.wbt'],
499    \ 'wml': ['file.wml'],
500    \ 'wsml': ['file.wsml'],
501    \ 'wvdial': ['wvdial.conf', '.wvdialrc'],
502    \ 'xdefaults': ['.Xdefaults', '.Xpdefaults', '.Xresources', 'xdm-config', 'file.ad'],
503    \ 'xhtml': ['file.xhtml', 'file.xht'],
504    \ 'xinetd': ['/etc/xinetd.conf'],
505    \ 'xmath': ['file.msc', 'file.msf'],
506    \ 'xml': ['/etc/blkid.tab', '/etc/blkid.tab.old', 'file.xmi', 'file.csproj', 'file.csproj.user', 'file.ui', 'file.tpm', '/etc/xdg/menus/file.menu', 'fglrxrc', 'file.xlf', 'file.xliff', 'file.xul', 'file.wsdl'],
507    \ 'xmodmap': ['anyXmodmap'],
508    \ 'xf86conf': ['xorg.conf', 'xorg.conf-4'],
509    \ 'xpm2': ['file.xpm2'],
510    \ 'xquery': ['file.xq', 'file.xql', 'file.xqm', 'file.xquery', 'file.xqy'],
511    \ 'xs': ['file.xs'],
512    \ 'xsd': ['file.xsd'],
513    \ 'xslt': ['file.xsl', 'file.xslt'],
514    \ 'yacc': ['file.yy', 'file.yxx', 'file.y++'],
515    \ 'yaml': ['file.yaml', 'file.yml'],
516    \ 'raml': ['file.raml'],
517    \ 'z8a': ['file.z8a'],
518    \ 'zimbu': ['file.zu'],
519    \ 'zimbutempl': ['file.zut'],
520    \ 'zsh': ['.zprofile', '/etc/zprofile', '.zfbfmarks', 'file.zsh'],
521    \
522    \ 'help': [$VIMRUNTIME . '/doc/help.txt'],
523    \ 'xpm': ['file.xpm'],
524    \ }
525
526let s:filename_case_checks = {
527    \ 'modula2': ['file.DEF', 'file.MOD'],
528    \ }
529
530func CheckItems(checks)
531  for [ft, names] in items(a:checks)
532    for i in range(0, len(names) - 1)
533      new
534      try
535        exe 'edit ' . fnameescape(names[i])
536      catch
537	call assert_report('cannot edit "' . names[i] . '": ' . v:exception)
538      endtry
539      if &filetype == '' && &readonly
540	" File exists but not able to edit it (permission denied)
541      else
542	call assert_equal(ft, &filetype, 'with file name: ' . names[i])
543      endif
544      bwipe!
545    endfor
546  endfor
547endfunc
548
549func Test_filetype_detection()
550  filetype on
551  call CheckItems(s:filename_checks)
552  if has('fname_case')
553    call CheckItems(s:filename_case_checks)
554  endif
555  filetype off
556endfunc
557
558" Filetypes detected from the file contents by scripts.vim
559let s:script_checks = {
560      \ 'virata': [['% Virata'],
561      \		['', '% Virata'],
562      \		['', '', '% Virata'],
563      \		['', '', '', '% Virata'],
564      \		['', '', '', '', '% Virata']],
565      \ 'strace': [['execve("/usr/bin/pstree", ["pstree"], 0x7ff0 /* 63 vars */) = 0'],
566      \		['15:17:47 execve("/usr/bin/pstree", ["pstree"], ... "_=/usr/bin/strace"]) = 0'],
567      \		['__libc_start_main and something']],
568      \ 'clojure': [['#!/path/clojure']],
569      \ 'scala': [['#!/path/scala']],
570      \ 'tcsh': [['#!/path/tcsh']],
571      \ 'zsh': [['#!/path/zsh']],
572      \ 'tcl': [['#!/path/tclsh'],
573      \         ['#!/path/wish'],
574      \         ['#!/path/expectk'],
575      \         ['#!/path/itclsh'],
576      \         ['#!/path/itkwish']],
577      \ 'expect': [['#!/path/expect']],
578      \ 'gnuplot': [['#!/path/gnuplot']],
579      \ 'make': [['#!/path/make']],
580      \ 'pike': [['#!/path/pike'],
581      \          ['#!/path/pike0'],
582      \          ['#!/path/pike9']],
583      \ 'lua': [['#!/path/lua']],
584      \ 'perl6': [['#!/path/perl6']],
585      \ 'perl': [['#!/path/perl']],
586      \ 'php': [['#!/path/php']],
587      \ 'python': [['#!/path/python'],
588      \            ['#!/path/python2'],
589      \            ['#!/path/python3']],
590      \ 'groovy': [['#!/path/groovy']],
591      \ 'ruby': [['#!/path/ruby']],
592      \ 'javascript': [['#!/path/node'],
593      \                ['#!/path/js'],
594      \                ['#!/path/nodejs'],
595      \                ['#!/path/rhino']],
596      \ 'bc': [['#!/path/bc']],
597      \ 'sed': [['#!/path/sed']],
598      \ 'ocaml': [['#!/path/ocaml']],
599      \ 'awk': [['#!/path/awk']],
600      \ 'wml': [['#!/path/wml']],
601      \ 'scheme': [['#!/path/scheme']],
602      \ 'cfengine': [['#!/path/cfengine']],
603      \ 'erlang': [['#!/path/escript']],
604      \ 'haskell': [['#!/path/haskell']],
605      \ 'cpp': [['// Standard iostream objects -*- C++ -*-'],
606      \         ['// -*- C++ -*-']],
607      \ 'yaml': [['%YAML 1.2']],
608      \ }
609
610" Various forms of "env" optional arguments.
611let s:script_env_checks = {
612      \ 'perl': [['#!/usr/bin/env VAR=val perl']],
613      \ 'scala': [['#!/usr/bin/env VAR=val VVAR=vval scala']],
614      \ 'awk': [['#!/usr/bin/env VAR=val -i awk']],
615      \ 'scheme': [['#!/usr/bin/env VAR=val --ignore-environment scheme']],
616      \ 'python': [['#!/usr/bin/env VAR=val -S python -w -T']],
617      \ 'wml': [['#!/usr/bin/env VAR=val --split-string wml']],
618      \ }
619
620func Run_script_detection(test_dict)
621  filetype on
622  for [ft, files] in items(a:test_dict)
623    for file in files
624      call writefile(file, 'Xtest')
625      split Xtest
626      call assert_equal(ft, &filetype, 'for text: ' . string(file))
627      bwipe!
628    endfor
629  endfor
630  call delete('Xtest')
631  filetype off
632endfunc
633
634func Test_script_detection()
635  call Run_script_detection(s:script_checks)
636  call Run_script_detection(s:script_env_checks)
637endfunc
638
639func Test_setfiletype_completion()
640  call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx')
641  call assert_equal('"setfiletype java javacc javascript javascriptreact', @:)
642endfunc
643
644" Test for ':filetype detect' command for a buffer without a file
645func Test_emptybuf_ftdetect()
646  new
647  call setline(1, '#!/bin/sh')
648  call assert_equal('', &filetype)
649  filetype detect
650  call assert_equal('sh', &filetype)
651  close!
652endfunc
653
654" Test for ':filetype indent on' and ':filetype indent off' commands
655func Test_filetype_indent_off()
656  new Xtest.vim
657  filetype indent on
658  call assert_equal(1, g:did_indent_on)
659  call assert_equal(['filetype detection:ON  plugin:OFF  indent:ON'],
660        \ execute('filetype')->split("\n"))
661  filetype indent off
662  call assert_equal(0, exists('g:did_indent_on'))
663  call assert_equal(['filetype detection:ON  plugin:OFF  indent:OFF'],
664        \ execute('filetype')->split("\n"))
665  close
666endfunc
667
668" vim: shiftwidth=2 sts=2 expandtab
669