robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Tests for filetype-plugin behavior (files in runtime/ftplugin/*). 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5 6local describe , it , before_each , setup , teardown = 7t . describe , t . it , t . before_each , t . setup , t . teardown 8local exec_lua =n . exec_lua 9local command =n . command 10local eq =t . eq 11 12---@param type string 13---@return string 14local function stdpath ( type ) 15return exec_lua ( [[return vim.fs.abspath(vim.fn.stdpath(...))]] , type ) 16end 17 18---@return string 19local function vimruntime () 20return exec_lua [[ return vim.fs.abspath(vim.env.VIMRUNTIME) ]] 21end 22 23---@param module string 24---@return string 25local function lua_includeexpr ( module ) 26return exec_lua ( [[return vim.fs.abspath(require 'vim._ftplugin.lua'.includeexpr(...))]] , module ) 27end 28 29describe ( "ftplugin: Lua 'includeexpr'" , function () 30local repo_root =vim . fs . normalize ( t . paths . test_source_path ) 31local temp_dir ='' 32 33setup ( function () 34temp_dir =t . tmpname ( false ) 35n . clear () 36n . api . nvim_set_current_dir ( repo_root ) 37end ) 38 39teardown ( function () 40n . expect_exit ( n . command , 'qall!' ) 41n . rmdir ( repo_root .. '/runtime/lua/foo/' ) 42end ) 43 44before_each ( function () 45command (( [[ 46edit `=stdpath('config') .. '/lua/user-foo/init.lua'` 47write ++p 48edit `=stdpath('config') .. '/lua/user-foo/bar.lua'` 49write ++p 50edit `=stdpath('data') .. '/site/pack/packer/start/plugin-foo/lua/plugin-foo/init.lua'` 51write ++p 52edit `=stdpath('data') .. '/site/pack/packer/start/plugin-foo/lua/plugin-foo/bar.lua'` 53write ++p 54 55edit runtime/lua/foo/init.lua 56write ++p 57edit runtime/lua/foo/bar/init.lua 58write ++p 59 60edit %s/lua/runtime-foo/init.lua 61write ++p 62edit %s/lua/runtime-foo/bar.lua 63write ++p 64 65edit %s/general-foo/bar/init.lua 66write ++p 67edit %s/general-foo/bar/baz.lua 68write ++p 69]] ): format ( temp_dir , temp_dir , temp_dir , temp_dir )) 70end ) 71 72it ( 'finds module in current repo' , function () 73command [[ edit runtime/lua/vim/_ftplugin/lua.lua ]] 74eq ( repo_root .. '/runtime/lua/vim/_ftplugin/lua.lua' , lua_includeexpr ( 'vim._ftplugin.lua' )) 75eq ( repo_root .. '/runtime/lua/editorconfig.lua' , lua_includeexpr ( 'editorconfig' )) 76eq ( repo_root .. '/runtime/lua/foo/init.lua' , lua_includeexpr ( 'foo' )) 77eq ( repo_root .. '/runtime/lua/foo/bar/init.lua' , lua_includeexpr ( 'foo.bar' )) 78end ) 79 80it ( 'finds module in packpath/start' , function () 81eq ( 82stdpath ( 'data' ) .. '/site/pack/packer/start/plugin-foo/lua/plugin-foo/init.lua' , 83lua_includeexpr ( 'plugin-foo' ) 84) 85eq ( 86stdpath ( 'data' ) .. '/site/pack/packer/start/plugin-foo/lua/plugin-foo/bar.lua' , 87lua_includeexpr ( 'plugin-foo.bar' ) 88) 89end ) 90 91it ( 'finds module in $VIMRUNTIME' , function () 92command ( 'edit ' .. repo_root ) 93eq ( vimruntime () .. '/lua/vim/_ftplugin/lua.lua' , lua_includeexpr ( 'vim._ftplugin.lua' )) 94eq ( vimruntime () .. '/lua/editorconfig.lua' , lua_includeexpr ( 'editorconfig' )) 95end ) 96 97it ( 'finds module in runtimepath' , function () 98eq ( stdpath ( 'config' ) .. '/lua/user-foo/init.lua' , lua_includeexpr ( 'user-foo' )) 99eq ( stdpath ( 'config' ) .. '/lua/user-foo/bar.lua' , lua_includeexpr ( 'user-foo.bar' )) 100command ( 'set rtp+=' .. temp_dir ) 101eq ( temp_dir .. '/lua/runtime-foo/init.lua' , lua_includeexpr ( 'runtime-foo' )) 102eq ( temp_dir .. '/lua/runtime-foo/bar.lua' , lua_includeexpr ( 'runtime-foo.bar' )) 103end ) 104 105it ( 'non-Nvim-style Lua modules' , function () 106command ( 'cd ' .. temp_dir ) 107eq ( temp_dir .. '/general-foo/bar/init.lua' , lua_includeexpr ( 'general-foo.bar' )) 108eq ( temp_dir .. '/general-foo/bar/baz.lua' , lua_includeexpr ( 'general-foo.bar.baz' )) 109command ( 'cd -' ) 110end ) 111end )