neovim/test/functional/ex_cmds/script_spec.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
2.4 KiB
Lua
Raw Normal View History

local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local neq = helpers.neq
local command = helpers.command
local exec_capture = helpers.exec_capture
local write_file = helpers.write_file
local api = helpers.api
local clear = helpers.clear
local dedent = helpers.dedent
local exc_exec = helpers.exc_exec
local missing_provider = helpers.missing_provider
local tmpfile = 'X_ex_cmds_script'
before_each(clear)
local function source(code)
write_file(tmpfile, code)
2024-01-02 18:09:18 -07:00
command('source ' .. tmpfile)
end
describe('script_get-based command', function()
local garbage = ')}{+*({}]*[;(+}{&[]}{*])('
after_each(function()
os.remove(tmpfile)
end)
local function test_garbage_exec(cmd, check_neq)
describe(cmd, function()
it('works correctly when skipping oneline variant', function()
2024-01-02 18:09:18 -07:00
eq(
true,
pcall(
source,
(dedent([[
if 0
%s %s
endif
2024-01-02 18:09:18 -07:00
]])):format(cmd, garbage)
)
)
eq('', exec_capture('messages'))
if check_neq then
2024-01-02 18:09:18 -07:00
neq(
0,
exc_exec(dedent([[
%s %s
2024-01-02 18:09:18 -07:00
]])):format(cmd, garbage)
)
end
end)
it('works correctly when skipping HEREdoc variant', function()
2024-01-02 18:09:18 -07:00
eq(
true,
pcall(
source,
(dedent([[
if 0
%s << EOF
%s
EOF
endif
2024-01-02 18:09:18 -07:00
]])):format(cmd, garbage)
)
)
eq('', exec_capture('messages'))
if check_neq then
2024-01-02 18:09:18 -07:00
eq(
true,
pcall(
source,
(dedent([[
let g:exc = 0
try
%s << EOF
%s
EOF
catch
let g:exc = v:exception
endtry
2024-01-02 18:09:18 -07:00
]])):format(cmd, garbage)
)
)
neq(0, api.nvim_get_var('exc'))
end
end)
end)
end
clear()
-- Built-in scripts
test_garbage_exec('lua', true)
-- Provider-based scripts
test_garbage_exec('ruby', not missing_provider('ruby'))
test_garbage_exec('python3', not missing_provider('python3'))
-- Missing scripts
test_garbage_exec('python', false)
test_garbage_exec('tcl', false)
test_garbage_exec('mzscheme', false)
test_garbage_exec('perl', false)
-- Not really a script
test_garbage_exec('xxxinvalidlanguagexxx', true)
end)