2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local assert_alive = n.assert_alive
|
|
|
|
local eval, command, feed = n.eval, n.command, n.feed
|
|
|
|
local eq, clear, insert = t.eq, n.clear, n.insert
|
|
|
|
local expect, write_file = n.expect, t.write_file
|
|
|
|
local feed_command = n.feed_command
|
|
|
|
local source = n.source
|
|
|
|
local missing_provider = n.missing_provider
|
2024-04-08 02:03:20 -07:00
|
|
|
local matches = t.matches
|
|
|
|
local pcall_err = t.pcall_err
|
2024-04-20 08:44:13 -07:00
|
|
|
local fn = n.fn
|
2024-04-08 02:03:20 -07:00
|
|
|
local dedent = t.dedent
|
2015-09-22 05:33:08 -07:00
|
|
|
|
2015-03-20 15:55:39 -07:00
|
|
|
do
|
2015-11-04 03:01:22 -07:00
|
|
|
clear()
|
2024-01-07 05:05:03 -07:00
|
|
|
local reason = missing_provider('python')
|
2019-12-23 23:53:56 -07:00
|
|
|
if reason then
|
2018-12-11 16:17:27 -07:00
|
|
|
it(':python3 reports E319 if provider is missing', function()
|
2019-01-11 16:52:12 -07:00
|
|
|
local expected = [[Vim%(py3.*%):E319: No "python3" provider found.*]]
|
2019-09-06 17:17:37 -07:00
|
|
|
matches(expected, pcall_err(command, 'py3 print("foo")'))
|
|
|
|
matches(expected, pcall_err(command, 'py3file foo'))
|
2018-12-11 16:17:27 -07:00
|
|
|
end)
|
2024-03-05 00:54:41 -07:00
|
|
|
it('feature test when Python 3 provider is missing', function()
|
|
|
|
eq(0, eval('has("python3")'))
|
|
|
|
eq(0, eval('has("python3_compiled")'))
|
|
|
|
eq(0, eval('has("python3_dynamic")'))
|
|
|
|
eq(0, eval('has("pythonx")'))
|
|
|
|
end)
|
2024-01-02 18:09:18 -07:00
|
|
|
pending(
|
|
|
|
string.format('Python 3 (or the pynvim module) is broken/missing (%s)', reason),
|
|
|
|
function() end
|
|
|
|
)
|
2015-03-20 15:55:39 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-20 15:57:41 -07:00
|
|
|
describe('python3 provider', function()
|
2015-03-20 15:55:39 -07:00
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
command('python3 import vim')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('feature test', function()
|
|
|
|
eq(1, eval('has("python3")'))
|
2019-09-09 10:54:07 -07:00
|
|
|
eq(1, eval('has("python3_compiled")'))
|
|
|
|
eq(1, eval('has("python3_dynamic")'))
|
2024-03-05 00:54:41 -07:00
|
|
|
eq(1, eval('has("pythonx")'))
|
2019-09-09 10:54:07 -07:00
|
|
|
eq(0, eval('has("python3_dynamic_")'))
|
|
|
|
eq(0, eval('has("python3_")'))
|
2015-03-20 15:55:39 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('python3_execute', function()
|
|
|
|
command('python3 vim.vars["set_by_python3"] = [100, 0]')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq({ 100, 0 }, eval('g:set_by_python3'))
|
2015-03-20 15:55:39 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-01 02:43:47 -07:00
|
|
|
it('does not truncate error message <1 MB', function()
|
|
|
|
-- XXX: Python limits the error name to 200 chars, so this test is
|
|
|
|
-- mostly bogus.
|
|
|
|
local very_long_symbol = string.rep('a', 1200)
|
2024-01-02 18:09:18 -07:00
|
|
|
feed_command(':silent! py3 print(' .. very_long_symbol .. ' b)')
|
2019-01-24 11:15:39 -07:00
|
|
|
-- Error message will contain this (last) line.
|
2024-01-02 18:09:18 -07:00
|
|
|
matches(
|
|
|
|
string.format(
|
|
|
|
dedent([[
|
2022-03-13 07:05:56 -07:00
|
|
|
^Error invoking 'python_execute' on channel 3 %%(python3%%-script%%-host%%):
|
|
|
|
File "<string>", line 1
|
|
|
|
print%%(%s b%%)
|
|
|
|
%%C*
|
2024-01-02 18:09:18 -07:00
|
|
|
SyntaxError: invalid syntax%%C*$]]),
|
|
|
|
very_long_symbol
|
|
|
|
),
|
|
|
|
eval('v:errmsg')
|
|
|
|
)
|
2017-03-01 02:43:47 -07:00
|
|
|
end)
|
|
|
|
|
2015-03-20 15:55:39 -07:00
|
|
|
it('python3_execute with nested commands', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
command(
|
|
|
|
[[python3 vim.command('python3 vim.command("python3 vim.command(\'let set_by_nested_python3 = 555\')")')]]
|
|
|
|
)
|
2015-03-20 15:55:39 -07:00
|
|
|
eq(555, eval('g:set_by_nested_python3'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('python3_execute with range', function()
|
|
|
|
insert([[
|
|
|
|
line1
|
|
|
|
line2
|
|
|
|
line3
|
|
|
|
line4]])
|
|
|
|
feed('ggjvj:python3 vim.vars["range"] = vim.current.range[:]<CR>')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq({ 'line2', 'line3' }, eval('g:range'))
|
2015-03-20 15:55:39 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('py3file', function()
|
|
|
|
local fname = 'py3file.py'
|
2015-06-30 05:16:22 -07:00
|
|
|
write_file(fname, 'vim.command("let set_by_py3file = 123")')
|
2015-03-20 15:55:39 -07:00
|
|
|
command('py3file py3file.py')
|
|
|
|
eq(123, eval('g:set_by_py3file'))
|
|
|
|
os.remove(fname)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('py3do', function()
|
|
|
|
-- :pydo3 42 returns None for all lines,
|
|
|
|
-- the buffer should not be changed
|
|
|
|
command('normal :py3do 42')
|
|
|
|
eq(0, eval('&mod'))
|
|
|
|
-- insert some text
|
|
|
|
insert('abc\ndef\nghi')
|
|
|
|
expect([[
|
|
|
|
abc
|
|
|
|
def
|
|
|
|
ghi]])
|
|
|
|
-- go to top and select and replace the first two lines
|
|
|
|
feed('ggvj:py3do return str(linenr)<CR>')
|
|
|
|
expect([[
|
|
|
|
1
|
|
|
|
2
|
|
|
|
ghi]])
|
|
|
|
end)
|
|
|
|
|
2022-01-28 07:42:19 -07:00
|
|
|
describe('py3eval()', function()
|
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 1, 2, { ['key'] = 'val' } }, fn.py3eval('[1, 2, {"key": "val"}]'))
|
2022-01-28 07:42:19 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('errors out when given non-string', function()
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(10)'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(v:_null_dict)'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(v:_null_list)'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(0.0)'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(function("tr"))'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(v:true)'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(v:false)'))
|
|
|
|
eq('Vim:E474: Invalid argument', pcall_err(eval, 'py3eval(v:null)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('accepts NULL string', function()
|
|
|
|
matches('.*SyntaxError.*', pcall_err(eval, 'py3eval($XXX_NONEXISTENT_VAR_XXX)'))
|
|
|
|
end)
|
2015-03-20 15:55:39 -07:00
|
|
|
end)
|
2018-03-20 15:57:41 -07:00
|
|
|
|
2019-08-14 13:36:43 -07:00
|
|
|
it('pyxeval #10758', function()
|
2022-01-28 07:42:19 -07:00
|
|
|
eq(3, eval([[&pyxversion]]))
|
2019-08-14 13:36:43 -07:00
|
|
|
eq(3, eval([[pyxeval('sys.version_info[:3][0]')]]))
|
|
|
|
eq(3, eval([[&pyxversion]]))
|
|
|
|
end)
|
|
|
|
|
2022-01-28 07:42:19 -07:00
|
|
|
it("setting 'pyxversion'", function()
|
|
|
|
command 'set pyxversion=3' -- no error
|
|
|
|
eq('Vim(set):E474: Invalid argument: pyxversion=2', pcall_err(command, 'set pyxversion=2'))
|
|
|
|
command 'set pyxversion=0' -- allowed, but equivalent to pyxversion=3
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(3, eval '&pyxversion')
|
2022-01-28 07:42:19 -07:00
|
|
|
end)
|
|
|
|
|
2018-03-20 15:57:41 -07:00
|
|
|
it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function()
|
2024-04-20 08:44:13 -07:00
|
|
|
n.add_builddir_to_rtp()
|
2018-03-20 15:57:41 -07:00
|
|
|
source([=[
|
|
|
|
python3 << EOF
|
|
|
|
import vim
|
|
|
|
def foo():
|
|
|
|
vim.eval('expand("<afile>:p")')
|
|
|
|
vim.eval('bufnr(expand("<afile>:p"))')
|
|
|
|
EOF
|
|
|
|
autocmd BufDelete * python3 foo()
|
|
|
|
autocmd BufUnload * python3 foo()]=])
|
|
|
|
feed_command("exe 'split' tempname()")
|
2024-01-02 18:09:18 -07:00
|
|
|
feed_command('bwipeout!')
|
2018-03-20 15:57:41 -07:00
|
|
|
feed_command('help help')
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2018-03-20 15:57:41 -07:00
|
|
|
end)
|
2015-03-20 15:55:39 -07:00
|
|
|
end)
|
2022-01-28 07:42:19 -07:00
|
|
|
|
|
|
|
describe('python2 feature test', function()
|
|
|
|
-- python2 is not supported, so correct behaviour is to return 0
|
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.has('python2'))
|
|
|
|
eq(0, fn.has('python'))
|
|
|
|
eq(0, fn.has('python_compiled'))
|
|
|
|
eq(0, fn.has('python_dynamic'))
|
|
|
|
eq(0, fn.has('python_dynamic_'))
|
|
|
|
eq(0, fn.has('python_'))
|
2022-01-28 07:42:19 -07:00
|
|
|
end)
|
|
|
|
end)
|