aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
authorJonas Strittmatter <40792180+smjonas@users.noreply.github.com>2023-02-14 00:04:16 +0100
committerGitHub <noreply@github.com>2023-02-13 16:04:16 -0700
commitb518aceaa8f738e581e58aacae93514699b5ff8e (patch)
treeecf570a92d612d10fc3b442cd1f0c7af7c30ceb5 /test/functional/lua
parent1d6bb0892b58e5a4183e74c0fbd2dc20204e33a4 (diff)
downloadrneovim-b518aceaa8f738e581e58aacae93514699b5ff8e.tar.gz
rneovim-b518aceaa8f738e581e58aacae93514699b5ff8e.tar.bz2
rneovim-b518aceaa8f738e581e58aacae93514699b5ff8e.zip
feat(filetype): fall back to file extension when matching from hashbang (#22140)
If nothing matched in match_from_hashbang, also check the file extension table. For a hashbang like '#!/bin/env foo', this will set the filetype to 'fooscript' assuming the filetype for the 'foo' extension is 'fooscript' in the extension table.
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/filetype_spec.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua
index 034665f717..add69235b6 100644
--- a/test/functional/lua/filetype_spec.lua
+++ b/test/functional/lua/filetype_spec.lua
@@ -98,10 +98,22 @@ describe('vim.filetype', function()
it('works with contents #22180', function()
eq('sh', exec_lua [[
-- Needs to be set so detect#sh doesn't fail
- vim.g.ft_ignore_pat = "\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$"
+ vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'
return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } })
]])
end)
+
+ it('considers extension mappings when matching from hashbang', function()
+ eq('fooscript', exec_lua [[
+ vim.filetype.add({
+ extension = {
+ foo = 'fooscript',
+ }
+ })
+ return vim.filetype.match({ contents = { '#!/usr/bin/env foo' } })
+ ]])
+ end)
+
end)
describe('filetype.lua', function()