From 1e6c02510afd79659519f2a69075b36784134322 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 09:32:37 +0600 Subject: feat(runtime): Allow lua to be used in colorschemes * tests(runtime): move runtime/plugin tests to functional/lua/runtime_spec --- test/functional/lua/runtime_spec.lua | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/functional/lua/runtime_spec.lua (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua new file mode 100644 index 0000000000..a37570e4a4 --- /dev/null +++ b/test/functional/lua/runtime_spec.lua @@ -0,0 +1,89 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local exec = helpers.exec +local mkdir_p = helpers.mkdir_p +local rmdir = helpers.rmdir +local write_file = helpers.write_file + +describe('runtime:', function() + local xhome = 'Xhome' + local pathsep = helpers.get_pathsep() + local xconfig = xhome .. pathsep .. 'Xconfig' + + before_each(function() + clear() + mkdir_p(xconfig .. pathsep .. 'nvim') + end) + + after_each(function() + rmdir(xhome) + end) + + describe('plugin', function() + it('loads plugin/*.lua from XDG config home', function() + local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) + local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) + mkdir_p(plugin_folder_path) + write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + + eq(1, eval('g:lua_plugin')) + rmdir(plugin_folder_path) + end) + + + it('loads plugin/*.lua from start plugins', function() + local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory', + 'start', 'test_plugin'}, pathsep) + local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) + local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, + pathsep) + mkdir_p(plugin_folder_path) + write_file(plugin_file_path, [[vim.g.lua_plugin = 2]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + + eq(2, eval('g:lua_plugin')) + rmdir(plugin_path) + end) + end) + + describe('colors', function() + it('loads lua colorscheme', function() + local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'}, + pathsep) + local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'}, + pathsep) + mkdir_p(colorscheme_folder) + write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]]) + + clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }} + exec('colorscheme new_colorscheme') + + eq(1, eval('g:lua_colorscheme')) + rmdir(colorscheme_folder) + end) + + it('loads vim colorscheme when both lua and vim version exist', function() + local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'}, + pathsep) + local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme'}, + pathsep) + mkdir_p(colorscheme_folder) + write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']]) + write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + exec('colorscheme new_colorscheme') + + eq('vim', eval('g:colorscheme')) + rmdir(colorscheme_folder) + end) + end) + +end) + -- cgit From 68be8b99cfb1ab6105c48707986ce409ca38dd35 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 13:48:13 +0600 Subject: feat(runtime): Allow lua to be used in compiler --- test/functional/lua/runtime_spec.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index a37570e4a4..11407ad19c 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -85,5 +85,35 @@ describe('runtime:', function() end) end) + describe('compiler', function() + local compiler_folder = table.concat({xconfig, 'nvim', 'compiler'}, pathsep) + + it('loads lua compilers', function() + local compiler_file = table.concat({compiler_folder, 'new_compiler.lua'}, + pathsep) + mkdir_p(compiler_folder) + write_file(compiler_file, [[vim.g.lua_compiler = 1]]) + + clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }} + exec('compiler new_compiler') + + eq(1, eval('g:lua_compiler')) + rmdir(compiler_folder) + end) + + it('loads vim compilers when both lua and vim version exist', function() + local compiler_file = table.concat({compiler_folder, 'new_compiler'}, + pathsep) + mkdir_p(compiler_folder) + write_file(compiler_file..'.vim', [[let g:compiler = 'vim']]) + write_file(compiler_file..'.lua', [[vim.g.compiler = 'lua']]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + exec('compiler new_compiler') + + eq('vim', eval('g:compiler')) + rmdir(compiler_folder) + end) + end) end) -- cgit From fd5e5d2715d264447d94d7253f3c78bd7003a472 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 16:25:50 +0600 Subject: feat(runtime): Allow lua to be used in ftplugin --- test/functional/lua/runtime_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index 11407ad19c..b55141f427 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -23,6 +23,7 @@ describe('runtime:', function() end) describe('plugin', function() + before_each(clear) it('loads plugin/*.lua from XDG config home', function() local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) @@ -53,6 +54,7 @@ describe('runtime:', function() end) describe('colors', function() + before_each(clear) it('loads lua colorscheme', function() local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'}, pathsep) @@ -87,6 +89,7 @@ describe('runtime:', function() describe('compiler', function() local compiler_folder = table.concat({xconfig, 'nvim', 'compiler'}, pathsep) + before_each(clear) it('loads lua compilers', function() local compiler_file = table.concat({compiler_folder, 'new_compiler.lua'}, @@ -115,5 +118,23 @@ describe('runtime:', function() rmdir(compiler_folder) end) end) + + describe('ftplugin', function() + local ftplugin_folder = table.concat({xconfig, 'nvim', 'ftplugin'}, pathsep) + + before_each(clear) + + it('loads lua ftplugins', function() + local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep) + mkdir_p(ftplugin_folder) + write_file(ftplugin_file , [[ vim.g.lua_ftplugin = 1 ]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} + + exec [[set filetype=new-ft]] + eq(1, eval('g:lua_ftplugin')) + rmdir(ftplugin_folder) + end) + end) end) -- cgit From 4dffe1ff2f284fbd4d2bdb6a0f3997e21f9c0c6c Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 16:33:40 +0600 Subject: feat(runtime): Allow lua to be used in indent --- test/functional/lua/runtime_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index b55141f427..cd554d6bea 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -136,5 +136,24 @@ describe('runtime:', function() rmdir(ftplugin_folder) end) end) + + describe('indent', function() + local indent_folder = table.concat({xconfig, 'nvim', 'indent'}, pathsep) + + before_each(clear) + + it('loads lua indents', function() + local indent_file = table.concat({indent_folder , 'new-ft.lua'}, pathsep) + mkdir_p(indent_folder) + write_file(indent_file , [[ vim.g.lua_indent = 1 ]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} + + exec [[set filetype=new-ft]] + eq(1, eval('g:lua_indent')) + rmdir(indent_folder) + end) + end) + end) -- cgit From f256a18fefeebe76edcca42f530b238e95bc25b6 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 17:04:42 +0600 Subject: feat(runtime): Allow lua to be used in ftdetect --- test/functional/lua/runtime_spec.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index cd554d6bea..7286e89c76 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -127,7 +127,7 @@ describe('runtime:', function() it('loads lua ftplugins', function() local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep) mkdir_p(ftplugin_folder) - write_file(ftplugin_file , [[ vim.g.lua_ftplugin = 1 ]]) + write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]]) clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} @@ -145,7 +145,7 @@ describe('runtime:', function() it('loads lua indents', function() local indent_file = table.concat({indent_folder , 'new-ft.lua'}, pathsep) mkdir_p(indent_folder) - write_file(indent_file , [[ vim.g.lua_indent = 1 ]]) + write_file(indent_file , [[vim.g.lua_indent = 1]]) clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} @@ -155,5 +155,22 @@ describe('runtime:', function() end) end) + describe('ftdetect', function() + local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep) + + before_each(clear) + + it('loads lua ftdetects', function() + local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep) + mkdir_p(ftdetect_folder) + write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} + + eq(1, eval('g:lua_ftdetect')) + rmdir(ftdetect_folder) + end) + end) + end) -- cgit From f000251e087637d1add3678184ada80bef432fa9 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 21:08:28 +0600 Subject: feat(runtime): Allow lua to be used in syntax --- test/functional/lua/runtime_spec.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index 7286e89c76..cbdc6fa184 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -172,5 +172,35 @@ describe('runtime:', function() end) end) + describe('syntax', function() + local syntax_folder = table.concat({xconfig, 'nvim', 'syntax'}, pathsep) + + before_each(clear) + + it('loads lua syntaxes on filetype change', function() + local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, pathsep) + mkdir_p(syntax_folder) + write_file(syntax_file , [[vim.g.lua_syntax = 1]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} + + exec('set filetype=my-lang') + eq(1, eval('g:lua_syntax')) + rmdir(syntax_folder) + end) + + it('loads lua syntaxes on syntax change', function() + local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, pathsep) + mkdir_p(syntax_folder) + write_file(syntax_file , [[vim.g.lua_syntax = 5]]) + + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} + + exec('set syntax=my-lang') + eq(5, eval('g:lua_syntax')) + rmdir(syntax_folder) + end) + end) + end) -- cgit From 92b6b3764cf75d01bcbf04fcf598140fc01e7902 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 22:46:25 +0600 Subject: refactor(tests): Simplify tests at functional/lua/runtime_spec --- test/functional/lua/runtime_spec.lua | 123 +++++++++-------------------------- 1 file changed, 29 insertions(+), 94 deletions(-) (limited to 'test/functional/lua/runtime_spec.lua') diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index cbdc6fa184..e9c34c9228 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -9,61 +9,36 @@ local rmdir = helpers.rmdir local write_file = helpers.write_file describe('runtime:', function() - local xhome = 'Xhome' - local pathsep = helpers.get_pathsep() - local xconfig = xhome .. pathsep .. 'Xconfig' - - before_each(function() - clear() - mkdir_p(xconfig .. pathsep .. 'nvim') + 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) end) - after_each(function() - rmdir(xhome) + teardown(function() + os.remove(init) end) - describe('plugin', function() - before_each(clear) - it('loads plugin/*.lua from XDG config home', function() - local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) - local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) - mkdir_p(plugin_folder_path) - write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]]) - - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} - - eq(1, eval('g:lua_plugin')) - rmdir(plugin_folder_path) - end) - - - it('loads plugin/*.lua from start plugins', function() - local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory', - 'start', 'test_plugin'}, pathsep) - local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) - local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, - pathsep) - mkdir_p(plugin_folder_path) - write_file(plugin_file_path, [[vim.g.lua_plugin = 2]]) - - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + before_each(function() + mkdir_p(plug_dir) + end) - eq(2, eval('g:lua_plugin')) - rmdir(plugin_path) - end) + after_each(function() + rmdir(plug_dir) end) describe('colors', function() - before_each(clear) + local colorscheme_folder = plug_dir .. sep .. 'colors' + it('loads lua colorscheme', function() - local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'}, - pathsep) - local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'}, - pathsep) + local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme.lua' mkdir_p(colorscheme_folder) write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]]) - clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }} exec('colorscheme new_colorscheme') eq(1, eval('g:lua_colorscheme')) @@ -71,15 +46,11 @@ describe('runtime:', function() end) it('loads vim colorscheme when both lua and vim version exist', function() - local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'}, - pathsep) - local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme'}, - pathsep) + local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme' mkdir_p(colorscheme_folder) write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']]) write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']]) - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} exec('colorscheme new_colorscheme') eq('vim', eval('g:colorscheme')) @@ -88,16 +59,13 @@ describe('runtime:', function() end) describe('compiler', function() - local compiler_folder = table.concat({xconfig, 'nvim', 'compiler'}, pathsep) - before_each(clear) + local compiler_folder = plug_dir .. sep .. 'compiler' it('loads lua compilers', function() - local compiler_file = table.concat({compiler_folder, 'new_compiler.lua'}, - pathsep) + local compiler_file = compiler_folder .. sep .. 'new_compiler.lua' mkdir_p(compiler_folder) write_file(compiler_file, [[vim.g.lua_compiler = 1]]) - clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }} exec('compiler new_compiler') eq(1, eval('g:lua_compiler')) @@ -105,13 +73,11 @@ describe('runtime:', function() end) it('loads vim compilers when both lua and vim version exist', function() - local compiler_file = table.concat({compiler_folder, 'new_compiler'}, - pathsep) + local compiler_file = compiler_folder .. sep .. 'new_compiler' mkdir_p(compiler_folder) write_file(compiler_file..'.vim', [[let g:compiler = 'vim']]) write_file(compiler_file..'.lua', [[vim.g.compiler = 'lua']]) - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} exec('compiler new_compiler') eq('vim', eval('g:compiler')) @@ -120,17 +86,13 @@ describe('runtime:', function() end) describe('ftplugin', function() - local ftplugin_folder = table.concat({xconfig, 'nvim', 'ftplugin'}, pathsep) - - before_each(clear) + local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep) it('loads lua ftplugins', function() - local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep) + local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep) mkdir_p(ftplugin_folder) write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]]) - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} - exec [[set filetype=new-ft]] eq(1, eval('g:lua_ftplugin')) rmdir(ftplugin_folder) @@ -138,64 +100,37 @@ describe('runtime:', function() end) describe('indent', function() - local indent_folder = table.concat({xconfig, 'nvim', 'indent'}, pathsep) - - before_each(clear) + local indent_folder = table.concat({plug_dir, 'indent'}, sep) it('loads lua indents', function() - local indent_file = table.concat({indent_folder , 'new-ft.lua'}, pathsep) + local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep) mkdir_p(indent_folder) write_file(indent_file , [[vim.g.lua_indent = 1]]) - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} - exec [[set filetype=new-ft]] eq(1, eval('g:lua_indent')) rmdir(indent_folder) end) end) - describe('ftdetect', function() - local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep) - - before_each(clear) - - it('loads lua ftdetects', function() - local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep) - mkdir_p(ftdetect_folder) - write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]]) - - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} - - eq(1, eval('g:lua_ftdetect')) - rmdir(ftdetect_folder) - end) - end) - describe('syntax', function() - local syntax_folder = table.concat({xconfig, 'nvim', 'syntax'}, pathsep) - - before_each(clear) + local syntax_folder = table.concat({plug_dir, 'syntax'}, sep) it('loads lua syntaxes on filetype change', function() - local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, pathsep) + local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep) mkdir_p(syntax_folder) write_file(syntax_file , [[vim.g.lua_syntax = 1]]) - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} - exec('set filetype=my-lang') eq(1, eval('g:lua_syntax')) rmdir(syntax_folder) end) it('loads lua syntaxes on syntax change', function() - local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, pathsep) + local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep) mkdir_p(syntax_folder) write_file(syntax_file , [[vim.g.lua_syntax = 5]]) - clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }} - exec('set syntax=my-lang') eq(5, eval('g:lua_syntax')) rmdir(syntax_folder) -- cgit