diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-06-02 21:00:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-02 21:00:55 +0800 |
commit | 4b60267f82ef1947f8a583c02eaf502cf1db69ca (patch) | |
tree | b2e181245724b67dd0ed8828537701a3dd6a3c6b /test/functional/ex_cmds/source_spec.lua | |
parent | 36fd2fcaae757e8ac64c8ff7a66e4f480a075dcf (diff) | |
download | rneovim-4b60267f82ef1947f8a583c02eaf502cf1db69ca.tar.gz rneovim-4b60267f82ef1947f8a583c02eaf502cf1db69ca.tar.bz2 rneovim-4b60267f82ef1947f8a583c02eaf502cf1db69ca.zip |
feat(:source): source current ft=lua buffer as Lua code (#23802)
Diffstat (limited to 'test/functional/ex_cmds/source_spec.lua')
-rw-r--r-- | test/functional/ex_cmds/source_spec.lua | 108 |
1 files changed, 59 insertions, 49 deletions
diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 02f5bff021..24987354a4 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -7,6 +7,7 @@ local meths = helpers.meths local feed = helpers.feed local feed_command = helpers.feed_command local write_file = helpers.write_file +local tmpname = helpers.tmpname local exec = helpers.exec local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua @@ -179,56 +180,65 @@ describe(':source', function() os.remove(test_file) end) - it('can source selected region in lua file', function() - local test_file = 'test.lua' - - write_file (test_file, [[ - vim.g.b = 5 - vim.g.b = 6 - vim.g.b = 7 - a = [=[ - "\ a - \ b]=] - ]]) - - command('edit '..test_file) - - feed('ggjV') - feed_command(':source') - eq(6, eval('g:b')) - - feed('GVkk') - feed_command(':source') - eq(' "\\ a\n \\ b', exec_lua('return _G.a')) - - os.remove(test_file) - end) - - it('can source current lua buffer without argument', function() - local test_file = 'test.lua' - - write_file(test_file, [[ - vim.g.c = 10 - vim.g.c = 11 - vim.g.c = 12 - a = [=[ - \ 1 - "\ 2]=] - vim.g.sfile_value = vim.fn.expand('<sfile>') - vim.g.stack_value = vim.fn.expand('<stack>') - vim.g.script_value = vim.fn.expand('<script>') - ]]) - - command('edit '..test_file) - feed_command(':source') - - eq(12, eval('g:c')) - eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) - eq(':source (no file)', meths.get_var('sfile_value')) - eq(':source (no file)', meths.get_var('stack_value')) - eq(':source (no file)', meths.get_var('script_value')) + describe('can source current buffer', function() + local function test_source_lua_curbuf() + it('selected region', function() + insert([[ + vim.g.b = 5 + vim.g.b = 6 + vim.g.b = 7 + a = [=[ + "\ a + \ b]=] + ]]) + feed('dd') + + feed('ggjV') + feed_command(':source') + eq(6, eval('g:b')) + + feed('GVkk') + feed_command(':source') + eq(' "\\ a\n \\ b', exec_lua('return _G.a')) + end) + + it('whole buffer', function() + insert([[ + vim.g.c = 10 + vim.g.c = 11 + vim.g.c = 12 + a = [=[ + \ 1 + "\ 2]=] + vim.g.sfile_value = vim.fn.expand('<sfile>') + vim.g.stack_value = vim.fn.expand('<stack>') + vim.g.script_value = vim.fn.expand('<script>') + ]]) + feed('dd') + + feed_command(':source') + + eq(12, eval('g:c')) + eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) + eq(':source (no file)', meths.get_var('sfile_value')) + eq(':source (no file)', meths.get_var('stack_value')) + eq(':source (no file)', meths.get_var('script_value')) + end) + end - os.remove(test_file) + describe('with ft=lua', function() + before_each(function() + command('setlocal ft=lua') + end) + test_source_lua_curbuf() + end) + + describe('with .lua extension', function() + before_each(function() + command('edit ' .. tmpname() .. '.lua') + end) + test_source_lua_curbuf() + end) end) it("doesn't throw E484 for lua parsing/runtime errors", function() |