diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /test/functional/ex_cmds/source_spec.lua | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'test/functional/ex_cmds/source_spec.lua')
-rw-r--r-- | test/functional/ex_cmds/source_spec.lua | 130 |
1 files changed, 70 insertions, 60 deletions
diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 64c3464be7..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 @@ -48,7 +49,7 @@ describe(':source', function() pending("'shellslash' only works on Windows") return end - meths.set_option('shellslash', false) + meths.set_option_value('shellslash', false, {}) mkdir('Xshellslash') write_file([[Xshellslash/Xstack.vim]], [[ @@ -96,12 +97,12 @@ describe(':source', function() let d = s:s]]) command('source') - eq('2', meths.exec('echo a', true)) - eq("{'k': 'v'}", meths.exec('echo b', true)) + eq('2', exec_capture('echo a')) + eq("{'k': 'v'}", exec_capture('echo b')) -- Script items are created only on script var access - eq("1", meths.exec('echo c', true)) - eq("0zBEEFCAFE", meths.exec('echo d', true)) + eq("1", exec_capture('echo c')) + eq("0zBEEFCAFE", exec_capture('echo d')) exec('set cpoptions+=C') eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) @@ -124,14 +125,14 @@ describe(':source', function() -- Source the 2nd line only feed('ggjV') feed_command(':source') - eq('3', meths.exec('echo a', true)) + eq('3', exec_capture('echo a')) -- Source from 2nd line to end of file feed('ggjVG') feed_command(':source') - eq('4', meths.exec('echo a', true)) - eq("{'K': 'V'}", meths.exec('echo b', true)) - eq("<SNR>1_C()", meths.exec('echo D()', true)) + eq('4', exec_capture('echo a')) + eq("{'K': 'V'}", exec_capture('echo b')) + eq("<SNR>1_C()", exec_capture('echo D()')) -- Source last line only feed_command(':$source') @@ -147,7 +148,7 @@ describe(':source', function() let a = 123 ]] command('source') - eq('123', meths.exec('echo a', true)) + eq('123', exec_capture('echo a')) end) it('multiline heredoc command', function() @@ -157,7 +158,7 @@ describe(':source', function() EOF]]) command('source') - eq('4', meths.exec('echo luaeval("y")', true)) + eq('4', exec_capture('echo luaeval("y")')) end) it('can source lua files', function() @@ -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() |