forked from aniani/vim
patch 8.2.1146: not enough testing for Python
Problem: Not enough testing for Python. Solution: Add more tests. Fix uncovered problems. (Yegappan Lakshmanan, closes #6392)
This commit is contained in:
@@ -2250,6 +2250,9 @@ ListNew(PyTypeObject *subtype, list_T *list)
|
|||||||
{
|
{
|
||||||
ListObject *self;
|
ListObject *self;
|
||||||
|
|
||||||
|
if (list == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
self = (ListObject *) subtype->tp_alloc(subtype, 0);
|
self = (ListObject *) subtype->tp_alloc(subtype, 0);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -2695,6 +2698,12 @@ ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj)
|
|||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
{
|
{
|
||||||
li = list_find(l, (long) index);
|
li = list_find(l, (long) index);
|
||||||
|
if (li == NULL)
|
||||||
|
{
|
||||||
|
PyErr_VIM_FORMAT(N_("internal error: failed to get Vim "
|
||||||
|
"list item %d"), (int) index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
vimlist_remove(l, li, li);
|
vimlist_remove(l, li, li);
|
||||||
clear_tv(&li->li_tv);
|
clear_tv(&li->li_tv);
|
||||||
vim_free(li);
|
vim_free(li);
|
||||||
@@ -2716,6 +2725,12 @@ ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
li = list_find(l, (long) index);
|
li = list_find(l, (long) index);
|
||||||
|
if (li == NULL)
|
||||||
|
{
|
||||||
|
PyErr_VIM_FORMAT(N_("internal error: failed to get Vim "
|
||||||
|
"list item %d"), (int) index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
clear_tv(&li->li_tv);
|
clear_tv(&li->li_tv);
|
||||||
copy_tv(&tv, &li->li_tv);
|
copy_tv(&tv, &li->li_tv);
|
||||||
clear_tv(&tv);
|
clear_tv(&tv);
|
||||||
@@ -3897,7 +3912,7 @@ WindowDestructor(WindowObject *self)
|
|||||||
PyObject_GC_UnTrack((void *)(self));
|
PyObject_GC_UnTrack((void *)(self));
|
||||||
if (self->win && self->win != INVALID_WINDOW_VALUE)
|
if (self->win && self->win != INVALID_WINDOW_VALUE)
|
||||||
WIN_PYTHON_REF(self->win) = NULL;
|
WIN_PYTHON_REF(self->win) = NULL;
|
||||||
Py_XDECREF(((PyObject *)(self->tabObject)));
|
Py_XDECREF(((PyObject *)(self->tabObject)));
|
||||||
PyObject_GC_Del((void *)(self));
|
PyObject_GC_Del((void *)(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1256,6 +1256,10 @@ BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
|
|||||||
if (PyLong_Check(idx))
|
if (PyLong_Check(idx))
|
||||||
{
|
{
|
||||||
long n = PyLong_AsLong(idx);
|
long n = PyLong_AsLong(idx);
|
||||||
|
|
||||||
|
if (CheckBuffer((BufferObject *) self))
|
||||||
|
return -1;
|
||||||
|
|
||||||
return RBAsItem((BufferObject *)(self), n, val, 1,
|
return RBAsItem((BufferObject *)(self), n, val, 1,
|
||||||
(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
|
(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
|
||||||
NULL);
|
NULL);
|
||||||
|
@@ -353,4 +353,19 @@ func GetMessages()
|
|||||||
return msg_list
|
return msg_list
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Run the list of commands in 'cmds' and look for 'errstr' in exception.
|
||||||
|
" Note that assert_fails() cannot be used in some places and this function
|
||||||
|
" can be used.
|
||||||
|
func AssertException(cmds, errstr)
|
||||||
|
let save_exception = ''
|
||||||
|
try
|
||||||
|
for cmd in a:cmds
|
||||||
|
exe cmd
|
||||||
|
endfor
|
||||||
|
catch
|
||||||
|
let save_exception = v:exception
|
||||||
|
endtry
|
||||||
|
call assert_match(a:errstr, save_exception)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
source check.vim
|
source check.vim
|
||||||
CheckFeature python
|
CheckFeature python
|
||||||
CheckFeature quickfix
|
CheckFeature quickfix
|
||||||
|
source shared.vim
|
||||||
|
|
||||||
" NOTE: This will cause errors when run under valgrind.
|
" NOTE: This will cause errors when run under valgrind.
|
||||||
" This would require recompiling Python with:
|
" This would require recompiling Python with:
|
||||||
@@ -55,13 +56,13 @@ func Test_AAA_python_setup()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_pydo()
|
func Test_pydo()
|
||||||
" Check deleting lines does not trigger ml_get error.
|
" Check deleting lines does not trigger an ml_get error.
|
||||||
new
|
new
|
||||||
call setline(1, ['one', 'two', 'three'])
|
call setline(1, ['one', 'two', 'three'])
|
||||||
pydo vim.command("%d_")
|
pydo vim.command("%d_")
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
" Check switching to another buffer does not trigger ml_get error.
|
" Check switching to another buffer does not trigger an ml_get error.
|
||||||
new
|
new
|
||||||
let wincount = winnr('$')
|
let wincount = winnr('$')
|
||||||
call setline(1, ['one', 'two', 'three'])
|
call setline(1, ['one', 'two', 'three'])
|
||||||
@@ -69,6 +70,19 @@ func Test_pydo()
|
|||||||
call assert_equal(wincount + 1, winnr('$'))
|
call assert_equal(wincount + 1, winnr('$'))
|
||||||
bwipe!
|
bwipe!
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
|
" Try modifying a buffer with 'nomodifiable' set
|
||||||
|
set nomodifiable
|
||||||
|
call assert_fails('pydo toupper(line)', 'cannot save undo information')
|
||||||
|
set modifiable
|
||||||
|
|
||||||
|
" Invalid command
|
||||||
|
call AssertException(['pydo non_existing_cmd'],
|
||||||
|
\ "Vim(pydo):NameError: global name 'non_existing_cmd' is not defined")
|
||||||
|
call AssertException(["pydo raise Exception('test')"],
|
||||||
|
\ 'Vim(pydo):Exception: test')
|
||||||
|
call AssertException(["pydo {lambda}"],
|
||||||
|
\ 'Vim(pydo):SyntaxError: invalid syntax')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_set_cursor()
|
func Test_set_cursor()
|
||||||
@@ -106,14 +120,9 @@ func Test_vim_function()
|
|||||||
call assert_false(v:exception)
|
call assert_false(v:exception)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
let caught_vim_err = v:false
|
" Non-existing function attribute
|
||||||
try
|
call AssertException(["let x = pyeval('f.abc')"],
|
||||||
let x = pyeval('f.abc')
|
\ 'Vim(let):AttributeError: abc')
|
||||||
catch
|
|
||||||
call assert_match('AttributeError: abc', v:exception)
|
|
||||||
let caught_vim_err = v:true
|
|
||||||
endtry
|
|
||||||
call assert_equal(v:true, caught_vim_err)
|
|
||||||
|
|
||||||
py del f
|
py del f
|
||||||
delfunc s:foo
|
delfunc s:foo
|
||||||
@@ -250,6 +259,9 @@ func Test_python_range()
|
|||||||
py r = b.range(1, 3)
|
py r = b.range(1, 3)
|
||||||
call assert_equal(0, pyeval('r.start'))
|
call assert_equal(0, pyeval('r.start'))
|
||||||
call assert_equal(2, pyeval('r.end'))
|
call assert_equal(2, pyeval('r.end'))
|
||||||
|
call assert_equal('one', pyeval('r[0]'))
|
||||||
|
call assert_equal('one', pyeval('r[-3]'))
|
||||||
|
call assert_equal('three', pyeval('r[-4]'))
|
||||||
call assert_equal(['two', 'three'], pyeval('r[1:]'))
|
call assert_equal(['two', 'three'], pyeval('r[1:]'))
|
||||||
py r[0] = 'green'
|
py r[0] = 'green'
|
||||||
call assert_equal(['green', 'two', 'three'], getline(1, '$'))
|
call assert_equal(['green', 'two', 'three'], getline(1, '$'))
|
||||||
@@ -257,14 +269,22 @@ func Test_python_range()
|
|||||||
call assert_equal(['red', 'blue', 'three'], getline(1, '$'))
|
call assert_equal(['red', 'blue', 'three'], getline(1, '$'))
|
||||||
call assert_equal(['start', 'end', '__members__'], pyeval('r.__members__'))
|
call assert_equal(['start', 'end', '__members__'], pyeval('r.__members__'))
|
||||||
|
|
||||||
let caught_vim_err = v:false
|
" try different invalid start/end index for the range slice
|
||||||
try
|
%d
|
||||||
let x = pyeval('r.abc')
|
call setline(1, ['one', 'two', 'three'])
|
||||||
catch
|
py r[-10:1] = ["a"]
|
||||||
call assert_match('AttributeError: abc', v:exception)
|
py r[10:12] = ["b"]
|
||||||
let caught_vim_err = v:true
|
py r[-10:-9] = ["c"]
|
||||||
endtry
|
py r[1:0] = ["d"]
|
||||||
call assert_equal(v:true, caught_vim_err)
|
call assert_equal(['c', 'd', 'a', 'two', 'three', 'b'], getline(1, '$'))
|
||||||
|
|
||||||
|
" FIXME: The following code triggers ml_get errors
|
||||||
|
" %d
|
||||||
|
" let x = pyeval('r[:]')
|
||||||
|
|
||||||
|
" Non-existing range attribute
|
||||||
|
call AssertException(["let x = pyeval('r.abc')"],
|
||||||
|
\ 'Vim(let):AttributeError: abc')
|
||||||
|
|
||||||
close!
|
close!
|
||||||
endfunc
|
endfunc
|
||||||
@@ -273,33 +293,50 @@ endfunc
|
|||||||
func Test_python_tabpage()
|
func Test_python_tabpage()
|
||||||
tabnew
|
tabnew
|
||||||
py t = vim.tabpages[1]
|
py t = vim.tabpages[1]
|
||||||
|
py wl = t.windows
|
||||||
tabclose
|
tabclose
|
||||||
let caught_vim_err = v:false
|
" Accessing a closed tabpage
|
||||||
try
|
call AssertException(["let n = pyeval('t.number')"],
|
||||||
let n = pyeval('t.number')
|
\ 'Vim(let):vim.error: attempt to refer to deleted tab page')
|
||||||
catch
|
call AssertException(["let n = pyeval('len(wl)')"],
|
||||||
call assert_match('vim.error: attempt to refer to deleted tab page',
|
\ 'Vim(let):vim.error: attempt to refer to deleted tab page')
|
||||||
\ v:exception)
|
call AssertException(["py w = wl[0]"],
|
||||||
let caught_vim_err = v:true
|
\ 'Vim(python):vim.error: attempt to refer to deleted tab page')
|
||||||
endtry
|
call AssertException(["py vim.current.tabpage = t"],
|
||||||
call assert_equal(v:true, caught_vim_err)
|
\ 'Vim(python):vim.error: attempt to refer to deleted tab page')
|
||||||
|
call assert_match('<tabpage object (deleted)', pyeval('repr(t)'))
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for the python window object
|
" Test for the python window object
|
||||||
func Test_python_window()
|
func Test_python_window()
|
||||||
new
|
" Test for setting the window height
|
||||||
|
10new
|
||||||
|
py vim.current.window.height = 5
|
||||||
|
call assert_equal(5, winheight(0))
|
||||||
|
|
||||||
|
" Test for setting the window width
|
||||||
|
10vnew
|
||||||
|
py vim.current.window.width = 6
|
||||||
|
call assert_equal(6, winwidth(0))
|
||||||
|
|
||||||
|
" Try accessing a closed window
|
||||||
py w = vim.current.window
|
py w = vim.current.window
|
||||||
|
py wopts = w.options
|
||||||
close
|
close
|
||||||
let caught_vim_err = v:false
|
" Access the attributes of a closed window
|
||||||
try
|
call AssertException(["let n = pyeval('w.number')"],
|
||||||
let n = pyeval('w.number')
|
\ 'Vim(let):vim.error: attempt to refer to deleted window')
|
||||||
catch
|
call AssertException(["py w.height = 5"],
|
||||||
call assert_match('vim.error: attempt to refer to deleted window',
|
\ 'Vim(python):vim.error: attempt to refer to deleted window')
|
||||||
\ v:exception)
|
call AssertException(["py vim.current.window = w"],
|
||||||
let caught_vim_err = v:true
|
\ 'Vim(python):vim.error: attempt to refer to deleted window')
|
||||||
endtry
|
" Try to set one of the options of the closed window
|
||||||
call assert_equal(v:true, caught_vim_err)
|
" FIXME: The following causes ASAN failure
|
||||||
|
"call AssertException(["py wopts['list'] = False"],
|
||||||
|
" \ 'vim.error: problem while switching windows')
|
||||||
|
call assert_match('<window object (deleted)', pyeval("repr(w)"))
|
||||||
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for the python List object
|
" Test for the python List object
|
||||||
@@ -308,6 +345,21 @@ func Test_python_list()
|
|||||||
py pl = vim.bindeval('l')
|
py pl = vim.bindeval('l')
|
||||||
call assert_equal(['locked', '__members__'], pyeval('pl.__members__'))
|
call assert_equal(['locked', '__members__'], pyeval('pl.__members__'))
|
||||||
|
|
||||||
|
" Try to convert a null List
|
||||||
|
call AssertException(["py t = vim.eval('test_null_list()')"],
|
||||||
|
\ 'Vim(python):SystemError: error return without exception set')
|
||||||
|
|
||||||
|
" Try to convert a List with a null List item
|
||||||
|
call AssertException(["py t = vim.eval('[test_null_list()]')"],
|
||||||
|
\ 'Vim(python):SystemError: error return without exception set')
|
||||||
|
|
||||||
|
" Try to bind a null List variable
|
||||||
|
let cmds =<< trim END
|
||||||
|
let l = test_null_list()
|
||||||
|
py ll = vim.bindeval('l')
|
||||||
|
END
|
||||||
|
call AssertException(cmds, 'Vim(python):SystemError: error return without exception set')
|
||||||
|
|
||||||
let l = []
|
let l = []
|
||||||
py l = vim.bindeval('l')
|
py l = vim.bindeval('l')
|
||||||
py f = vim.bindeval('function("strlen")')
|
py f = vim.bindeval('function("strlen")')
|
||||||
@@ -322,6 +374,16 @@ func Test_python_list()
|
|||||||
call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l)
|
call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l)
|
||||||
py l[-2] = f
|
py l[-2] = f
|
||||||
call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l)
|
call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l)
|
||||||
|
|
||||||
|
" appending to a list
|
||||||
|
let l = [1, 2]
|
||||||
|
py ll = vim.bindeval('l')
|
||||||
|
py ll[2] = 8
|
||||||
|
call assert_equal([1, 2, 8], l)
|
||||||
|
|
||||||
|
" Using dict as an index
|
||||||
|
call AssertException(['py ll[{}] = 10'],
|
||||||
|
\ 'Vim(python):TypeError: index must be int or slice, not dict')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for the python Dict object
|
" Test for the python Dict object
|
||||||
@@ -330,6 +392,26 @@ func Test_python_dict()
|
|||||||
py pd = vim.bindeval('d')
|
py pd = vim.bindeval('d')
|
||||||
call assert_equal(['locked', 'scope', '__members__'],
|
call assert_equal(['locked', 'scope', '__members__'],
|
||||||
\ pyeval('pd.__members__'))
|
\ pyeval('pd.__members__'))
|
||||||
|
|
||||||
|
" Try to convert a null Dict
|
||||||
|
call AssertException(["py t = vim.eval('test_null_dict()')"],
|
||||||
|
\ 'Vim(python):SystemError: error return without exception set')
|
||||||
|
|
||||||
|
" Try to convert a Dict with a null List value
|
||||||
|
call AssertException(["py t = vim.eval(\"{'a' : test_null_list()}\")"],
|
||||||
|
\ 'Vim(python):SystemError: error return without exception set')
|
||||||
|
|
||||||
|
" Try to convert a Dict with a null string key
|
||||||
|
py t = vim.eval("{test_null_string() : 10}")
|
||||||
|
call assert_fails("let d = pyeval('t')", 'E859:')
|
||||||
|
|
||||||
|
" Dict length
|
||||||
|
let d = {'a' : 10, 'b' : 20}
|
||||||
|
py d = vim.bindeval('d')
|
||||||
|
call assert_equal(2, pyeval('len(d)'))
|
||||||
|
|
||||||
|
" Deleting an non-existing key
|
||||||
|
call AssertException(["py del d['c']"], "Vim(python):KeyError: 'c'")
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Extending Dictionary directly with different types
|
" Extending Dictionary directly with different types
|
||||||
@@ -356,6 +438,12 @@ func Test_python_dict_extend()
|
|||||||
di.sort(cmpfun)
|
di.sort(cmpfun)
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
" Try extending a locked dictionary
|
||||||
|
lockvar d
|
||||||
|
call AssertException(["py d.update({'b' : 20})"],
|
||||||
|
\ 'Vim(python):vim.error: dictionary is locked')
|
||||||
|
unlockvar d
|
||||||
|
|
||||||
call assert_equal(1, pyeval("d['f'](self={})"))
|
call assert_equal(1, pyeval("d['f'](self={})"))
|
||||||
call assert_equal("['-1', '0', '1', 'b', 'f']", pyeval('repr(dk)'))
|
call assert_equal("['-1', '0', '1', 'b', 'f']", pyeval('repr(dk)'))
|
||||||
call assert_equal("['asd', -1L, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >]", substitute(pyeval('repr(dv)'),'0x\x\+','','g'))
|
call assert_equal("['asd', -1L, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >]", substitute(pyeval('repr(dv)'),'0x\x\+','','g'))
|
||||||
@@ -552,6 +640,11 @@ func Test_python_lockedvar()
|
|||||||
EOF
|
EOF
|
||||||
call assert_equal(['', "l[2] threw vim.error: error:('list is locked',)"],
|
call assert_equal(['', "l[2] threw vim.error: error:('list is locked',)"],
|
||||||
\ getline(1, '$'))
|
\ getline(1, '$'))
|
||||||
|
|
||||||
|
" Try to concatenate a locked list
|
||||||
|
call AssertException(['py l += [4, 5]'],
|
||||||
|
\ 'Vim(python):vim.error: list is locked')
|
||||||
|
|
||||||
call assert_equal([0, 1, 2, 3], l)
|
call assert_equal([0, 1, 2, 3], l)
|
||||||
unlockvar! l
|
unlockvar! l
|
||||||
close!
|
close!
|
||||||
@@ -665,6 +758,11 @@ func Test_python_lock_scope_attr()
|
|||||||
call assert_equal([0], l)
|
call assert_equal([0], l)
|
||||||
call assert_equal([1], ll)
|
call assert_equal([1], ll)
|
||||||
unlet l ll
|
unlet l ll
|
||||||
|
|
||||||
|
" Try changing an attribute of a fixed list
|
||||||
|
py a = vim.bindeval('v:argv')
|
||||||
|
call AssertException(['py a.locked = 0'],
|
||||||
|
\ 'Vim(python):TypeError: cannot modify fixed list')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for pyeval()
|
" Test for pyeval()
|
||||||
@@ -679,42 +777,38 @@ func Test_python_pyeval()
|
|||||||
call assert_equal(v:none, pyeval('None'))
|
call assert_equal(v:none, pyeval('None'))
|
||||||
call assert_equal('', v:errmsg)
|
call assert_equal('', v:errmsg)
|
||||||
|
|
||||||
|
py v = vim.eval('test_null_function()')
|
||||||
|
call assert_equal(v:none, pyeval('v'))
|
||||||
|
|
||||||
if has('float')
|
if has('float')
|
||||||
call assert_equal(0.0, pyeval('0.0'))
|
call assert_equal(0.0, pyeval('0.0'))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Invalid values:
|
" Evaluate an invalid values
|
||||||
let caught_859 = 0
|
call AssertException(['let v = pyeval(''"\0"'')'], 'E859:')
|
||||||
try
|
call AssertException(['let v = pyeval(''{"\0" : 1}'')'], 'E859:')
|
||||||
let v = pyeval('"\0"')
|
call AssertException(['let v = pyeval("undefined_name")'],
|
||||||
catch /E859:/
|
\ "Vim(let):NameError: name 'undefined_name' is not defined")
|
||||||
let caught_859 = 1
|
call AssertException(['let v = pyeval("vim")'], 'E859:')
|
||||||
endtry
|
endfunc
|
||||||
call assert_equal(1, caught_859)
|
|
||||||
|
|
||||||
let caught_859 = 0
|
" Test for vim.bindeval()
|
||||||
try
|
func Test_python_vim_bindeval()
|
||||||
let v = pyeval('{"\0" : 1}')
|
" Float
|
||||||
catch /E859:/
|
let f = 3.14
|
||||||
let caught_859 = 1
|
py f = vim.bindeval('f')
|
||||||
endtry
|
call assert_equal(3.14, pyeval('f'))
|
||||||
call assert_equal(1, caught_859)
|
|
||||||
|
|
||||||
let caught_nameerr = 0
|
" Blob
|
||||||
try
|
let b = 0z12
|
||||||
let v = pyeval("undefined_name")
|
py b = vim.bindeval('b')
|
||||||
catch /NameError: name 'undefined_name'/
|
call assert_equal("\x12", pyeval('b'))
|
||||||
let caught_nameerr = 1
|
|
||||||
endtry
|
|
||||||
call assert_equal(1, caught_nameerr)
|
|
||||||
|
|
||||||
let caught_859 = 0
|
" Bool
|
||||||
try
|
call assert_equal(1, pyeval("vim.bindeval('v:true')"))
|
||||||
let v = pyeval("vim")
|
call assert_equal(0, pyeval("vim.bindeval('v:false')"))
|
||||||
catch /E859:/
|
call assert_equal(v:none, pyeval("vim.bindeval('v:null')"))
|
||||||
let caught_859 = 1
|
call assert_equal(v:none, pyeval("vim.bindeval('v:none')"))
|
||||||
endtry
|
|
||||||
call assert_equal(1, caught_859)
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" threading
|
" threading
|
||||||
@@ -812,7 +906,24 @@ func Test_python_list_slice()
|
|||||||
call assert_equal([0, 2, 4], pyeval('l'))
|
call assert_equal([0, 2, 4], pyeval('l'))
|
||||||
py l = ll[4:2:1]
|
py l = ll[4:2:1]
|
||||||
call assert_equal([], pyeval('l'))
|
call assert_equal([], pyeval('l'))
|
||||||
|
|
||||||
|
" Error case: Use an invalid index
|
||||||
|
call AssertException(['py ll[-10] = 5'], 'Vim(python):vim.error: internal error:')
|
||||||
|
|
||||||
|
" Use a step value of 0
|
||||||
|
call AssertException(['py ll[0:3:0] = [1, 2, 3]'],
|
||||||
|
\ 'Vim(python):ValueError: slice step cannot be zero')
|
||||||
|
|
||||||
|
" Error case: Invalid slice type
|
||||||
|
call AssertException(["py x = ll['abc']"],
|
||||||
|
\ 'Vim(python):TypeError: index must be int or slice, not str')
|
||||||
py del l
|
py del l
|
||||||
|
|
||||||
|
" Error case: List with a null list item
|
||||||
|
let l = [test_null_list()]
|
||||||
|
py ll = vim.bindeval('l')
|
||||||
|
call AssertException(["py x = ll[:]"],
|
||||||
|
\ 'Vim(python):SystemError: error return without exception set')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Vars
|
" Vars
|
||||||
@@ -1249,6 +1360,24 @@ func Test_python_opts()
|
|||||||
|
|
||||||
call assert_equal(expected, g:res)
|
call assert_equal(expected, g:res)
|
||||||
unlet g:res
|
unlet g:res
|
||||||
|
|
||||||
|
call assert_equal(0, pyeval("'' in vim.options"))
|
||||||
|
|
||||||
|
" use an empty key to index vim.options
|
||||||
|
call AssertException(["let v = pyeval(\"vim.options['']\")"],
|
||||||
|
\ 'Vim(let):ValueError: empty keys are not allowed')
|
||||||
|
call AssertException(["py vim.current.window.options[''] = 0"],
|
||||||
|
\ 'Vim(python):ValueError: empty keys are not allowed')
|
||||||
|
call AssertException(["py vim.current.window.options[{}] = 0"],
|
||||||
|
\ 'Vim(python):TypeError: expected str() or unicode() instance, but got dict')
|
||||||
|
|
||||||
|
" set one of the number options to a very large number
|
||||||
|
let cmd = ["py vim.options['previewheight'] = 9999999999999999"]
|
||||||
|
call AssertException(cmd, 'OverflowError:')
|
||||||
|
|
||||||
|
" unset a global-local string option
|
||||||
|
call AssertException(["py del vim.options['errorformat']"],
|
||||||
|
\ 'Vim(python):ValueError: unable to unset global option errorformat')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for vim.buffer object
|
" Test for vim.buffer object
|
||||||
@@ -1267,11 +1396,26 @@ func Test_python_buffer()
|
|||||||
py b = vim.current.buffer
|
py b = vim.current.buffer
|
||||||
wincmd w
|
wincmd w
|
||||||
|
|
||||||
|
" Test for getting lines from the buffer using a slice
|
||||||
|
call assert_equal(['First line'], pyeval('b[-10:1]'))
|
||||||
|
call assert_equal(['Third line'], pyeval('b[2:10]'))
|
||||||
|
call assert_equal([], pyeval('b[2:0]'))
|
||||||
|
call assert_equal([], pyeval('b[10:12]'))
|
||||||
|
call assert_equal([], pyeval('b[-10:-8]'))
|
||||||
|
|
||||||
" Tests BufferAppend and BufferItem
|
" Tests BufferAppend and BufferItem
|
||||||
py cb.append(b[0])
|
py cb.append(b[0])
|
||||||
call assert_equal(['First line'], getbufline(bnr1, 2))
|
call assert_equal(['First line'], getbufline(bnr1, 2))
|
||||||
%d
|
%d
|
||||||
|
|
||||||
|
" Try to append using out-of-range line number
|
||||||
|
call AssertException(["py b.append('abc', 10)"],
|
||||||
|
\ 'Vim(python):IndexError: line number out of range')
|
||||||
|
|
||||||
|
" Append a non-string item
|
||||||
|
call AssertException(["py b.append([22])"],
|
||||||
|
\ 'Vim(python):TypeError: expected str() or unicode() instance, but got int')
|
||||||
|
|
||||||
" Tests BufferSlice and BufferAssSlice
|
" Tests BufferSlice and BufferAssSlice
|
||||||
py cb.append('abc5') # Will be overwritten
|
py cb.append('abc5') # Will be overwritten
|
||||||
py cb[-1:] = b[:-2]
|
py cb[-1:] = b[:-2]
|
||||||
@@ -1363,11 +1507,62 @@ func Test_python_buffer()
|
|||||||
EOF
|
EOF
|
||||||
call assert_equal([''], getline(1, '$'))
|
call assert_equal([''], getline(1, '$'))
|
||||||
|
|
||||||
|
" Delete all the lines in a buffer
|
||||||
|
call setline(1, ['a', 'b', 'c'])
|
||||||
|
py vim.current.buffer[:] = []
|
||||||
|
call assert_equal([''], getline(1, '$'))
|
||||||
|
|
||||||
|
" Test for modifying a 'nomodifiable' buffer
|
||||||
|
setlocal nomodifiable
|
||||||
|
call AssertException(["py vim.current.buffer[0] = 'abc'"],
|
||||||
|
\ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py vim.current.buffer[0] = None"],
|
||||||
|
\ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py vim.current.buffer[:] = None"],
|
||||||
|
\ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py vim.current.buffer[:] = []"],
|
||||||
|
\ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py vim.current.buffer.append('abc')"],
|
||||||
|
\ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py vim.current.buffer.append([])"],
|
||||||
|
\ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
setlocal modifiable
|
||||||
|
|
||||||
augroup BUFS
|
augroup BUFS
|
||||||
autocmd!
|
autocmd!
|
||||||
augroup END
|
augroup END
|
||||||
augroup! BUFS
|
augroup! BUFS
|
||||||
%bw!
|
%bw!
|
||||||
|
|
||||||
|
" Range object for a deleted buffer
|
||||||
|
new Xfile
|
||||||
|
call setline(1, ['one', 'two', 'three'])
|
||||||
|
py b = vim.current.buffer
|
||||||
|
py r = vim.current.buffer.range(0, 2)
|
||||||
|
call assert_equal('<range Xfile (0:2)>', pyeval('repr(r)'))
|
||||||
|
%bw!
|
||||||
|
call AssertException(['py r[:] = []'],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call assert_match('<buffer object (deleted)', pyeval('repr(b)'))
|
||||||
|
call assert_match('<range object (for deleted buffer)', pyeval('repr(r)'))
|
||||||
|
call AssertException(["let n = pyeval('len(r)')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py r.append('abc')"],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
|
|
||||||
|
" object for a deleted buffer
|
||||||
|
call AssertException(["py b[0] = 'one'"],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py b.append('one')"],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["let n = pyeval('len(b)')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py pos = b.mark('a')"],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py vim.current.buffer = b"],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py rn = b.range(0, 2)"],
|
||||||
|
\ 'Vim(python):vim.error: attempt to refer to deleted buffer')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test vim.buffers object
|
" Test vim.buffers object
|
||||||
@@ -1468,6 +1663,8 @@ func Test_python_tabpage_window()
|
|||||||
vnew b.2
|
vnew b.2
|
||||||
vnew c.2
|
vnew c.2
|
||||||
|
|
||||||
|
call assert_equal(4, pyeval('vim.current.window.tabpage.number'))
|
||||||
|
|
||||||
py << trim EOF
|
py << trim EOF
|
||||||
cb.append('Number of tabs: ' + str(len(vim.tabpages)))
|
cb.append('Number of tabs: ' + str(len(vim.tabpages)))
|
||||||
cb.append('Current tab pages:')
|
cb.append('Current tab pages:')
|
||||||
@@ -1617,6 +1814,8 @@ func Test_python_vim_current()
|
|||||||
Current line: 'python interface'
|
Current line: 'python interface'
|
||||||
END
|
END
|
||||||
call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
|
call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
|
||||||
|
py vim.current.line = 'one line'
|
||||||
|
call assert_equal('one line', getline('.'))
|
||||||
call deletebufline(bufnr('Xfile'), 1, '$')
|
call deletebufline(bufnr('Xfile'), 1, '$')
|
||||||
|
|
||||||
py << trim EOF
|
py << trim EOF
|
||||||
@@ -1739,13 +1938,13 @@ endfunc
|
|||||||
|
|
||||||
" Test vim.Function
|
" Test vim.Function
|
||||||
func Test_python_vim_func()
|
func Test_python_vim_func()
|
||||||
function Args(...)
|
func Args(...)
|
||||||
return a:000
|
return a:000
|
||||||
endfunction
|
endfunc
|
||||||
|
|
||||||
function SelfArgs(...) dict
|
func SelfArgs(...) dict
|
||||||
return [a:000, self]
|
return [a:000, self]
|
||||||
endfunction
|
endfunc
|
||||||
|
|
||||||
" The following four lines should not crash
|
" The following four lines should not crash
|
||||||
let Pt = function('tr', [[]], {'l': []})
|
let Pt = function('tr', [[]], {'l': []})
|
||||||
@@ -1753,6 +1952,8 @@ func Test_python_vim_func()
|
|||||||
unlet Pt
|
unlet Pt
|
||||||
py del Pt
|
py del Pt
|
||||||
|
|
||||||
|
call assert_equal(3, pyeval('vim.strwidth("a\tb")'))
|
||||||
|
|
||||||
%bw!
|
%bw!
|
||||||
py cb = vim.current.buffer
|
py cb = vim.current.buffer
|
||||||
py << trim EOF
|
py << trim EOF
|
||||||
@@ -2129,9 +2330,9 @@ endfunc
|
|||||||
" Test subclassing
|
" Test subclassing
|
||||||
func Test_python_subclass()
|
func Test_python_subclass()
|
||||||
new
|
new
|
||||||
fun Put(...)
|
func Put(...)
|
||||||
return a:000
|
return a:000
|
||||||
endfun
|
endfunc
|
||||||
|
|
||||||
py << trim EOF
|
py << trim EOF
|
||||||
class DupDict(vim.Dictionary):
|
class DupDict(vim.Dictionary):
|
||||||
@@ -2211,11 +2412,11 @@ endfunc
|
|||||||
|
|
||||||
" Test errors
|
" Test errors
|
||||||
func Test_python_errors()
|
func Test_python_errors()
|
||||||
fun F() dict
|
func F() dict
|
||||||
endfun
|
endfunc
|
||||||
|
|
||||||
fun D()
|
func D()
|
||||||
endfun
|
endfunc
|
||||||
|
|
||||||
new
|
new
|
||||||
py cb = vim.current.buffer
|
py cb = vim.current.buffer
|
||||||
@@ -2537,8 +2738,8 @@ func Test_python_errors()
|
|||||||
ee('vim.windows[1000]')
|
ee('vim.windows[1000]')
|
||||||
cb.append("> Buffer")
|
cb.append("> Buffer")
|
||||||
cb.append(">> StringToLine (indirect)")
|
cb.append(">> StringToLine (indirect)")
|
||||||
ee('vim.current.buffer[0] = u"\\na"')
|
|
||||||
ee('vim.current.buffer[0] = "\\na"')
|
ee('vim.current.buffer[0] = "\\na"')
|
||||||
|
ee('vim.current.buffer[0] = u"\\na"')
|
||||||
cb.append(">> SetBufferLine (indirect)")
|
cb.append(">> SetBufferLine (indirect)")
|
||||||
ee('vim.current.buffer[0] = True')
|
ee('vim.current.buffer[0] = True')
|
||||||
cb.append(">> SetBufferLineList (indirect)")
|
cb.append(">> SetBufferLineList (indirect)")
|
||||||
@@ -3360,8 +3561,8 @@ func Test_python_errors()
|
|||||||
vim.windows[1000]:IndexError:('no such window',)
|
vim.windows[1000]:IndexError:('no such window',)
|
||||||
> Buffer
|
> Buffer
|
||||||
>> StringToLine (indirect)
|
>> StringToLine (indirect)
|
||||||
vim.current.buffer[0] = u"\na":error:('string cannot contain newlines',)
|
|
||||||
vim.current.buffer[0] = "\na":error:('string cannot contain newlines',)
|
vim.current.buffer[0] = "\na":error:('string cannot contain newlines',)
|
||||||
|
vim.current.buffer[0] = u"\na":error:('string cannot contain newlines',)
|
||||||
>> SetBufferLine (indirect)
|
>> SetBufferLine (indirect)
|
||||||
vim.current.buffer[0] = True:TypeError:('bad argument type for built-in operation',)
|
vim.current.buffer[0] = True:TypeError:('bad argument type for built-in operation',)
|
||||||
>> SetBufferLineList (indirect)
|
>> SetBufferLineList (indirect)
|
||||||
@@ -3442,6 +3643,7 @@ func Test_python_import()
|
|||||||
cb.append(tm.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/__init__.py'):])
|
cb.append(tm.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/__init__.py'):])
|
||||||
cb.append(tms.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/__init__.py'):])
|
cb.append(tms.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/__init__.py'):])
|
||||||
cb.append(tmsss.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/subsubmodule/subsubsubmodule.py'):])
|
cb.append(tmsss.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/subsubmodule/subsubsubmodule.py'):])
|
||||||
|
|
||||||
del before
|
del before
|
||||||
del after
|
del after
|
||||||
del d
|
del d
|
||||||
@@ -3463,13 +3665,16 @@ func Test_python_import()
|
|||||||
END
|
END
|
||||||
call assert_equal(expected, getline(2, '$'))
|
call assert_equal(expected, getline(2, '$'))
|
||||||
close!
|
close!
|
||||||
|
|
||||||
|
" Try to import a non-existing moudle with a dot (.)
|
||||||
|
call AssertException(['py import a.b.c'], 'ImportError:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test exceptions
|
" Test exceptions
|
||||||
func Test_python_exception()
|
func Test_python_exception()
|
||||||
fun Exe(e)
|
func Exe(e)
|
||||||
execute a:e
|
execute a:e
|
||||||
endfun
|
endfunc
|
||||||
|
|
||||||
new
|
new
|
||||||
py cb = vim.current.buffer
|
py cb = vim.current.buffer
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
source check.vim
|
source check.vim
|
||||||
CheckFeature python3
|
CheckFeature python3
|
||||||
|
source shared.vim
|
||||||
|
|
||||||
" This function should be called first. This sets up python functions used by
|
" This function should be called first. This sets up python functions used by
|
||||||
" the other tests.
|
" the other tests.
|
||||||
@@ -73,7 +74,6 @@ endfunc
|
|||||||
|
|
||||||
func Test_py3do()
|
func Test_py3do()
|
||||||
" Check deleting lines does not trigger an ml_get error.
|
" Check deleting lines does not trigger an ml_get error.
|
||||||
py3 import vim
|
|
||||||
new
|
new
|
||||||
call setline(1, ['one', 'two', 'three'])
|
call setline(1, ['one', 'two', 'three'])
|
||||||
py3do vim.command("%d_")
|
py3do vim.command("%d_")
|
||||||
@@ -87,11 +87,23 @@ func Test_py3do()
|
|||||||
call assert_equal(wincount + 1, winnr('$'))
|
call assert_equal(wincount + 1, winnr('$'))
|
||||||
bwipe!
|
bwipe!
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
|
" Try modifying a buffer with 'nomodifiable' set
|
||||||
|
set nomodifiable
|
||||||
|
call assert_fails('py3do toupper(line)', 'cannot save undo information')
|
||||||
|
set modifiable
|
||||||
|
|
||||||
|
" Invalid command
|
||||||
|
call AssertException(['py3do non_existing_cmd'],
|
||||||
|
\ "Vim(py3do):NameError: name 'non_existing_cmd' is not defined")
|
||||||
|
call AssertException(["py3do raise Exception('test')"],
|
||||||
|
\ 'Vim(py3do):Exception: test')
|
||||||
|
call AssertException(["py3do {lambda}"],
|
||||||
|
\ 'Vim(py3do):SyntaxError: invalid syntax')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_set_cursor()
|
func Test_set_cursor()
|
||||||
" Check that setting the cursor position works.
|
" Check that setting the cursor position works.
|
||||||
py3 import vim
|
|
||||||
new
|
new
|
||||||
call setline(1, ['first line', 'second line'])
|
call setline(1, ['first line', 'second line'])
|
||||||
normal gg
|
normal gg
|
||||||
@@ -105,7 +117,6 @@ endfunc
|
|||||||
|
|
||||||
func Test_vim_function()
|
func Test_vim_function()
|
||||||
" Check creating vim.Function object
|
" Check creating vim.Function object
|
||||||
py3 import vim
|
|
||||||
|
|
||||||
func s:foo()
|
func s:foo()
|
||||||
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$')
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$')
|
||||||
@@ -126,14 +137,9 @@ func Test_vim_function()
|
|||||||
call assert_false(v:exception)
|
call assert_false(v:exception)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
let caught_vim_err = v:false
|
" Non-existing function attribute
|
||||||
try
|
call AssertException(["let x = py3eval('f.abc')"],
|
||||||
let x = py3eval('f.abc')
|
\ "Vim(let):AttributeError: 'vim.function' object has no attribute 'abc'")
|
||||||
catch
|
|
||||||
call assert_match("AttributeError: 'vim.function' object has no attribute 'abc'", v:exception)
|
|
||||||
let caught_vim_err = v:true
|
|
||||||
endtry
|
|
||||||
call assert_equal(v:true, caught_vim_err)
|
|
||||||
|
|
||||||
py3 del f
|
py3 del f
|
||||||
delfunc s:foo
|
delfunc s:foo
|
||||||
@@ -148,7 +154,6 @@ func Test_skipped_python3_command_does_not_affect_pyxversion()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func _SetUpHiddenBuffer()
|
func _SetUpHiddenBuffer()
|
||||||
py3 import vim
|
|
||||||
new
|
new
|
||||||
edit hidden
|
edit hidden
|
||||||
setlocal bufhidden=hide
|
setlocal bufhidden=hide
|
||||||
@@ -198,7 +203,6 @@ func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func _SetUpVisibleBuffer()
|
func _SetUpVisibleBuffer()
|
||||||
py3 import vim
|
|
||||||
new
|
new
|
||||||
let lnum = 0
|
let lnum = 0
|
||||||
while lnum < 10
|
while lnum < 10
|
||||||
@@ -303,8 +307,8 @@ func Test_python3_range()
|
|||||||
|
|
||||||
call assert_fails('py3 r[3] = "x"', 'IndexError: line number out of range')
|
call assert_fails('py3 r[3] = "x"', 'IndexError: line number out of range')
|
||||||
call assert_fails('py3 x = r[3]', 'IndexError: line number out of range')
|
call assert_fails('py3 x = r[3]', 'IndexError: line number out of range')
|
||||||
call assert_fails('py3 r["a"] = "x"', 'TypeError')
|
call assert_fails('py3 r["a"] = "x"', 'TypeError: index must be int or slice, not str')
|
||||||
call assert_fails('py3 x = r["a"]', 'TypeError')
|
call assert_fails('py3 x = r["a"]', 'TypeError: index must be int or slice, not str')
|
||||||
|
|
||||||
py3 del r[:]
|
py3 del r[:]
|
||||||
call assert_equal(['1', '5', '6'], getline(1, '$'))
|
call assert_equal(['1', '5', '6'], getline(1, '$'))
|
||||||
@@ -431,8 +435,112 @@ s+='B'
|
|||||||
call assert_equal('ABCDE', pyxeval('s'))
|
call assert_equal('ABCDE', pyxeval('s'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for the buffer range object
|
||||||
|
func Test_python3_range2()
|
||||||
|
new
|
||||||
|
call setline(1, ['one', 'two', 'three'])
|
||||||
|
py3 b = vim.current.buffer
|
||||||
|
py3 r = b.range(1, 3)
|
||||||
|
call assert_equal(0, py3eval('r.start'))
|
||||||
|
call assert_equal(2, py3eval('r.end'))
|
||||||
|
call assert_equal('one', py3eval('r[0]'))
|
||||||
|
call assert_equal('one', py3eval('r[-3]'))
|
||||||
|
call AssertException(["let x = py3eval('r[-4]')"],
|
||||||
|
\ 'Vim(let):IndexError: line number out of range')
|
||||||
|
call assert_equal(['two', 'three'], py3eval('r[1:]'))
|
||||||
|
py3 r[0] = 'green'
|
||||||
|
call assert_equal(['green', 'two', 'three'], getline(1, '$'))
|
||||||
|
py3 r[0:2] = ['red', 'blue']
|
||||||
|
call assert_equal(['red', 'blue', 'three'], getline(1, '$'))
|
||||||
|
|
||||||
|
" try different invalid start/end index for the range slice
|
||||||
|
%d
|
||||||
|
call setline(1, ['one', 'two', 'three'])
|
||||||
|
py3 r[-10:1] = ["a"]
|
||||||
|
py3 r[10:12] = ["b"]
|
||||||
|
py3 r[-10:-9] = ["c"]
|
||||||
|
py3 r[1:0] = ["d"]
|
||||||
|
call assert_equal(['c', 'd', 'a', 'two', 'three', 'b'], getline(1, '$'))
|
||||||
|
|
||||||
|
" FIXME: The following code triggers ml_get errors
|
||||||
|
" %d
|
||||||
|
" let x = py3eval('r[:]')
|
||||||
|
|
||||||
|
" Non-existing range attribute
|
||||||
|
call AssertException(["let x = py3eval('r.abc')"],
|
||||||
|
\ "Vim(let):AttributeError: 'vim.range' object has no attribute 'abc'")
|
||||||
|
|
||||||
|
close!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for the python tabpage object
|
||||||
|
func Test_python3_tabpage()
|
||||||
|
tabnew
|
||||||
|
py3 t = vim.tabpages[1]
|
||||||
|
py3 wl = t.windows
|
||||||
|
tabclose
|
||||||
|
" Accessing a closed tabpage
|
||||||
|
call AssertException(["let n = py3eval('t.number')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted tab page')
|
||||||
|
call AssertException(["let n = py3eval('len(wl)')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted tab page')
|
||||||
|
call AssertException(["py3 w = wl[0]"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted tab page')
|
||||||
|
call AssertException(["py3 vim.current.tabpage = t"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted tab page')
|
||||||
|
call assert_match('<tabpage object (deleted)', py3eval('repr(t)'))
|
||||||
|
%bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for the python window object
|
||||||
|
func Test_python3_window()
|
||||||
|
" Test for setting the window height
|
||||||
|
10new
|
||||||
|
py3 vim.current.window.height = 5
|
||||||
|
call assert_equal(5, winheight(0))
|
||||||
|
|
||||||
|
" Test for setting the window width
|
||||||
|
10vnew
|
||||||
|
py3 vim.current.window.width = 6
|
||||||
|
call assert_equal(6, winwidth(0))
|
||||||
|
|
||||||
|
" Try accessing a closed window
|
||||||
|
py3 w = vim.current.window
|
||||||
|
py3 wopts = w.options
|
||||||
|
close
|
||||||
|
" Access the attributes of a closed window
|
||||||
|
call AssertException(["let n = py3eval('w.number')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted window')
|
||||||
|
call AssertException(["py3 w.height = 5"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted window')
|
||||||
|
call AssertException(["py3 vim.current.window = w"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted window')
|
||||||
|
" Try to set one of the options of the closed window
|
||||||
|
" FIXME: The following causes ASAN failure
|
||||||
|
"call AssertException(["py3 wopts['list'] = False"],
|
||||||
|
" \ 'Vim(py3):vim.error: problem while switching windows')
|
||||||
|
call assert_match('<window object (deleted)', py3eval("repr(w)"))
|
||||||
|
%bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for the python List object
|
" Test for the python List object
|
||||||
func Test_python3_list()
|
func Test_python3_list()
|
||||||
|
" Try to convert a null List
|
||||||
|
call AssertException(["py3 t = vim.eval('test_null_list()')"],
|
||||||
|
\ 'Vim(py3):SystemError: <built-in function eval> returned NULL without setting an error')
|
||||||
|
|
||||||
|
" Try to convert a List with a null List item
|
||||||
|
call AssertException(["py3 t = vim.eval('[test_null_list()]')"],
|
||||||
|
\ 'Vim(py3):SystemError: <built-in function eval> returned NULL without setting an error')
|
||||||
|
|
||||||
|
" Try to bind a null List variable
|
||||||
|
let cmds =<< trim END
|
||||||
|
let l = test_null_list()
|
||||||
|
py3 ll = vim.bindeval('l')
|
||||||
|
END
|
||||||
|
call AssertException(cmds,
|
||||||
|
\ 'Vim(py3):SystemError: <built-in function bindeval> returned NULL without setting an error')
|
||||||
|
|
||||||
let l = []
|
let l = []
|
||||||
py3 l = vim.bindeval('l')
|
py3 l = vim.bindeval('l')
|
||||||
py3 f = vim.bindeval('function("strlen")')
|
py3 f = vim.bindeval('function("strlen")')
|
||||||
@@ -447,6 +555,39 @@ func Test_python3_list()
|
|||||||
call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l)
|
call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l)
|
||||||
py3 l[-2] = f
|
py3 l[-2] = f
|
||||||
call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l)
|
call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l)
|
||||||
|
|
||||||
|
" appending to a list
|
||||||
|
let l = [1, 2]
|
||||||
|
py3 ll = vim.bindeval('l')
|
||||||
|
py3 ll[2] = 8
|
||||||
|
call assert_equal([1, 2, 8], l)
|
||||||
|
|
||||||
|
" Using dict as an index
|
||||||
|
call AssertException(['py3 ll[{}] = 10'],
|
||||||
|
\ 'Vim(py3):TypeError: index must be int or slice, not dict')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for the python Dict object
|
||||||
|
func Test_python3_dict()
|
||||||
|
" Try to convert a null Dict
|
||||||
|
call AssertException(["py3 t = vim.eval('test_null_dict()')"],
|
||||||
|
\ 'Vim(py3):SystemError: <built-in function eval> returned NULL without setting an error')
|
||||||
|
|
||||||
|
" Try to convert a Dict with a null List value
|
||||||
|
call AssertException(["py3 t = vim.eval(\"{'a' : test_null_list()}\")"],
|
||||||
|
\ 'Vim(py3):SystemError: <built-in function eval> returned NULL without setting an error')
|
||||||
|
|
||||||
|
" Try to convert a Dict with a null string key
|
||||||
|
py3 t = vim.eval("{test_null_string() : 10}")
|
||||||
|
call assert_fails("let d = py3eval('t')", 'E859:')
|
||||||
|
|
||||||
|
" Dict length
|
||||||
|
let d = {'a' : 10, 'b' : 20}
|
||||||
|
py3 d = vim.bindeval('d')
|
||||||
|
call assert_equal(2, py3eval('len(d)'))
|
||||||
|
|
||||||
|
" Deleting an non-existing key
|
||||||
|
call AssertException(["py3 del d['c']"], "Vim(py3):KeyError: 'c'")
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Extending Dictionary directly with different types
|
" Extending Dictionary directly with different types
|
||||||
@@ -472,6 +613,12 @@ func Test_python3_dict_extend()
|
|||||||
di.sort(key=repr)
|
di.sort(key=repr)
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
" Try extending a locked dictionary
|
||||||
|
lockvar d
|
||||||
|
call AssertException(["py3 d.update({'b' : 20})"],
|
||||||
|
\ 'Vim(py3):vim.error: dictionary is locked')
|
||||||
|
unlockvar d
|
||||||
|
|
||||||
call assert_equal(1, py3eval("d['f'](self={})"))
|
call assert_equal(1, py3eval("d['f'](self={})"))
|
||||||
call assert_equal("[b'-1', b'0', b'1', b'b', b'f']", py3eval('repr(dk)'))
|
call assert_equal("[b'-1', b'0', b'1', b'b', b'f']", py3eval('repr(dk)'))
|
||||||
call assert_equal("[-1, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >, b'asd']", substitute(py3eval('repr(dv)'),'0x\x\+','','g'))
|
call assert_equal("[-1, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >, b'asd']", substitute(py3eval('repr(dv)'),'0x\x\+','','g'))
|
||||||
@@ -668,6 +815,10 @@ func Test_python3_lockedvar()
|
|||||||
EOF
|
EOF
|
||||||
call assert_equal(['', "l[2] threw vim.error: error:('list is locked',)"],
|
call assert_equal(['', "l[2] threw vim.error: error:('list is locked',)"],
|
||||||
\ getline(1, '$'))
|
\ getline(1, '$'))
|
||||||
|
|
||||||
|
" Try to concatenate a locked list
|
||||||
|
call AssertException(['py3 l += [4, 5]'], 'Vim(py3):vim.error: list is locked')
|
||||||
|
|
||||||
call assert_equal([0, 1, 2, 3], l)
|
call assert_equal([0, 1, 2, 3], l)
|
||||||
unlockvar! l
|
unlockvar! l
|
||||||
close!
|
close!
|
||||||
@@ -785,6 +936,11 @@ func Test_python3_lock_scope_attr()
|
|||||||
call assert_equal([0], l)
|
call assert_equal([0], l)
|
||||||
call assert_equal([1], ll)
|
call assert_equal([1], ll)
|
||||||
unlet l ll
|
unlet l ll
|
||||||
|
|
||||||
|
" Try changing an attribute of a fixed list
|
||||||
|
py3 a = vim.bindeval('v:argv')
|
||||||
|
call AssertException(['py3 a.locked = 0'],
|
||||||
|
\ 'Vim(py3):TypeError: cannot modify fixed list')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for py3eval()
|
" Test for py3eval()
|
||||||
@@ -799,48 +955,44 @@ func Test_python3_pyeval()
|
|||||||
call assert_equal(v:none, py3eval('None'))
|
call assert_equal(v:none, py3eval('None'))
|
||||||
call assert_equal('', v:errmsg)
|
call assert_equal('', v:errmsg)
|
||||||
|
|
||||||
|
py3 v = vim.eval('test_null_function()')
|
||||||
|
call assert_equal(v:none, py3eval('v'))
|
||||||
|
|
||||||
if has('float')
|
if has('float')
|
||||||
call assert_equal(0.0, py3eval('0.0'))
|
call assert_equal(0.0, py3eval('0.0'))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Invalid values:
|
" Evaluate an invalid values
|
||||||
let caught_859 = 0
|
call AssertException(['let v = py3eval(''"\0"'')'], 'E859:')
|
||||||
try
|
call AssertException(['let v = py3eval(''{"\0" : 1}'')'], 'E859:')
|
||||||
let v = py3eval('"\0"')
|
call AssertException(['let v = py3eval("undefined_name")'],
|
||||||
catch /E859:/
|
\ "Vim(let):NameError: name 'undefined_name' is not defined")
|
||||||
let caught_859 = 1
|
call AssertException(['let v = py3eval("vim")'], 'E859:')
|
||||||
endtry
|
endfunc
|
||||||
call assert_equal(1, caught_859)
|
|
||||||
|
|
||||||
let caught_859 = 0
|
" Test for vim.bindeval()
|
||||||
try
|
func Test_python3_vim_bindeval()
|
||||||
let v = py3eval('{"\0" : 1}')
|
" Float
|
||||||
catch /E859:/
|
let f = 3.14
|
||||||
let caught_859 = 1
|
py3 f = vim.bindeval('f')
|
||||||
endtry
|
call assert_equal(3.14, py3eval('f'))
|
||||||
call assert_equal(1, caught_859)
|
|
||||||
|
|
||||||
let caught_nameerr = 0
|
" Blob
|
||||||
try
|
let b = 0z12
|
||||||
let v = py3eval("undefined_name")
|
py3 b = vim.bindeval('b')
|
||||||
catch /NameError: name 'undefined_name'/
|
call assert_equal("\x12", py3eval('b'))
|
||||||
let caught_nameerr = 1
|
|
||||||
endtry
|
|
||||||
call assert_equal(1, caught_nameerr)
|
|
||||||
|
|
||||||
let caught_859 = 0
|
" Bool
|
||||||
try
|
call assert_equal(1, py3eval("vim.bindeval('v:true')"))
|
||||||
let v = py3eval("vim")
|
call assert_equal(0, py3eval("vim.bindeval('v:false')"))
|
||||||
catch /E859:/
|
call assert_equal(v:none, py3eval("vim.bindeval('v:null')"))
|
||||||
let caught_859 = 1
|
call assert_equal(v:none, py3eval("vim.bindeval('v:none')"))
|
||||||
endtry
|
|
||||||
call assert_equal(1, caught_859)
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" threading
|
" threading
|
||||||
" Running py3do command (Test_pydo) before this test, stops the python thread
|
" Running py3do command (Test_pydo) before this test, stops the python thread
|
||||||
" from running. So this test should be run before the pydo test
|
" from running. So this test should be run before the pydo test
|
||||||
func Test_aaa_python_threading()
|
func Test_aaa_python3_threading()
|
||||||
let l = [0]
|
let l = [0]
|
||||||
py3 l = vim.bindeval('l')
|
py3 l = vim.bindeval('l')
|
||||||
py3 << trim EOF
|
py3 << trim EOF
|
||||||
@@ -932,7 +1084,24 @@ func Test_python3_list_slice()
|
|||||||
call assert_equal([0, 2, 4], py3eval('l'))
|
call assert_equal([0, 2, 4], py3eval('l'))
|
||||||
py3 l = ll[4:2:1]
|
py3 l = ll[4:2:1]
|
||||||
call assert_equal([], py3eval('l'))
|
call assert_equal([], py3eval('l'))
|
||||||
|
|
||||||
|
" Error case: Use an invalid index
|
||||||
|
call AssertException(['py3 ll[-10] = 5'], 'Vim(py3):vim.error: internal error:')
|
||||||
|
|
||||||
|
" Use a step value of 0
|
||||||
|
call AssertException(['py3 ll[0:3:0] = [1, 2, 3]'],
|
||||||
|
\ 'Vim(py3):ValueError: slice step cannot be zero')
|
||||||
|
|
||||||
|
" Error case: Invalid slice type
|
||||||
|
call AssertException(["py3 x = ll['abc']"],
|
||||||
|
\ "Vim(py3):TypeError: index must be int or slice, not str")
|
||||||
py3 del l
|
py3 del l
|
||||||
|
|
||||||
|
" Error case: List with a null list item
|
||||||
|
let l = [test_null_list()]
|
||||||
|
py3 ll = vim.bindeval('l')
|
||||||
|
call AssertException(["py3 x = ll[:]"],
|
||||||
|
\ "Vim(py3):SystemError: error return without exception set")
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Vars
|
" Vars
|
||||||
@@ -1369,6 +1538,24 @@ func Test_python3_opts()
|
|||||||
|
|
||||||
call assert_equal(expected, g:res)
|
call assert_equal(expected, g:res)
|
||||||
unlet g:res
|
unlet g:res
|
||||||
|
|
||||||
|
call assert_equal(0, py3eval("'' in vim.options"))
|
||||||
|
|
||||||
|
" use an empty key to index vim.options
|
||||||
|
call AssertException(["let v = py3eval(\"vim.options['']\")"],
|
||||||
|
\ 'Vim(let):ValueError: empty keys are not allowed')
|
||||||
|
call AssertException(["py3 vim.current.window.options[''] = 0"],
|
||||||
|
\ 'Vim(py3):ValueError: empty keys are not allowed')
|
||||||
|
call AssertException(["py3 vim.current.window.options[{}] = 0"],
|
||||||
|
\ 'Vim(py3):TypeError: expected bytes() or str() instance, but got dict')
|
||||||
|
|
||||||
|
" set one of the number options to a very large number
|
||||||
|
let cmd = ["py3 vim.options['previewheight'] = 9999999999999999"]
|
||||||
|
call AssertException(cmd, "Vim(py3):OverflowError:")
|
||||||
|
|
||||||
|
" unset a global-local string option
|
||||||
|
call AssertException(["py3 del vim.options['errorformat']"],
|
||||||
|
\ 'Vim(py3):ValueError: unable to unset global option errorformat')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for vim.buffer object
|
" Test for vim.buffer object
|
||||||
@@ -1387,11 +1574,26 @@ func Test_python3_buffer()
|
|||||||
py3 b = vim.current.buffer
|
py3 b = vim.current.buffer
|
||||||
wincmd w
|
wincmd w
|
||||||
|
|
||||||
|
" Test for getting lines from the buffer using a slice
|
||||||
|
call assert_equal(['First line'], py3eval('b[-10:1]'))
|
||||||
|
call assert_equal(['Third line'], py3eval('b[2:10]'))
|
||||||
|
call assert_equal([], py3eval('b[2:0]'))
|
||||||
|
call assert_equal([], py3eval('b[10:12]'))
|
||||||
|
call assert_equal([], py3eval('b[-10:-8]'))
|
||||||
|
|
||||||
" Tests BufferAppend and BufferItem
|
" Tests BufferAppend and BufferItem
|
||||||
py3 cb.append(b[0])
|
py3 cb.append(b[0])
|
||||||
call assert_equal(['First line'], getbufline(bnr1, 2))
|
call assert_equal(['First line'], getbufline(bnr1, 2))
|
||||||
%d
|
%d
|
||||||
|
|
||||||
|
" Try to append using out-of-range line number
|
||||||
|
call AssertException(["py3 b.append('abc', 10)"],
|
||||||
|
\ 'Vim(py3):IndexError: line number out of range')
|
||||||
|
|
||||||
|
" Append a non-string item
|
||||||
|
call AssertException(["py3 b.append([22])"],
|
||||||
|
\ 'Vim(py3):TypeError: expected bytes() or str() instance, but got int')
|
||||||
|
|
||||||
" Tests BufferSlice and BufferAssSlice
|
" Tests BufferSlice and BufferAssSlice
|
||||||
py3 cb.append('abc5') # Will be overwritten
|
py3 cb.append('abc5') # Will be overwritten
|
||||||
py3 cb[-1:] = b[:-2]
|
py3 cb[-1:] = b[:-2]
|
||||||
@@ -1483,11 +1685,62 @@ func Test_python3_buffer()
|
|||||||
EOF
|
EOF
|
||||||
call assert_equal([''], getline(1, '$'))
|
call assert_equal([''], getline(1, '$'))
|
||||||
|
|
||||||
|
" Delete all the lines in a buffer
|
||||||
|
call setline(1, ['a', 'b', 'c'])
|
||||||
|
py3 vim.current.buffer[:] = []
|
||||||
|
call assert_equal([''], getline(1, '$'))
|
||||||
|
|
||||||
|
" Test for modifying a 'nomodifiable' buffer
|
||||||
|
setlocal nomodifiable
|
||||||
|
call AssertException(["py3 vim.current.buffer[0] = 'abc'"],
|
||||||
|
\ "Vim(py3):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py3 vim.current.buffer[0] = None"],
|
||||||
|
\ "Vim(py3):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py3 vim.current.buffer[:] = None"],
|
||||||
|
\ "Vim(py3):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py3 vim.current.buffer[:] = []"],
|
||||||
|
\ "Vim(py3):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py3 vim.current.buffer.append('abc')"],
|
||||||
|
\ "Vim(py3):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
call AssertException(["py3 vim.current.buffer.append([])"],
|
||||||
|
\ "Vim(py3):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off")
|
||||||
|
setlocal modifiable
|
||||||
|
|
||||||
augroup BUFS
|
augroup BUFS
|
||||||
autocmd!
|
autocmd!
|
||||||
augroup END
|
augroup END
|
||||||
augroup! BUFS
|
augroup! BUFS
|
||||||
%bw!
|
%bw!
|
||||||
|
|
||||||
|
" Range object for a deleted buffer
|
||||||
|
new Xfile
|
||||||
|
call setline(1, ['one', 'two', 'three'])
|
||||||
|
py3 b = vim.current.buffer
|
||||||
|
py3 r = vim.current.buffer.range(0, 2)
|
||||||
|
call assert_equal('<range Xfile (0:2)>', py3eval('repr(r)'))
|
||||||
|
%bw!
|
||||||
|
call AssertException(['py3 r[:] = []'],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call assert_match('<buffer object (deleted)', py3eval('repr(b)'))
|
||||||
|
call assert_match('<range object (for deleted buffer)', py3eval('repr(r)'))
|
||||||
|
call AssertException(["let n = py3eval('len(r)')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py3 r.append('abc')"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
|
|
||||||
|
" object for a deleted buffer
|
||||||
|
call AssertException(["py3 b[0] = 'one'"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py3 b.append('one')"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["let n = py3eval('len(b)')"],
|
||||||
|
\ 'Vim(let):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py3 pos = b.mark('a')"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py3 vim.current.buffer = b"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
|
call AssertException(["py3 rn = b.range(0, 2)"],
|
||||||
|
\ 'Vim(py3):vim.error: attempt to refer to deleted buffer')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test vim.buffers object
|
" Test vim.buffers object
|
||||||
@@ -1731,6 +1984,8 @@ func Test_python3_vim_current()
|
|||||||
Current line: 'python interface'
|
Current line: 'python interface'
|
||||||
END
|
END
|
||||||
call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
|
call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
|
||||||
|
py3 vim.current.line = 'one line'
|
||||||
|
call assert_equal('one line', getline('.'))
|
||||||
call deletebufline(bufnr('Xfile'), 1, '$')
|
call deletebufline(bufnr('Xfile'), 1, '$')
|
||||||
|
|
||||||
py3 << trim EOF
|
py3 << trim EOF
|
||||||
@@ -1853,11 +2108,11 @@ endfunc
|
|||||||
|
|
||||||
" Test vim.Function
|
" Test vim.Function
|
||||||
func Test_python3_vim_func()
|
func Test_python3_vim_func()
|
||||||
function Args(...)
|
func Args(...)
|
||||||
return a:000
|
return a:000
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
function SelfArgs(...) dict
|
func SelfArgs(...) dict
|
||||||
return [a:000, self]
|
return [a:000, self]
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@@ -1867,6 +2122,8 @@ func Test_python3_vim_func()
|
|||||||
unlet Pt
|
unlet Pt
|
||||||
py3 del Pt
|
py3 del Pt
|
||||||
|
|
||||||
|
call assert_equal(3, py3eval('vim.strwidth("a\tb")'))
|
||||||
|
|
||||||
%bw!
|
%bw!
|
||||||
py3 cb = vim.current.buffer
|
py3 cb = vim.current.buffer
|
||||||
py3 << trim EOF
|
py3 << trim EOF
|
||||||
@@ -2309,7 +2566,6 @@ func Test_python3_chdir()
|
|||||||
cb.append(str(fnamemodify('.', ':p:h:t')))
|
cb.append(str(fnamemodify('.', ':p:h:t')))
|
||||||
cb.append(vim.eval('@%')[len(path)+1:].replace(os.path.sep, '/'))
|
cb.append(vim.eval('@%')[len(path)+1:].replace(os.path.sep, '/'))
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
del path
|
|
||||||
else:
|
else:
|
||||||
cb.append(str(fnamemodify('.', ':p:h:t')))
|
cb.append(str(fnamemodify('.', ':p:h:t')))
|
||||||
cb.append(vim.eval('@%').replace(os.path.sep, '/'))
|
cb.append(vim.eval('@%').replace(os.path.sep, '/'))
|
||||||
@@ -3579,6 +3835,9 @@ func Test_python3_import()
|
|||||||
END
|
END
|
||||||
call assert_equal(expected, getline(2, '$'))
|
call assert_equal(expected, getline(2, '$'))
|
||||||
close!
|
close!
|
||||||
|
|
||||||
|
" Try to import a non-existing moudle with a dot (.)
|
||||||
|
call AssertException(['py3 import a.b.c'], "No module named 'a'")
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test exceptions
|
" Test exceptions
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1146,
|
||||||
/**/
|
/**/
|
||||||
1145,
|
1145,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user