refactor: format test/*

This commit is contained in:
Justin M. Keyes
2024-01-03 02:09:18 +01:00
parent 59d117ec99
commit 04f2f864e2
363 changed files with 30631 additions and 20833 deletions

View File

@@ -52,13 +52,16 @@ describe(':source', function()
meths.set_option_value('shellslash', false, {})
mkdir('Xshellslash')
write_file([[Xshellslash/Xstack.vim]], [[
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]])
@@ -67,13 +70,16 @@ describe(':source', function()
matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack3'))
end
write_file([[Xshellslash/Xstack.lua]], [[
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]])
@@ -101,11 +107,11 @@ describe(':source', function()
eq("{'k': 'v'}", exec_capture('echo b'))
-- Script items are created only on script var access
eq("1", exec_capture('echo c'))
eq("0zBEEFCAFE", exec_capture('echo d'))
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'))
eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec('source'))
end)
it('selection in current buffer', function()
@@ -132,14 +138,14 @@ describe(':source', function()
feed_command(':source')
eq('4', exec_capture('echo a'))
eq("{'K': 'V'}", exec_capture('echo b'))
eq("<SNR>1_C()", exec_capture('echo D()'))
eq('<SNR>1_C()', exec_capture('echo D()'))
-- Source last line only
feed_command(':$source')
eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()'))
exec('set cpoptions+=C')
eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec("'<,'>source"))
eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec("'<,'>source"))
end)
it('does not break if current buffer is modified while sourced', function()
@@ -163,12 +169,15 @@ describe(':source', function()
it('can source lua files', function()
local test_file = 'test.lua'
write_file(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>')
vim.g.script_value = vim.fn.expand('<script>')
]])
]]
)
command('set shellslash')
command('source ' .. test_file)
@@ -245,22 +254,22 @@ describe(':source', function()
local test_file = 'test.lua'
-- Does throw E484 for unreadable files
local ok, result = pcall(exec_capture, ":source "..test_file ..'noexisting')
local ok, result = pcall(exec_capture, ':source ' .. test_file .. 'noexisting')
eq(false, ok)
neq(nil, result:find("E484"))
neq(nil, result:find('E484'))
-- Doesn't throw for parsing error
write_file (test_file, "vim.g.c = ")
ok, result = pcall(exec_capture, ":source "..test_file)
write_file(test_file, 'vim.g.c = ')
ok, result = pcall(exec_capture, ':source ' .. test_file)
eq(false, ok)
eq(nil, result:find("E484"))
eq(nil, result:find('E484'))
os.remove(test_file)
-- Doesn't throw for runtime error
write_file (test_file, "error('Cause error anyway :D')")
ok, result = pcall(exec_capture, ":source "..test_file)
write_file(test_file, "error('Cause error anyway :D')")
ok, result = pcall(exec_capture, ':source ' .. test_file)
eq(false, ok)
eq(nil, result:find("E484"))
eq(nil, result:find('E484'))
os.remove(test_file)
end)
end)