aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds/source_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
commit339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch)
treea6167fc8fcfc6ae2dc102f57b2473858eac34063 /test/functional/ex_cmds/source_spec.lua
parent067dc73729267c0262438a6fdd66e586f8496946 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'test/functional/ex_cmds/source_spec.lua')
-rw-r--r--test/functional/ex_cmds/source_spec.lua130
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()