fix(source): fix expand('<sfile>') no longer works for Lua

This commit is contained in:
zeertzjq
2022-08-15 13:40:01 +08:00
parent 1d28bbf1e5
commit d1464d16d6
3 changed files with 61 additions and 35 deletions

View File

@@ -48,21 +48,38 @@ describe(':source', function()
pending("'shellslash' only works on Windows")
return
end
mkdir('Xshellslash')
local script = [[
let g:result1 = expand('<stack>')
set shellslash
let g:result2 = expand('<stack>')
set noshellslash
let g:result3 = expand('<stack>')
]]
write_file([[Xshellslash/Xexpand.vim]], script)
meths.set_option('shellslash', false)
command([[source Xshellslash/Xexpand.vim]])
matches([[Xshellslash\Xexpand%.vim]], meths.get_var('result1'))
matches([[Xshellslash/Xexpand%.vim]], meths.get_var('result2'))
matches([[Xshellslash\Xexpand%.vim]], meths.get_var('result3'))
mkdir('Xshellslash')
write_file([[Xshellslash/Xstack.vim]], [[
let g:stack1 = expand('<stack>')
set shellslash
let g:stack2 = expand('<stack>')
set noshellslash
let g:stack3 = expand('<stack>')
]])
for _ = 1, 2 do
command([[source Xshellslash/Xstack.vim]])
matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack1'))
matches([[Xshellslash/Xstack%.vim]], meths.get_var('stack2'))
matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack3'))
end
write_file([[Xshellslash/Xstack.lua]], [[
vim.g.stack1 = vim.fn.expand('<stack>')
vim.o.shellslash = true
vim.g.stack2 = vim.fn.expand('<stack>')
vim.o.shellslash = false
vim.g.stack3 = vim.fn.expand('<stack>')
]])
for _ = 1, 2 do
command([[source Xshellslash/Xstack.lua]])
matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack1'))
matches([[Xshellslash/Xstack%.lua]], meths.get_var('stack2'))
matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack3'))
end
rmdir('Xshellslash')
end)
@@ -145,11 +162,18 @@ describe(':source', function()
it('can source lua files', function()
local test_file = 'test.lua'
write_file (test_file, [[vim.g.sourced_lua = 1]])
exec('source ' .. test_file)
write_file(test_file, [[
vim.g.sourced_lua = 1
vim.g.sfile_value = vim.fn.expand('<sfile>')
vim.g.stack_value = vim.fn.expand('<stack>')
]])
command('set shellslash')
command('source ' .. test_file)
eq(1, eval('g:sourced_lua'))
matches([[/test%.lua$]], meths.get_var('sfile_value'))
matches([[/test%.lua$]], meths.get_var('stack_value'))
os.remove(test_file)
end)
@@ -181,13 +205,15 @@ describe(':source', function()
it('can source current lua buffer without argument', function()
local test_file = 'test.lua'
write_file (test_file, [[
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>')
]])
command('edit '..test_file)
@@ -195,6 +221,9 @@ describe(':source', function()
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'))
os.remove(test_file)
end)