2021-06-01 20:32:37 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
local clear = helpers.clear
|
|
|
|
local eq = helpers.eq
|
|
|
|
local eval = helpers.eval
|
|
|
|
local exec = helpers.exec
|
2023-01-21 20:19:58 -07:00
|
|
|
local funcs = helpers.funcs
|
2021-06-01 20:32:37 -07:00
|
|
|
local mkdir_p = helpers.mkdir_p
|
|
|
|
local rmdir = helpers.rmdir
|
|
|
|
local write_file = helpers.write_file
|
|
|
|
|
|
|
|
describe('runtime:', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local plug_dir = 'Test_Plugin'
|
|
|
|
local sep = helpers.get_pathsep()
|
|
|
|
local init = 'dummy_init.lua'
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
io.open(init, 'w'):close() -- touch init file
|
|
|
|
clear{args = {'-u', init}}
|
|
|
|
exec('set rtp+=' .. plug_dir)
|
2023-07-08 08:29:24 -07:00
|
|
|
exec([[
|
|
|
|
set completeslash=slash
|
|
|
|
set isfname+=(,)
|
|
|
|
]])
|
2021-06-01 20:32:37 -07:00
|
|
|
end)
|
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
teardown(function()
|
|
|
|
os.remove(init)
|
2021-06-01 20:32:37 -07:00
|
|
|
end)
|
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
before_each(function()
|
|
|
|
mkdir_p(plug_dir)
|
|
|
|
end)
|
2021-06-01 20:32:37 -07:00
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
after_each(function()
|
|
|
|
rmdir(plug_dir)
|
2023-01-21 20:19:58 -07:00
|
|
|
exec('bwipe!')
|
2021-06-01 20:32:37 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('colors', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local colorscheme_folder = plug_dir .. sep .. 'colors'
|
2023-03-17 18:55:08 -07:00
|
|
|
before_each(function()
|
|
|
|
mkdir_p(colorscheme_folder)
|
|
|
|
end)
|
2021-06-02 09:46:25 -07:00
|
|
|
|
2021-06-01 20:32:37 -07:00
|
|
|
it('loads lua colorscheme', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme.lua'
|
2021-06-01 20:32:37 -07:00
|
|
|
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
|
|
|
|
2023-01-21 20:19:58 -07:00
|
|
|
eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color'))
|
2023-01-25 19:58:03 -07:00
|
|
|
eq({'colors/new_colorscheme.lua'}, funcs.getcompletion('colors/new_c', 'runtime'))
|
2023-01-21 20:19:58 -07:00
|
|
|
|
2021-06-01 20:32:37 -07:00
|
|
|
exec('colorscheme new_colorscheme')
|
|
|
|
|
|
|
|
eq(1, eval('g:lua_colorscheme'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads vim colorscheme when both lua and vim version exist', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme'
|
2021-06-01 20:32:37 -07:00
|
|
|
write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']])
|
|
|
|
write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']])
|
|
|
|
|
|
|
|
exec('colorscheme new_colorscheme')
|
|
|
|
|
|
|
|
eq('vim', eval('g:colorscheme'))
|
|
|
|
end)
|
2023-05-23 01:12:16 -07:00
|
|
|
|
|
|
|
it("loads lua colorscheme in 'rtp' if vim version only exists in 'pp' #23724", function()
|
|
|
|
local pack_dir = 'Test_Pack'
|
|
|
|
mkdir_p(pack_dir)
|
|
|
|
finally(function()
|
|
|
|
rmdir(pack_dir)
|
|
|
|
end)
|
|
|
|
exec('set pp+=' .. pack_dir)
|
|
|
|
|
|
|
|
local pack_opt_dir = pack_dir .. sep .. 'pack' .. sep .. 'some_name' .. sep .. 'opt'
|
|
|
|
local colors_opt_dir = pack_opt_dir .. sep .. 'some_pack' .. sep .. 'colors'
|
|
|
|
mkdir_p(colors_opt_dir)
|
|
|
|
|
|
|
|
local rtp_colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme'
|
|
|
|
local pp_opt_colorscheme_file = colors_opt_dir .. sep .. 'new_colorscheme'
|
|
|
|
|
|
|
|
write_file(pp_opt_colorscheme_file .. '.lua', [[vim.g.colorscheme = 'lua_pp']])
|
|
|
|
exec('colorscheme new_colorscheme')
|
|
|
|
eq('lua_pp', eval('g:colorscheme'))
|
|
|
|
|
|
|
|
write_file(pp_opt_colorscheme_file .. '.vim', [[let g:colorscheme = 'vim_pp']])
|
|
|
|
exec('colorscheme new_colorscheme')
|
|
|
|
eq('vim_pp', eval('g:colorscheme'))
|
|
|
|
|
|
|
|
write_file(rtp_colorscheme_file .. '.lua', [[vim.g.colorscheme = 'lua_rtp']])
|
|
|
|
exec('colorscheme new_colorscheme')
|
|
|
|
eq('lua_rtp', eval('g:colorscheme'))
|
|
|
|
|
|
|
|
write_file(rtp_colorscheme_file .. '.vim', [[let g:colorscheme = 'vim_rtp']])
|
|
|
|
exec('colorscheme new_colorscheme')
|
|
|
|
eq('vim_rtp', eval('g:colorscheme'))
|
|
|
|
end)
|
2021-06-01 20:32:37 -07:00
|
|
|
end)
|
|
|
|
|
2021-06-02 00:48:13 -07:00
|
|
|
describe('compiler', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local compiler_folder = plug_dir .. sep .. 'compiler'
|
2023-03-17 18:55:08 -07:00
|
|
|
before_each(function()
|
|
|
|
mkdir_p(compiler_folder)
|
|
|
|
end)
|
2021-06-02 00:48:13 -07:00
|
|
|
|
|
|
|
it('loads lua compilers', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local compiler_file = compiler_folder .. sep .. 'new_compiler.lua'
|
2023-01-21 20:19:58 -07:00
|
|
|
write_file(compiler_file, [[vim.b.lua_compiler = 1]])
|
|
|
|
|
|
|
|
eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler'))
|
2023-01-25 19:58:03 -07:00
|
|
|
eq({'compiler/new_compiler.lua'}, funcs.getcompletion('compiler/new_c', 'runtime'))
|
2021-06-02 00:48:13 -07:00
|
|
|
|
|
|
|
exec('compiler new_compiler')
|
|
|
|
|
2023-01-21 20:19:58 -07:00
|
|
|
eq(1, eval('b:lua_compiler'))
|
2021-06-02 00:48:13 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads vim compilers when both lua and vim version exist', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local compiler_file = compiler_folder .. sep .. 'new_compiler'
|
2023-07-13 02:17:19 -07:00
|
|
|
exec('let b:compiler = "compiler"')
|
|
|
|
write_file(compiler_file..'.vim', [[let b:compiler = b:compiler.'_vim']])
|
|
|
|
write_file(compiler_file..'.lua', [[vim.b.compiler = vim.b.compiler..'_lua']])
|
2021-06-02 00:48:13 -07:00
|
|
|
|
|
|
|
exec('compiler new_compiler')
|
|
|
|
|
2023-07-13 02:17:19 -07:00
|
|
|
-- lua version is sourced after vim
|
|
|
|
eq('compiler_vim_lua', eval('b:compiler'))
|
2021-06-02 00:48:13 -07:00
|
|
|
end)
|
|
|
|
end)
|
2021-06-02 03:25:50 -07:00
|
|
|
|
|
|
|
describe('ftplugin', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep)
|
2021-06-02 03:25:50 -07:00
|
|
|
|
|
|
|
it('loads lua ftplugins', function()
|
|
|
|
mkdir_p(ftplugin_folder)
|
2023-03-17 18:55:08 -07:00
|
|
|
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep)
|
2023-01-21 20:19:58 -07:00
|
|
|
write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]])
|
|
|
|
|
|
|
|
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
2023-01-25 19:58:03 -07:00
|
|
|
eq({'ftplugin/new-ft.lua'}, funcs.getcompletion('ftplugin/new-f', 'runtime'))
|
2021-06-02 03:25:50 -07:00
|
|
|
|
|
|
|
exec [[set filetype=new-ft]]
|
2023-01-21 20:19:58 -07:00
|
|
|
eq(1, eval('b:lua_ftplugin'))
|
2021-06-02 03:25:50 -07:00
|
|
|
end)
|
2023-06-30 02:01:13 -07:00
|
|
|
|
|
|
|
it("'rtp' order is respected", function()
|
|
|
|
local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
|
|
|
|
mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
|
|
|
|
mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
|
|
|
|
exec('set rtp+=' .. plug_dir .. '/after')
|
|
|
|
exec('let g:seq = ""')
|
|
|
|
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
|
|
|
-- All files in after/ftplugin/ are loaded after all files in ftplugin/.
|
|
|
|
write_file(table.concat({ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']])
|
|
|
|
write_file(table.concat({ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
|
|
|
write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
|
|
|
|
write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
|
|
|
|
write_file(table.concat({ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'E']])
|
|
|
|
write_file(table.concat({ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
|
|
|
|
write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
|
|
|
|
write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
|
|
|
write_file(table.concat({after_ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'c']])
|
|
|
|
write_file(table.concat({after_ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
|
|
|
|
write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
|
|
|
|
write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
|
|
|
|
exec('setfiletype new-ft')
|
|
|
|
eq('ABCDEFabcdef', eval('g:seq'))
|
|
|
|
end)
|
2021-06-02 03:25:50 -07:00
|
|
|
end)
|
2021-06-02 03:33:40 -07:00
|
|
|
|
|
|
|
describe('indent', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local indent_folder = table.concat({plug_dir, 'indent'}, sep)
|
2021-06-02 03:33:40 -07:00
|
|
|
|
|
|
|
it('loads lua indents', function()
|
|
|
|
mkdir_p(indent_folder)
|
2023-03-17 18:55:08 -07:00
|
|
|
local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep)
|
2023-01-21 20:19:58 -07:00
|
|
|
write_file(indent_file , [[vim.b.lua_indent = 1]])
|
|
|
|
|
|
|
|
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
2023-01-25 19:58:03 -07:00
|
|
|
eq({'indent/new-ft.lua'}, funcs.getcompletion('indent/new-f', 'runtime'))
|
2021-06-02 03:33:40 -07:00
|
|
|
|
|
|
|
exec [[set filetype=new-ft]]
|
2023-01-21 20:19:58 -07:00
|
|
|
eq(1, eval('b:lua_indent'))
|
2021-06-02 03:33:40 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2021-06-02 08:08:28 -07:00
|
|
|
describe('syntax', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local syntax_folder = table.concat({plug_dir, 'syntax'}, sep)
|
2021-06-02 08:08:28 -07:00
|
|
|
|
2023-01-21 20:19:58 -07:00
|
|
|
before_each(function()
|
2021-06-02 08:08:28 -07:00
|
|
|
mkdir_p(syntax_folder)
|
2023-03-17 18:55:08 -07:00
|
|
|
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
|
2023-01-21 20:19:58 -07:00
|
|
|
write_file(syntax_file , [[vim.b.current_syntax = 'my-lang']])
|
|
|
|
exec([[let b:current_syntax = '']])
|
|
|
|
end)
|
2021-06-02 08:08:28 -07:00
|
|
|
|
2023-01-21 20:19:58 -07:00
|
|
|
it('loads lua syntaxes on filetype change', function()
|
2021-06-02 08:08:28 -07:00
|
|
|
exec('set filetype=my-lang')
|
2023-01-21 20:19:58 -07:00
|
|
|
eq('my-lang', eval('b:current_syntax'))
|
2021-06-02 08:08:28 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads lua syntaxes on syntax change', function()
|
|
|
|
exec('set syntax=my-lang')
|
2023-01-21 20:19:58 -07:00
|
|
|
eq('my-lang', eval('b:current_syntax'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads lua syntaxes for :ownsyntax', function()
|
|
|
|
exec('ownsyntax my-lang')
|
|
|
|
eq('my-lang', eval('w:current_syntax'))
|
|
|
|
eq('', eval('b:current_syntax'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('lua syntaxes are included in cmdline completion', function()
|
|
|
|
eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype'))
|
|
|
|
eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax'))
|
2023-01-25 19:58:03 -07:00
|
|
|
eq({'syntax/my-lang.lua'}, funcs.getcompletion('syntax/my-l', 'runtime'))
|
2021-06-02 08:08:28 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2023-03-17 18:55:08 -07:00
|
|
|
describe('spell', function()
|
|
|
|
local spell_folder = table.concat({plug_dir, 'spell'}, sep)
|
|
|
|
|
|
|
|
it('loads spell/LANG.{vim,lua}', function()
|
|
|
|
mkdir_p(spell_folder)
|
|
|
|
local spell_vim = table.concat({spell_folder , 'Xtest.vim'}, sep)
|
|
|
|
write_file(spell_vim , [[let b:spell_vim = 1]])
|
|
|
|
local spell_lua = table.concat({spell_folder , 'Xtest.lua'}, sep)
|
|
|
|
write_file(spell_lua , [[vim.b.spell_lua = 1]])
|
|
|
|
exec('set spelllang=Xtest')
|
|
|
|
eq(1, eval('b:spell_vim'))
|
|
|
|
eq(1, eval('b:spell_lua'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2021-06-01 20:32:37 -07:00
|
|
|
end)
|
|
|
|
|