From 4f2d36194b4f299aa7509d815c07121039ea833b Mon Sep 17 00:00:00 2001 From: Mehmet Samet Duman Date: Sat, 4 Apr 2026 12:41:27 +0300 Subject: NOISSUE change uvim folder name to mnv Signed-off-by: Mehmet Samet Duman --- mnv/src/testdir/test_python3.mnv | 4413 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 4413 insertions(+) create mode 100644 mnv/src/testdir/test_python3.mnv (limited to 'mnv/src/testdir/test_python3.mnv') diff --git a/mnv/src/testdir/test_python3.mnv b/mnv/src/testdir/test_python3.mnv new file mode 100644 index 0000000000..e239571b61 --- /dev/null +++ b/mnv/src/testdir/test_python3.mnv @@ -0,0 +1,4413 @@ +" Test for python 3 commands. + +CheckFeature python3 + +func Create_mnv_list() + return [1] +endfunction + +func Create_mnv_tuple() + return ('a', 'b') +endfunction + +func Create_mnv_dict() + return {'a': 1} +endfunction + +let s:system_error_pat = 'MNV(py3):SystemError: \( returned NULL without setting an \(error\|exception\)\|error return without exception set\)' + +" This function should be called first. This sets up python functions used by +" the other tests. +func Test_AAA_python3_setup() + py3 << trim EOF + import mnv + import sys + import re + + py33_type_error_pattern = re.compile(r'^__call__\(\) takes (\d+) positional argument but (\d+) were given$') + py37_exception_repr = re.compile(r'([^\(\),])(\)+)$') + py39_type_error_pattern = re.compile(r'\w+\.([^(]+\(\) takes)') + py310_type_error_pattern = re.compile(r'takes (\d+) positional argument but (\d+) were given') + py314_type_error_tuple_pattern = re.compile(r'must be (\d+)-item tuple') + + def emsg(ei): + return ei[0].__name__ + ':' + repr(ei[1].args) + + def ee(expr, g=globals(), l=locals()): + cb = mnv.current.buffer + try: + try: + exec(expr, g, l) + except Exception as e: + if sys.version_info >= (3, 3) and e.__class__ is AttributeError and str(e).find('has no attribute')>=0 and not str(e).startswith("'mnv."): + msg = repr((e.__class__, AttributeError(str(e)[str(e).rfind(" '") + 2:-1]))) + elif sys.version_info >= (3, 3) and e.__class__ is ImportError and str(e).find('No module named \'') >= 0: + msg = repr((e.__class__, ImportError(str(e).replace("'", '')))) + elif sys.version_info >= (3, 6) and e.__class__ is ModuleNotFoundError: + # Python 3.6 gives ModuleNotFoundError, change it to an ImportError + msg = repr((ImportError, ImportError(str(e).replace("'", '')))) + elif sys.version_info >= (3, 3) and e.__class__ is TypeError: + m = py33_type_error_pattern.search(str(e)) + if m: + msg = '__call__() takes exactly {0} positional argument ({1} given)'.format(m.group(1), m.group(2)) + msg = repr((e.__class__, TypeError(msg))) + else: + msg = repr((e.__class__, e)) + # Messages changed with Python 3.6, change new to old. + newmsg1 = """'argument must be str, bytes or bytearray, not None'""" + oldmsg1 = '''"Can't convert 'NoneType' object to str implicitly"''' + if msg.find(newmsg1) > -1: + msg = msg.replace(newmsg1, oldmsg1) + newmsg2 = """'argument must be str, bytes or bytearray, not int'""" + oldmsg2 = '''"Can't convert 'int' object to str implicitly"''' + if msg.find(newmsg2) > -1: + msg = msg.replace(newmsg2, oldmsg2) + # Python 3.9 reports errors like "mnv.command() takes ..." instead of "command() takes ..." + msg = py39_type_error_pattern.sub(r'\1', msg) + msg = py310_type_error_pattern.sub(r'takes exactly \1 positional argument (\2 given)', msg) + # Python 3.14 has specific error messages for Tuple's + msg = py314_type_error_tuple_pattern.sub(r'must be \1-item sequence', msg) + elif sys.version_info >= (3, 5) and e.__class__ is ValueError and str(e) == 'embedded null byte': + msg = repr((TypeError, TypeError('expected bytes with no null'))) + else: + msg = repr((e.__class__, e)) + # Some Python versions say can't, others cannot. + if msg.find('can\'t') > -1: + msg = msg.replace('can\'t', 'cannot') + # Some Python versions use single quote, some double quote + if msg.find('"cannot ') > -1: + msg = msg.replace('"cannot ', '\'cannot ') + if msg.find(' attributes"') > -1: + msg = msg.replace(' attributes"', ' attributes\'') + if sys.version_info >= (3, 7): + msg = py37_exception_repr.sub(r'\1,\2', msg) + cb.append(expr + ':' + msg) + else: + cb.append(expr + ':NOT FAILED') + except Exception as e: + msg = repr((e.__class__, e)) + if sys.version_info >= (3, 7): + msg = py37_exception_repr.sub(r'\1,\2', msg) + cb.append(expr + '::' + msg) + EOF +endfunc + +func Test_py3do() + new + + " Check deleting lines does not trigger an ml_get error. + call setline(1, ['one', 'two', 'three']) + py3do mnv.command("%d_") + call assert_equal([''], getline(1, '$')) + + call setline(1, ['one', 'two', 'three']) + py3do mnv.command("1,2d_") + call assert_equal(['three'], getline(1, '$')) + + call setline(1, ['one', 'two', 'three']) + py3do mnv.command("2,3d_"); return "REPLACED" + call assert_equal(['REPLACED'], getline(1, '$')) + + call setline(1, ['one', 'two', 'three']) + 2,3py3do mnv.command("1,2d_"); return "REPLACED" + call assert_equal(['three'], getline(1, '$')) + + bwipe! + + " Check switching to another buffer does not trigger an ml_get error. + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + py3do mnv.command("new") + call assert_equal(wincount + 1, winnr('$')) + bwipe! + bwipe! + + " Try modifying a buffer with 'nomodifiable' set + set nomodifiable + call assert_fails('py3do toupper(line)', 'E21:') + set modifiable + + " Invalid command + call AssertException(['py3do non_existing_cmd'], + \ "MNV(py3do):NameError: name 'non_existing_cmd' is not defined") + call AssertException(["py3do raise Exception('test')"], + \ 'MNV(py3do):Exception: test') + call AssertException(["py3do {lambda}"], + \ 'MNV(py3do):SyntaxError: invalid syntax') +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + new + call setline(1, ['first line', 'second line']) + normal gg + py3do mnv.current.window.cursor = (1, 5) + call assert_equal([1, 6], [line('.'), col('.')]) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 6], [line('.'), col('.')]) +endfunc + +func Test_mnv_function() + " Check creating mnv.Function object + + func s:foo() + return matchstr(expand(''), '\zs\d\+_foo$') + endfunc + let name = '' . s:foo() + + try + py3 f = mnv.bindeval('function("s:foo")') + call assert_equal(name, py3eval('f.name')) + catch + call assert_false(v:exception) + endtry + + try + py3 f = mnv.Function(b'\x80\xfdR' + mnv.eval('s:foo()').encode()) + call assert_equal(name, 'f.name'->py3eval()) + catch + call assert_false(v:exception) + endtry + + " Non-existing function attribute + call AssertException(["let x = py3eval('f.abc')"], + \ "MNV(let):AttributeError: 'mnv.function' object has no attribute 'abc'") + + py3 del f + delfunc s:foo +endfunc + +func Test_skipped_python3_command_does_not_affect_pyxversion() + set pyxversion=0 + if 0 + python3 import mnv + endif + call assert_equal(0, &pyxversion) " This assertion would have failed with MNV 8.0.0251. (pyxversion was introduced in 8.0.0251.) +endfunc + +func _SetUpHiddenBuffer() + new + edit hidden + setlocal bufhidden=hide + + enew + let lnum = 0 + while lnum < 10 + call append( 1, string( lnum ) ) + let lnum = lnum + 1 + endwhile + normal G + + call assert_equal( line( '.' ), 11 ) +endfunc + +func _CleanUpHiddenBuffer() + bwipe! hidden + bwipe! +endfunc + +func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear() + call _SetUpHiddenBuffer() + py3 mnv.buffers[ int( mnv.eval( 'bufnr("hidden")' ) ) ][:] = None + call assert_equal( line( '.' ), 11 ) + call _CleanUpHiddenBuffer() +endfunc + +func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List() + call _SetUpHiddenBuffer() + py3 mnv.buffers[ int( mnv.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ] + call assert_equal( line( '.' ), 11 ) + call _CleanUpHiddenBuffer() +endfunc + +func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str() + call _SetUpHiddenBuffer() + py3 mnv.buffers[ int( mnv.eval( 'bufnr("hidden")' ) ) ][0] = 'test' + call assert_equal( line( '.' ), 11 ) + call _CleanUpHiddenBuffer() +endfunc + +func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine() + call _SetUpHiddenBuffer() + py3 mnv.buffers[ int( mnv.eval( 'bufnr("hidden")' ) ) ][0] = None + call assert_equal( line( '.' ), 11 ) + call _CleanUpHiddenBuffer() +endfunc + +func _SetUpVisibleBuffer() + new + let lnum = 0 + while lnum < 10 + call append( 1, string( lnum ) ) + let lnum = lnum + 1 + endwhile + normal G + call assert_equal( line( '.' ), 11 ) +endfunc + +func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear() + call _SetUpVisibleBuffer() + + py3 mnv.current.buffer[:] = None + call assert_equal( line( '.' ), 1 ) + + bwipe! +endfunc + +func Test_Write_To_Current_Buffer_Fixes_Cursor_List() + call _SetUpVisibleBuffer() + + py3 mnv.current.buffer[:] = [ 'test' ] + call assert_equal( line( '.' ), 1 ) + + bwipe! +endfunc + +func Test_Write_To_Current_Buffer_Fixes_Cursor_Str() + call _SetUpVisibleBuffer() + + py3 mnv.current.buffer[-1] = None + call assert_equal( line( '.' ), 10 ) + + bwipe! +endfunc + +func Test_Catch_Exception_Message() + try + py3 raise RuntimeError( 'TEST' ) + catch /.*/ + call assert_match( '^MNV(.*):RuntimeError: TEST$', v:exception ) + endtry +endfunc + +func Test_unicode() + " this crashed MNV once + if &tenc != '' + throw "Skipped: 'termencoding' is not empty" + endif + + set encoding=utf32 + py3 print('hello') + + if !has('win32') + set encoding=debug + py3 print('hello') + + set encoding=euc-tw + py3 print('hello') + endif + + set encoding=utf8 +endfunc + +" Test mnv.eval() with various types. +func Test_python3_mnv_eval() + call assert_equal("\n2061300532912", execute('py3 print(mnv.eval("2061300532912"))')) + call assert_equal("\n9223372036854775807", execute('py3 print(mnv.eval("9223372036854775807"))')) + call assert_equal("\n-9223372036854775807",execute('py3 print(mnv.eval("-9223372036854775807"))')) + call assert_equal("\n2147483648", execute('py3 print(mnv.eval("2147483648"))')) + call assert_equal("\n-2147483649", execute('py3 print(mnv.eval("-2147483649"))')) + call assert_equal("\n8", execute('py3 print(mnv.eval("3+5"))')) + call assert_equal("\n3.140000", execute('py3 print(mnv.eval("1.01+2.13"))')) + call assert_equal("\n0.000000", execute('py3 print(mnv.eval("0.0/(1.0/0.0)"))')) + call assert_equal("\n0.000000", execute('py3 print(mnv.eval("0.0/(1.0/0.0)"))')) + call assert_equal("\n-0.000000", execute('py3 print(mnv.eval("0.0/(-1.0/0.0)"))')) + " Commented out: output of infinity and nan depend on platforms. + " call assert_equal("\ninf", execute('py3 print(mnv.eval("1.0/0.0"))')) + " call assert_equal("\n-inf", execute('py3 print(mnv.eval("-1.0/0.0"))')) + " call assert_equal("\n-nan", execute('py3 print(mnv.eval("0.0/0.0"))')) + call assert_equal("\nabc", execute('py3 print(mnv.eval("\"abc\""))')) + call assert_equal("\n['1', '2']", execute('py3 print(mnv.eval("[1, 2]"))')) + call assert_equal("\n{'1': '2'}", execute('py3 print(mnv.eval("{1:2}"))')) + call assert_equal("\nTrue", execute('py3 print(mnv.eval("v:true"))')) + call assert_equal("\nFalse", execute('py3 print(mnv.eval("v:false"))')) + call assert_equal("\nNone", execute('py3 print(mnv.eval("v:null"))')) + call assert_equal("\nNone", execute('py3 print(mnv.eval("v:none"))')) + call assert_equal("\nb'\\xab\\x12'", execute('py3 print(mnv.eval("0zab12"))')) + + call assert_fails('py3 mnv.eval("1+")', 'E15: Invalid expression') +endfunc + +" Test range objects, see :help python-range +func Test_python3_range() + new + py3 b = mnv.current.buffer + + call setline(1, range(1, 6)) + py3 r = b.range(2, 4) + call assert_equal(6, py3eval('len(b)')) + call assert_equal(3, py3eval('len(r)')) + call assert_equal('3', py3eval('b[2]')) + call assert_equal('4', py3eval('r[2]')) + + call assert_fails('py3 r[3] = "x"', ['Traceback', 'IndexError: line number out of range']) + call assert_fails('py3 x = r[3]', ['Traceback', 'IndexError: line number out of range']) + call assert_fails('py3 r["a"] = "x"', ['Traceback', 'TypeError: index must be int or slice, not str']) + call assert_fails('py3 x = r["a"]', ['Traceback', 'TypeError: index must be int or slice, not str']) + + py3 del r[:] + call assert_equal(['1', '5', '6'], getline(1, '$')) + + %d | call setline(1, range(1, 6)) + py3 r = b.range(2, 5) + py3 del r[2] + call assert_equal(['1', '2', '3', '5', '6'], getline(1, '$')) + + %d | call setline(1, range(1, 6)) + py3 r = b.range(2, 4) + py3 mnv.command("%d,%dnorm Ax" % (r.start + 1, r.end + 1)) + call assert_equal(['1', '2x', '3x', '4x', '5', '6'], getline(1, '$')) + + %d | call setline(1, range(1, 4)) + py3 r = b.range(2, 3) + py3 r.append(['a', 'b']) + call assert_equal(['1', '2', '3', 'a', 'b', '4'], getline(1, '$')) + py3 r.append(['c', 'd'], 0) + call assert_equal(['1', 'c', 'd', '2', '3', 'a', 'b', '4'], getline(1, '$')) + + %d | call setline(1, range(1, 5)) + py3 r = b.range(2, 4) + py3 r.append('a') + call assert_equal(['1', '2', '3', '4', 'a', '5'], getline(1, '$')) + py3 r.append('b', 1) + call assert_equal(['1', '2', 'b', '3', '4', 'a', '5'], getline(1, '$')) + + bwipe! +endfunc + +" Test for resetting options with local values to global values +func Test_python3_opt_reset_local_to_global() + new + + py3 curbuf = mnv.current.buffer + py3 curwin = mnv.current.window + + " List of buffer-local options. Each list item has [option name, global + " value, buffer-local value, buffer-local value after reset] to use in the + " test. + let bopts = [ + \ ['autoread', 1, 0, -1], + \ ['equalprg', 'geprg', 'leprg', ''], + \ ['keywordprg', 'gkprg', 'lkprg', ''], + \ ['path', 'gpath', 'lpath', ''], + \ ['backupcopy', 'yes', 'no', ''], + \ ['tags', 'gtags', 'ltags', ''], + \ ['tagcase', 'ignore', 'match', ''], + \ ['define', 'gdef', 'ldef', ''], + \ ['include', 'ginc', 'linc', ''], + \ ['dict', 'gdict', 'ldict', ''], + \ ['thesaurus', 'gtsr', 'ltsr', ''], + \ ['thesaurusfunc', 'Gtsrfu', 'Ltsrfu', ''], + \ ['formatprg', 'gfprg', 'lfprg', ''], + \ ['errorformat', '%f:%l:%m', '%s-%l-%m', ''], + \ ['grepprg', 'ggprg', 'lgprg', ''], + \ ['makeprg', 'gmprg', 'lmprg', ''], + \ ['cryptmethod', 'blowfish2', 'zip', ''], + \ ['lispwords', 'abc', 'xyz', ''], + \ ['makeencoding', 'utf-8', 'latin1', ''], + \ ['undolevels', 100, 200, -123456]] + if has('balloon_eval') + call add(bopts, ['balloonexpr', 'gbexpr', 'lbexpr', '']) + endif + + " Set the global and buffer-local option values and then clear the + " buffer-local option value. + for opt in bopts + py3 << trim END + pyopt = mnv.bindeval("opt") + mnv.options[pyopt[0]] = pyopt[1] + curbuf.options[pyopt[0]] = pyopt[2] + END + exe "call assert_equal(opt[2], &" .. opt[0] .. ")" + exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")" + exe "call assert_equal(opt[2], &l:" .. opt[0] .. ")" + py3 del curbuf.options[pyopt[0]] + exe "call assert_equal(opt[1], &" .. opt[0] .. ")" + exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")" + exe "call assert_equal(opt[3], &l:" .. opt[0] .. ")" + exe "set " .. opt[0] .. "&" + endfor + + " Set the global and window-local option values and then clear the + " window-local option value. + let wopts = [ + \ ['fillchars', 'fold:>', 'fold:+', ''], + \ ['listchars', 'tab:>>', 'tab:--', ''], + \ ['scrolloff', 5, 10, -1], + \ ['showbreak', '>>', '++', ''], + \ ['sidescrolloff', 6, 12, -1], + \ ['statusline', '%<%f', '%<%F', ''], + \ ['virtualedit', 'block', 'insert', '']] + for opt in wopts + py3 << trim + pyopt = mnv.bindeval("opt") + mnv.options[pyopt[0]] = pyopt[1] + curwin.options[pyopt[0]] = pyopt[2] + . + exe "call assert_equal(opt[2], &" .. opt[0] .. ")" + exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")" + exe "call assert_equal(opt[2], &l:" .. opt[0] .. ")" + py3 del curwin.options[pyopt[0]] + exe "call assert_equal(opt[1], &" .. opt[0] .. ")" + exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")" + exe "call assert_equal(opt[3], &l:" .. opt[0] .. ")" + exe "set " .. opt[0] .. "&" + endfor + + close! +endfunc + +" Test for various heredoc syntax +func Test_python3_heredoc() + python3 << END +s='A' +END + python3 << +s+='B' +. + python3 << trim END + s+='C' + END + python3 << trim + s+='D' + . + python3 << trim eof + s+='E' + eof + python3 << trimm +s+='F' +trimm + call assert_equal('ABCDEF', pyxeval('s')) +endfunc + +" Test for the buffer range object +func Test_python3_range2() + new + call setline(1, ['one', 'two', 'three']) + py3 b = mnv.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]')"], + \ 'MNV(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, '$')) + + " The following code used to trigger an ml_get error + %d + let x = py3eval('r[:]') + + " Non-existing range attribute + call AssertException(["let x = py3eval('r.abc')"], + \ "MNV(let):AttributeError: 'mnv.range' object has no attribute 'abc'") + + bw! +endfunc + +" Test for the python tabpage object +func Test_python3_tabpage() + tabnew + py3 t = mnv.tabpages[1] + py3 wl = t.windows + tabclose + " Accessing a closed tabpage + call AssertException(["let n = py3eval('t.number')"], + \ 'MNV(let):mnv.error: attempt to refer to deleted tab page') + call AssertException(["let n = py3eval('len(wl)')"], + \ 'MNV(let):mnv.error: attempt to refer to deleted tab page') + call AssertException(["py3 w = wl[0]"], + \ 'MNV(py3):mnv.error: attempt to refer to deleted tab page') + call AssertException(["py3 mnv.current.tabpage = t"], + \ 'MNV(py3):mnv.error: attempt to refer to deleted tab page') + call assert_match('w_buffer +func Test_python3_window_set_height() + enew! + call setline(1, ['aaa', 'bbb', 'ccc']) + call cursor(2, 1) + set foldmethod=expr + new + wincmd w + python3 mnv.windows[0].height = 5 + call assert_equal(5, winheight(1)) + + call feedkeys('j', 'xt') + call assert_equal(3, getpos('.')[1]) + + bwipe! + bwipe! +endfunc + +" Test for the python List object +func Test_python3_list() + " Try to convert a null List + call AssertException(["py3 t = mnv.eval('test_null_list()')"], + \ s:system_error_pat) + + " Try to convert a List with a null List item + call AssertException(["py3 t = mnv.eval('[test_null_list()]')"], + \ s:system_error_pat) + + " Try to bind a null List variable (works because an empty list is used) + let cmds =<< trim END + let l = test_null_list() + py3 ll = mnv.bindeval('l') + END + call AssertException(cmds, '') + + let l = [] + py3 l = mnv.bindeval('l') + py3 f = mnv.bindeval('function("strlen")') + " Extending List directly with different types + py3 l += [1, "as'd", [1, 2, f, {'a': 1}]] + call assert_equal([1, "as'd", [1, 2, function("strlen"), {'a': 1}]], l) + call assert_equal([1, 2, function("strlen"), {'a': 1}], l[-1]) + call assert_fails('echo l[-4]', 'E684:') + + " List assignment + py3 l[0] = 0 + call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l) + py3 l[-2] = f + call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l) + + " appending to a list + let l = [1, 2] + py3 ll = mnv.bindeval('l') + py3 ll[2] = 8 + call assert_equal([1, 2, 8], l) + + " iterating over list from Python + py3 print([x for x in mnv.Function("getline")(1, 2)]) + + " Using dict as an index + call AssertException(['py3 ll[{}] = 10'], + \ 'MNV(py3):TypeError: index must be int or slice, not dict') +endfunc + +" Test for the python Tuple object +func Test_python3_tuple() + " Try to convert a null tuple + call AssertException(["py3 l = mnv.eval('test_null_tuple()')"], + \ s:system_error_pat) + + " Try to convert a Tuple with a null Tuple item + call AssertException(["py3 t = mnv.eval('(test_null_tuple(),)')"], + \ s:system_error_pat) + + " Try to convert a List with a null Tuple item + call AssertException(["py3 t = mnv.eval('[test_null_tuple()]')"], + \ s:system_error_pat) + + " Try to convert a Tuple with a null List item + call AssertException(["py3 t = mnv.eval('(test_null_list(),)')"], + \ s:system_error_pat) + + " Try to bind a null Tuple variable (works because an empty tuple is used) + let cmds =<< trim END + let t = test_null_tuple() + py3 tt = mnv.bindeval('t') + END + call AssertException(cmds, '') + + " Creating a tuple using different iterators + py3 t1 = mnv.Tuple(['abc', 20, 1.2, (4, 5)]) + call assert_equal(('abc', 20, 1.2, (4, 5)), py3eval('t1')) + py3 t2 = mnv.Tuple('abc') + call assert_equal(('a', 'b', 'c'), py3eval('t2')) + py3 t3 = mnv.Tuple({'color': 'red', 'model': 'ford'}) + call assert_equal(('color', 'model'), py3eval('t3')) + py3 t4 = mnv.Tuple() + call assert_equal((), py3eval('t4')) + py3 t5 = mnv.Tuple(x**2 for x in range(5)) + call assert_equal((0, 1, 4, 9, 16), py3eval('t5')) + py3 t6 = mnv.Tuple(('abc', 20, 1.2, (4, 5))) + call assert_equal(('abc', 20, 1.2, (4, 5)), py3eval('t6')) + + " Convert between MNV tuple/list and python tuple/list + py3 t = mnv.Tuple(mnv.bindeval("('a', ('b',), ['c'], {'s': 'd'})")) + call assert_equal(('a', ('b',), ['c'], {'s': 'd'}), py3eval('t')) + call assert_equal(['a', ('b',), ['c'], {'s': 'd'}], py3eval('list(t)')) + call assert_equal(('a', ('b',), ['c'], {'s': 'd'}), py3eval('tuple(t)')) + + py3 l = mnv.List(mnv.bindeval("['e', ('f',), ['g'], {'s': 'h'}]")) + call assert_equal(('e', ('f',), ['g'], {'s': 'h'}), py3eval('tuple(l)')) + + " Tuple assignment + py3 tt = mnv.bindeval('("a", "b")') + call AssertException(['py3 tt[0] = 10'], + \ "MNV(py3):TypeError: 'mnv.tuple' object does not support item assignment") + py3 tt = mnv.bindeval('("a", "b")') + call AssertException(['py3 tt[0:1] = (10, 20)'], + \ "MNV(py3):TypeError: 'mnv.tuple' object does not support item assignment") + + " iterating over tuple from Python + py3 print([x for x in mnv.bindeval("('a', 'b')")]) + + " modifying a list item within a tuple + let t = ('a', ['b', 'c'], 'd') + py3 mnv.bindeval('t')[1][1] = 'x' + call assert_equal(('a', ['b', 'x'], 'd'), t) + + " length of a tuple + let t = () + py3 p_t = mnv.bindeval('t') + call assert_equal(0, py3eval('len(p_t)')) + let t = ('a', ) + py3 p_t = mnv.bindeval('t') + call assert_equal(1, py3eval('len(p_t)')) + let t = ('a', 'b', 'c') + py3 p_t = mnv.bindeval('t') + call assert_equal(3, py3eval('len(p_t)')) + + " membership test + let t = ('a', 'b', 'c') + py3 p_t = mnv.bindeval('t') + call assert_true(py3eval("b'c' in p_t")) + call assert_true(py3eval("b'd' not in p_t")) + + py3 x = mnv.eval('("a", (2), [3], {})') + call assert_equal(('a', '2', ['3'], {}), py3eval('x')) + + " Using a keyword argument for a tuple + call AssertException(['py3 x = mnv.Tuple(a=1)'], + \ 'MNV(py3):TypeError: tuple constructor does not accept keyword arguments') + + " Using dict as an index + call AssertException(['py3 x = tt[{}]'], + \ 'MNV(py3):TypeError: index must be int or slice, not dict') + call AssertException(['py3 x = tt["abc"]'], + \ 'MNV(py3):TypeError: index must be int or slice, not str') + + call AssertException(['py3 del tt.locked'], + \ 'MNV(py3):AttributeError: cannot delete mnv.Tuple attributes') + + call AssertException(['py3 tt.foobar = 1'], + \ 'MNV(py3):AttributeError: cannot set attribute foobar') +endfunc + +" Test for the python Dict object +func Test_python3_dict() + " Try to convert a null Dict + call AssertException(["py3 t = mnv.eval('test_null_dict()')"], + \ s:system_error_pat) + + " Try to convert a Dict with a null List value + call AssertException(["py3 t = mnv.eval(\"{'a' : test_null_list()}\")"], + \ s:system_error_pat) + + " Try to convert a Dict with a null string key + py3 t = mnv.eval("{test_null_string() : 10}") + call assert_fails("let d = py3eval('t')", 'E859:') + + " Dict length + let d = {'a' : 10, 'b' : 20} + py3 d = mnv.bindeval('d') + call assert_equal(2, py3eval('len(d)')) + + " Deleting a non-existing key + call AssertException(["py3 del d['c']"], "MNV(py3):KeyError: 'c'") +endfunc + +" Extending Dictionary directly with different types +func Test_python3_dict_extend() + let d = {} + func d.f() + return 1 + endfunc + + py3 f = mnv.bindeval('function("strlen")') + py3 << trim EOF + d = mnv.bindeval('d') + d['1'] = 'asd' + d.update() # Must not do anything, including throwing errors + d.update(b = [1, 2, f]) + d.update((('-1', {'a': 1}),)) + d.update({'0': -1}) + dk = d.keys() + dv = d.values() + di = d.items() + dk.sort(key=repr) + dv.sort(key=repr) + di.sort(key=repr) + EOF + + " Try extending a locked dictionary + lockvar d + call AssertException(["py3 d.update({'b' : 20})"], + \ 'MNV(py3):mnv.error: dictionary is locked') + unlockvar d + + 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("[-1, , , , b'asd']", substitute(py3eval('repr(dv)'),'0x\x\+','','g')) + call assert_equal("[(b'-1', ), (b'0', -1), (b'1', b'asd'), (b'b', ), (b'f', )]", substitute(py3eval('repr(di)'),'0x\x\+','','g')) + call assert_equal(['0', '1', 'b', 'f', '-1'], keys(d)) + call assert_equal("[-1, 'asd', [1, 2, function('strlen')], function('1'), {'a': 1}]", string(values(d))) + py3 del dk + py3 del di + py3 del dv +endfunc + +func Test_python3_list_del_items() + " removing items with del + let l = [0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]] + py3 l = mnv.bindeval('l') + py3 del l[2] + call assert_equal("[0, function('strlen')]", string(l)) + + let l = range(8) + py3 l = mnv.bindeval('l') + py3 del l[:3] + py3 del l[1:] + call assert_equal([3], l) + + " removing items out of range: silently skip items that don't exist + + " The following two ranges delete nothing as they match empty list: + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[2:1] + call assert_equal([0, 1, 2, 3], l) + py3 del l[2:2] + call assert_equal([0, 1, 2, 3], l) + py3 del l[2:3] + call assert_equal([0, 1, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[2:4] + call assert_equal([0, 1], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[2:5] + call assert_equal([0, 1], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[2:6] + call assert_equal([0, 1], l) + + " The following two ranges delete nothing as they match empty list: + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[-1:2] + call assert_equal([0, 1, 2, 3], l) + py3 del l[-2:2] + call assert_equal([0, 1, 2, 3], l) + py3 del l[-3:2] + call assert_equal([0, 2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[-4:2] + call assert_equal([2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[-5:2] + call assert_equal([2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[-6:2] + call assert_equal([2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[::2] + call assert_equal([1, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[3:0:-2] + call assert_equal([0, 2], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 del l[2:4:-2] + let l = [0, 1, 2, 3] +endfunc + +func Test_python3_dict_del_items() + let d = eval("{'0' : -1, '1' : 'asd', 'b' : [1, 2, function('strlen')], 'f' : function('min'), '-1' : {'a': 1}}") + py3 d = mnv.bindeval('d') + py3 del d['-1'] + py3 del d['f'] + call assert_equal([1, 2, function('strlen')], py3eval('d.get(''b'', 1)')) + call assert_equal([1, 2, function('strlen')], py3eval('d.pop(''b'')')) + call assert_equal(1, py3eval('d.get(''b'', 1)')) + call assert_equal('asd', py3eval('d.pop(''1'', 2)')) + call assert_equal(2, py3eval('d.pop(''1'', 2)')) + call assert_equal('True', py3eval('repr(d.has_key(''0''))')) + call assert_equal('False', py3eval('repr(d.has_key(''1''))')) + call assert_equal('True', py3eval('repr(''0'' in d)')) + call assert_equal('False', py3eval('repr(''1'' in d)')) + call assert_equal("[b'0']", py3eval('repr(list(iter(d)))')) + call assert_equal({'0' : -1}, d) + call assert_equal("(b'0', -1)", py3eval('repr(d.popitem())')) + call assert_equal('None', py3eval('repr(d.get(''0''))')) + call assert_equal('[]', py3eval('repr(list(iter(d)))')) +endfunc + +" Slice assignment to a list +func Test_python3_slice_assignment() + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[0:0] = ['a'] + call assert_equal(['a', 0, 1, 2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[1:2] = ['b'] + call assert_equal([0, 'b', 2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[2:4] = ['c'] + call assert_equal([0, 1, 'c'], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[4:4] = ['d'] + call assert_equal([0, 1, 2, 3, 'd'], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[-1:2] = ['e'] + call assert_equal([0, 1, 2, 'e', 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[-10:2] = ['f'] + call assert_equal(['f', 2, 3], l) + + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + py3 l[2:-10] = ['g'] + call assert_equal([0, 1, 'g', 2, 3], l) + + let l = [] + py3 l = mnv.bindeval('l') + py3 l[0:0] = ['h'] + call assert_equal(['h'], l) + + let l = range(8) + py3 l = mnv.bindeval('l') + py3 l[2:6:2] = [10, 20] + call assert_equal([0, 1, 10, 3, 20, 5, 6, 7], l) + + let l = range(8) + py3 l = mnv.bindeval('l') + py3 l[6:2:-2] = [10, 20] + call assert_equal([0, 1, 2, 3, 20, 5, 10, 7], l) + + let l = range(8) + py3 l = mnv.bindeval('l') + py3 l[6:2] = () + call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) + + let l = range(8) + py3 l = mnv.bindeval('l') + py3 l[6:2:1] = () + call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) + + let l = range(8) + py3 l = mnv.bindeval('l') + py3 l[2:2:1] = () + call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) + + call AssertException(["py3 x = l[10:11:0]"], + \ "MNV(py3):ValueError: slice step cannot be zero") +endfunc + +" Locked variables +func Test_python3_lockedvar() + new + py3 cb = mnv.current.buffer + let l = [0, 1, 2, 3] + py3 l = mnv.bindeval('l') + lockvar! l + py3 << trim EOF + try: + l[2]='i' + except mnv.error: + cb.append('l[2] threw mnv.error: ' + emsg(sys.exc_info())) + EOF + call assert_equal(['', "l[2] threw mnv.error: error:('list is locked',)"], + \ getline(1, '$')) + + " Try to concatenate a locked list + call AssertException(['py3 l += [4, 5]'], 'MNV(py3):mnv.error: list is locked') + + call assert_equal([0, 1, 2, 3], l) + unlockvar! l + bw! +endfunc + +" Test for calling a function +func Test_python3_function_call() + func New(...) + return ['NewStart'] + a:000 + ['NewEnd'] + endfunc + + func DictNew(...) dict + return ['DictNewStart'] + a:000 + ['DictNewEnd', self] + endfunc + + new + let l = [function('New'), function('DictNew')] + py3 l = mnv.bindeval('l') + py3 l.extend(list(l[0](1, 2, 3))) + call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd'], l) + py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'}))) + call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}], l) + py3 l += [[l[0].name]] + call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, ['New']], l) + py3 ee('l[1](1, 2, 3)') + call assert_equal("l[1](1, 2, 3):(, error('MNV:E725: Calling dict function without Dictionary: DictNew',))", getline(2)) + %d + py3 f = l[0] + delfunction New + py3 ee('f(1, 2, 3)') + call assert_equal("f(1, 2, 3):(, error('MNV:E117: Unknown function: New',))", getline(2)) + bw! + delfunction DictNew +endfunc + +func Test_python3_float() + let l = [0.0] + py3 l = mnv.bindeval('l') + py3 l.extend([0.0]) + call assert_equal([0.0, 0.0], l) +endfunc + +" Test for Dict key errors +func Test_python3_dict_key_error() + let messages = [] + py3 << trim EOF + import sys + d = mnv.bindeval('{}') + m = mnv.bindeval('messages') + def em(expr, g=globals(), l=locals()): + try: + exec(expr, g, l) + except Exception as e: + if sys.version_info >= (3, 5) and e.__class__ is ValueError and str(e) == 'embedded null byte': + m.extend([TypeError.__name__]) + else: + m.extend([e.__class__.__name__]) + + em('d["abc1"]') + em('d["abc1"]="\\0"') + em('d["abc1"]=mnv') + em('d[""]=1') + em('d["a\\0b"]=1') + em('d[b"a\\0b"]=1') + em('d.pop("abc1")') + em('d.popitem()') + del em + del m + EOF + + call assert_equal(['KeyError', 'TypeError', 'TypeError', 'ValueError', + \ 'TypeError', 'TypeError', 'KeyError', 'KeyError'], messages) + unlet messages +endfunc + +" Test for locked and scope attributes +func Test_python3_lock_scope_attr() + let d = {} | let dl = {} | lockvar dl + let res = [] + for s in split("d dl v: g:") + let name = tr(s, ':', 's') + execute 'py3 ' .. name .. ' = mnv.bindeval("' .. s .. '")' + call add(res, s .. ' : ' .. join(map(['locked', 'scope'], + \ 'v:val .. ":" .. py3eval(name .. "." .. v:val)'), ';')) + endfor + call assert_equal(['d : locked:0;scope:0', 'dl : locked:1;scope:0', + \ 'v: : locked:2;scope:1', 'g: : locked:0;scope:2'], res) + + silent! let d.abc2 = 1 + silent! let dl.abc3 = 1 + py3 d.locked = True + py3 dl.locked = False + silent! let d.def = 1 + silent! let dl.def = 1 + call assert_equal({'abc2': 1}, d) + call assert_equal({'def': 1}, dl) + unlet d dl + + let l = [] | let ll = [] | lockvar ll + let res = [] + for s in split("l ll") + let name = tr(s, ':', 's') + execute 'py3 ' .. name .. '=mnv.bindeval("' .. s .. '")' + call add(res, s .. ' : locked:' .. py3eval(name .. '.locked')) + endfor + call assert_equal(['l : locked:0', 'll : locked:1'], res) + + silent! call extend(l, [0]) + silent! call extend(ll, [0]) + py3 l.locked = True + py3 ll.locked = False + silent! call extend(l, [1]) + silent! call extend(ll, [1]) + call assert_equal([0], l) + call assert_equal([1], ll) + unlet l ll + + " Try changing an attribute of a fixed list + py3 a = mnv.bindeval('v:argv') + call AssertException(['py3 a.locked = 0'], + \ 'MNV(py3):TypeError: cannot modify fixed list') +endfunc + +" Test for locking/unlocking a tuple +func Test_tuple_lock() + let t = (1, 2, 3) + py3 t = mnv.bindeval('t') + py3 t.locked = True + call assert_equal(1, islocked('t')) + py3 t.locked = False + call assert_equal(0, islocked('t')) +endfunc + +" Test for py3eval() +func Test_python3_pyeval() + let l = py3eval('[0, 1, 2]') + call assert_equal([0, 1, 2], l) + + let t = py3eval('("a", "b", "c")') + call assert_equal(("a", "b", "c"), t) + + let d = py3eval('{"a": "b", "c": 1, "d": ["e"]}') + call assert_equal([['a', 'b'], ['c', 1], ['d', ['e']]], sort(items(d))) + + let v:errmsg = '' + call assert_equal(v:none, py3eval('None')) + call assert_equal('', v:errmsg) + + py3 v = mnv.eval('test_null_function()') + call assert_equal(v:none, py3eval('v')) + + call assert_equal(0.0, py3eval('0.0')) + + " Evaluate an invalid values + call AssertException(['let v = py3eval(''"\0"'')'], 'E859:') + call AssertException(['let v = py3eval(''{"\0" : 1}'')'], 'E859:') + call AssertException(['let v = py3eval("undefined_name")'], + \ "MNV(let):NameError: name 'undefined_name' is not defined") + call AssertException(['let v = py3eval("mnv")'], 'E859:') +endfunc + +" Test for py3eval with locals +func Test_python3_pyeval_locals() + let str = 'a string' + let num = 0xbadb33f + let d = {'a': 1, 'b': 2, 'c': str} + let l = [ str, num, d ] + let t = ( str, num, d ) + + let locals = #{ + \ s: str, + \ n: num, + \ d: d, + \ l: l, + \ t: t, + \ } + + " check basics + call assert_equal('a string', py3eval('s', locals)) + call assert_equal(0xbadb33f, py3eval('n', locals)) + call assert_equal(d, py3eval('d', locals)) + call assert_equal(l, py3eval('l', locals)) + call assert_equal(t, py3eval('t', locals)) + call assert_equal('a,b,c', py3eval('b",".join(l)', {'l': ['a', 'b', 'c']})) + call assert_equal('hello', 's'->py3eval({'s': 'hello'})) + call assert_equal('a,b,c', 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})) + call assert_equal('a-b-c', 'b"-".join(t)'->py3eval({'t': ('a', 'b', 'c')})) + + py3 << trim EOF + def __UpdateDict(d, upd): + d.update(upd) + return d + + def __ExtendList(l, *args): + l.extend(*args) + return l + EOF + + " check assign to dict member works like bindeval + call assert_equal(3, py3eval('__UpdateDict( d, {"c": 3} )["c"]', locals)) + call assert_equal(3, d['c']) + + " check append lo list + call assert_equal(4, py3eval('len(__ExtendList(l, ["new item"]))', locals)) + call assert_equal("new item", l[-1]) + + " check calling a function + let StrLen = function('strlen') + call assert_equal(3, py3eval('f("abc")', {'f': StrLen})) +endfunc + +" Test for mnv.bindeval() +func Test_python3_mnv_bindeval() + " Float + let f = 3.14 + py3 f = mnv.bindeval('f') + call assert_equal(3.14, py3eval('f')) + + " Blob + let b = 0z12 + py3 b = mnv.bindeval('b') + call assert_equal("\x12", py3eval('b')) + + " Bool + call assert_equal(1, py3eval("mnv.bindeval('v:true')")) + call assert_equal(0, py3eval("mnv.bindeval('v:false')")) + call assert_equal(v:none, py3eval("mnv.bindeval('v:null')")) + call assert_equal(v:none, py3eval("mnv.bindeval('v:none')")) + + " channel/job + if has('channel') + call assert_equal(v:none, py3eval("mnv.bindeval('test_null_channel()')")) + endif + if has('job') + call assert_equal(v:none, py3eval("mnv.bindeval('test_null_job()')")) + endif +endfunc + +" threading +" Running py3do command (Test_pydo) before this test, stops the python thread +" from running. So this test should be run before the pydo test +func Test_aaa_python3_threading() + let l = [0] + py3 l = mnv.bindeval('l') + py3 << trim EOF + import threading + import time + + class T(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self.t = 0 + self.running = True + + def run(self): + while self.running: + self.t += 1 + time.sleep(0.1) + + t = T() + del T + t.start() + EOF + + sleep 1 + py3 t.running = False + py3 t.join() + + " Check if the background thread is working. Count should be 10, but on a + " busy system (AppVeyor) it can be much lower. + py3 l[0] = t.t > 4 + py3 del time + py3 del threading + py3 del t + call assert_equal([1], l) +endfunc + +" settrace +func Test_python3_settrace() + let l = [] + py3 l = mnv.bindeval('l') + py3 << trim EOF + import sys + + def traceit(frame, event, arg): + global l + if event == "line": + l += [frame.f_lineno] + return traceit + + def trace_main(): + for i in range(5): + pass + EOF + py3 sys.settrace(traceit) + py3 trace_main() + py3 sys.settrace(None) + py3 del traceit + py3 del trace_main + call assert_equal([1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1], l) +endfunc + +" Slice +func Test_python3_list_slice() + py3 ll = mnv.bindeval('[0, 1, 2, 3, 4, 5]') + py3 l = ll[:4] + call assert_equal([0, 1, 2, 3], py3eval('l')) + py3 l = ll[2:] + call assert_equal([2, 3, 4, 5], py3eval('l')) + py3 l = ll[:-4] + call assert_equal([0, 1], py3eval('l')) + py3 l = ll[-2:] + call assert_equal([4, 5], py3eval('l')) + py3 l = ll[2:4] + call assert_equal([2, 3], py3eval('l')) + py3 l = ll[4:2] + call assert_equal([], py3eval('l')) + py3 l = ll[-4:-2] + call assert_equal([2, 3], py3eval('l')) + py3 l = ll[-2:-4] + call assert_equal([], py3eval('l')) + py3 l = ll[:] + call assert_equal([0, 1, 2, 3, 4, 5], py3eval('l')) + py3 l = ll[0:6] + call assert_equal([0, 1, 2, 3, 4, 5], py3eval('l')) + py3 l = ll[-10:10] + call assert_equal([0, 1, 2, 3, 4, 5], py3eval('l')) + py3 l = ll[4:2:-1] + call assert_equal([4, 3], py3eval('l')) + py3 l = ll[::2] + call assert_equal([0, 2, 4], py3eval('l')) + py3 l = ll[4:2:1] + call assert_equal([], py3eval('l')) + + " Error case: Use an invalid index + call AssertException(['py3 ll[-10] = 5'], 'MNV(py3):mnv.error: internal error:') + + " Use a step value of 0 + call AssertException(['py3 ll[0:3:0] = [1, 2, 3]'], + \ 'MNV(py3):ValueError: slice step cannot be zero') + + " Error case: Invalid slice type + call AssertException(["py3 x = ll['abc']"], + \ "MNV(py3):TypeError: index must be int or slice, not str") + py3 del l + + " Error case: List with a null list item + let l = [test_null_list()] + py3 ll = mnv.bindeval('l') + call AssertException(["py3 x = ll[:]"], + \ s:system_error_pat) +endfunc + +" Slice +func Test_python3_tuple_slice() + py3 tt = mnv.bindeval('(0, 1, 2, 3, 4, 5)') + py3 t = tt[:4] + call assert_equal((0, 1, 2, 3), py3eval('t')) + py3 t = tt[2:] + call assert_equal((2, 3, 4, 5), py3eval('t')) + py3 t = tt[:-4] + call assert_equal((0, 1), py3eval('t')) + py3 t = tt[-2:] + call assert_equal((4, 5), py3eval('t')) + py3 t = tt[2:4] + call assert_equal((2, 3), py3eval('t')) + py3 t = tt[4:2] + call assert_equal((), py3eval('t')) + py3 t = tt[-4:-2] + call assert_equal((2, 3), py3eval('t')) + py3 t = tt[-2:-4] + call assert_equal((), py3eval('t')) + py3 t = tt[:] + call assert_equal((0, 1, 2, 3, 4, 5), py3eval('t')) + py3 t = tt[0:6] + call assert_equal((0, 1, 2, 3, 4, 5), py3eval('t')) + py3 t = tt[-10:10] + call assert_equal((0, 1, 2, 3, 4, 5), py3eval('t')) + py3 t = tt[4:2:-1] + call assert_equal((4, 3), py3eval('t')) + py3 t = tt[::2] + call assert_equal((0, 2, 4), py3eval('t')) + py3 t = tt[4:2:1] + call assert_equal((), py3eval('t')) + + " Error case: Use an invalid index + call AssertException(['py3 x = tt[-10]'], 'MNV(py3):IndexError: tuple index out of range') + + " Use a step value of 0 + call AssertException(['py3 x = tt[0:3:0]'], + \ 'MNV(py3):ValueError: slice step cannot be zero') + + " Error case: Invalid slice type + call AssertException(["py3 x = tt['abc']"], + \ "MNV(py3):TypeError: index must be int or slice, not str") + + " Error case: List with a null tuple item + let t = (test_null_tuple(),) + py3 tt = mnv.bindeval('t') + call AssertException(["py3 x = tt[:]"], s:system_error_pat) +endfunc + +func Test_python3_pytuple_to_mnvtuple() + let t = py3eval("('a', 'b')") + call assert_equal(('a', 'b'), t) + let t = py3eval("()") + call assert_equal((), t) + let t = py3eval("('x',)") + call assert_equal(('x',), t) + let t = py3eval("((1, 2), (), (3, 4))") + call assert_equal(((1, 2), (), (3, 4)), t) + let t = py3eval("((1, 2), {'a': 10}, [5, 6])") + call assert_equal(((1, 2), {'a': 10}, [5, 6]), t) + + " Invalid python tuple + py3 << trim END + class FailingIter(object): + def __iter__(self): + raise NotImplementedError('iter') + END + call assert_fails('call py3eval("(1, FailingIter, 2)")', + \ 'E859: Failed to convert returned python object to a MNV value') + + py3 del FailingIter +endfunc + +" Test for tuple garbage collection +func Test_python3_tuple_garbage_collect() + let t = (1, (2, 3), [4, 5], {'a': 6}) + py3 py_t = mnv.bindeval('t') + let save_testing = v:testing + let v:testing = 1 + call test_garbagecollect_now() + let v:testing = save_testing + + let new_t = py3eval('py_t') + call assert_equal((1, (2, 3), [4, 5], {'a': 6}), new_t) +endfunc + +" Vars +func Test_python3_vars() + let g:foo = 'bac' + let w:abc3 = 'def' + let b:baz = 'bar' + let t:bar = 'jkl' + try + throw "Abc" + catch /Abc/ + call assert_equal('Abc', py3eval('mnv.vvars[''exception'']')) + endtry + call assert_equal('bac', py3eval('mnv.vars[''foo'']')) + call assert_equal('def', py3eval('mnv.current.window.vars[''abc3'']')) + call assert_equal('bar', py3eval('mnv.current.buffer.vars[''baz'']')) + call assert_equal('jkl', py3eval('mnv.current.tabpage.vars[''bar'']')) +endfunc + +" Options +" paste: boolean, global +" previewheight number, global +" operatorfunc: string, global +" number: boolean, window-local +" numberwidth: number, window-local +" colorcolumn: string, window-local +" statusline: string, window-local/global +" autoindent: boolean, buffer-local +" shiftwidth: number, buffer-local +" omnifunc: string, buffer-local +" preserveindent: boolean, buffer-local/global +" path: string, buffer-local/global +func Test_python3_opts() + let g:res = [] + let g:bufs = [bufnr('%')] + new + let g:bufs += [bufnr('%')] + vnew + let g:bufs += [bufnr('%')] + wincmd j + vnew + let g:bufs += [bufnr('%')] + wincmd l + + func RecVars(opt) + let gval = string(eval('&g:' .. a:opt)) + let wvals = join(map(range(1, 4), + \ 'v:val .. ":" .. string(getwinvar(v:val, "&" .. a:opt))')) + let bvals = join(map(copy(g:bufs), + \ 'v:val .. ":" .. string(getbufvar(v:val, "&" .. a:opt))')) + call add(g:res, ' G: ' .. gval) + call add(g:res, ' W: ' .. wvals) + call add(g:res, ' B: ' .. wvals) + endfunc + + py3 << trim EOF + def e(s, g=globals(), l=locals()): + try: + exec(s, g, l) + except Exception as e: + mnv.command('return ' + repr(e.__class__.__name__)) + + def ev(s, g=globals(), l=locals()): + try: + return eval(s, g, l) + except Exception as e: + mnv.command('let exc=' + repr(e.__class__.__name__)) + return 0 + EOF + + func E(s) + python3 e(mnv.eval('a:s')) + endfunc + + func Ev(s) + let r = py3eval('ev(mnv.eval("a:s"))') + if exists('exc') + throw exc + endif + return r + endfunc + + py3 gopts1 = mnv.options + py3 wopts1 = mnv.windows[2].options + py3 wopts2 = mnv.windows[0].options + py3 wopts3 = mnv.windows[1].options + py3 bopts1 = mnv.buffers[mnv.bindeval("g:bufs")[2]].options + py3 bopts2 = mnv.buffers[mnv.bindeval("g:bufs")[1]].options + py3 bopts3 = mnv.buffers[mnv.bindeval("g:bufs")[0]].options + call add(g:res, 'wopts iters equal: ' .. + \ py3eval('list(wopts1) == list(wopts2)')) + call add(g:res, 'bopts iters equal: ' .. + \ py3eval('list(bopts1) == list(bopts2)')) + py3 gset = set(iter(gopts1)) + py3 wset = set(iter(wopts1)) + py3 bset = set(iter(bopts1)) + + set path=.,..,, + let lst = [] + let lst += [['paste', 1, 0, 1, 2, 1, 1, 0]] + let lst += [['previewheight', 5, 1, 6, 'a', 0, 1, 0]] + let lst += [['operatorfunc', 'A', 'B', 'C', 2, 0, 1, 0]] + let lst += [['number', 0, 1, 1, 0, 1, 0, 1]] + let lst += [['numberwidth', 2, 3, 5, -100, 0, 0, 1]] + let lst += [['colorcolumn', '+1', '+2', '+3', 'abc4', 0, 0, 1]] + let lst += [['statusline', '1', '2', '4', 0, 0, 1, 1]] + let lst += [['autoindent', 0, 1, 1, 2, 1, 0, 2]] + let lst += [['shiftwidth', 0, 2, 1, 3, 0, 0, 2]] + let lst += [['omnifunc', 'A', 'B', 'C', 1, 0, 0, 2]] + let lst += [['preserveindent', 0, 1, 1, 2, 1, 1, 2]] + let lst += [['path', '.,,', ',,', '.', 0, 0, 1, 2]] + for [oname, oval1, oval2, oval3, invval, bool, global, local] in lst + py3 oname = mnv.eval('oname') + py3 oval1 = mnv.bindeval('oval1') + py3 oval2 = mnv.bindeval('oval2') + py3 oval3 = mnv.bindeval('oval3') + if invval is 0 || invval is 1 + py3 invval = bool(mnv.bindeval('invval')) + else + py3 invval = mnv.bindeval('invval') + endif + if bool + py3 oval1 = bool(oval1) + py3 oval2 = bool(oval2) + py3 oval3 = bool(oval3) + endif + call add(g:res, '>>> ' .. oname) + call add(g:res, ' g/w/b:' .. py3eval('oname in gset') .. '/' .. + \ py3eval('oname in wset') .. '/' .. py3eval('oname in bset')) + call add(g:res, ' g/w/b (in):' .. py3eval('oname in gopts1') .. '/' .. + \ py3eval('oname in wopts1') .. '/' .. py3eval('oname in bopts1')) + for v in ['gopts1', 'wopts1', 'bopts1'] + try + call add(g:res, ' p/' .. v .. ': ' .. Ev('repr(' .. v .. '[''' .. oname .. '''])')) + catch + call add(g:res, ' p/' .. v .. '! ' .. v:exception) + endtry + let r = E(v .. '[''' .. oname .. ''']=invval') + if r isnot 0 + call add(g:res, ' inv: ' .. string(invval) .. '! ' .. r) + endif + for vv in (v is# 'gopts1' ? [v] : [v, v[:-2] .. '2', v[:-2] .. '3']) + let val = substitute(vv, '^.opts', 'oval', '') + let r = E(vv .. '[''' .. oname .. ''']=' .. val) + if r isnot 0 + call add(g:res, ' ' .. vv .. '! ' .. r) + endif + endfor + endfor + call RecVars(oname) + for v in ['wopts3', 'bopts3'] + let r = E('del ' .. v .. '["' .. oname .. '"]') + if r isnot 0 + call add(g:res, ' del ' .. v .. '! ' .. r) + endif + endfor + call RecVars(oname) + endfor + delfunction RecVars + delfunction E + delfunction Ev + py3 del ev + py3 del e + only + for buf in g:bufs[1:] + execute 'bwipeout!' buf + endfor + py3 del gopts1 + py3 del wopts1 + py3 del wopts2 + py3 del wopts3 + py3 del bopts1 + py3 del bopts2 + py3 del bopts3 + py3 del oval1 + py3 del oval2 + py3 del oval3 + py3 del oname + py3 del invval + + let expected =<< trim END + wopts iters equal: 1 + bopts iters equal: 1 + >>> paste + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: False + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 2! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 1 + W: 1:1 2:1 3:1 4:1 + B: 1:1 2:1 3:1 4:1 + del wopts3! KeyError + del bopts3! KeyError + G: 1 + W: 1:1 2:1 3:1 4:1 + B: 1:1 2:1 3:1 4:1 + >>> previewheight + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: 12 + inv: 'a'! TypeError + p/wopts1! KeyError + inv: 'a'! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 'a'! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 5 + W: 1:5 2:5 3:5 4:5 + B: 1:5 2:5 3:5 4:5 + del wopts3! KeyError + del bopts3! KeyError + G: 5 + W: 1:5 2:5 3:5 4:5 + B: 1:5 2:5 3:5 4:5 + >>> operatorfunc + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: b'' + inv: 2! TypeError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 2! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 'A' + W: 1:'A' 2:'A' 3:'A' 4:'A' + B: 1:'A' 2:'A' 3:'A' 4:'A' + del wopts3! KeyError + del bopts3! KeyError + G: 'A' + W: 1:'A' 2:'A' 3:'A' 4:'A' + B: 1:'A' 2:'A' 3:'A' 4:'A' + >>> number + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: 0! KeyError + gopts1! KeyError + p/wopts1: False + p/bopts1! KeyError + inv: 0! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 0 + W: 1:1 2:1 3:0 4:0 + B: 1:1 2:1 3:0 4:0 + del wopts3! ValueError + del bopts3! KeyError + G: 0 + W: 1:1 2:1 3:0 4:0 + B: 1:1 2:1 3:0 4:0 + >>> numberwidth + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: -100! KeyError + gopts1! KeyError + p/wopts1: 4 + inv: -100! error + p/bopts1! KeyError + inv: -100! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 4 + W: 1:3 2:5 3:2 4:4 + B: 1:3 2:5 3:2 4:4 + del wopts3! ValueError + del bopts3! KeyError + G: 4 + W: 1:3 2:5 3:2 4:4 + B: 1:3 2:5 3:2 4:4 + >>> colorcolumn + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: 'abc4'! KeyError + gopts1! KeyError + p/wopts1: b'' + inv: 'abc4'! error + p/bopts1! KeyError + inv: 'abc4'! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: '' + W: 1:'+2' 2:'+3' 3:'+1' 4:'' + B: 1:'+2' 2:'+3' 3:'+1' 4:'' + del wopts3! ValueError + del bopts3! KeyError + G: '' + W: 1:'+2' 2:'+3' 3:'+1' 4:'' + B: 1:'+2' 2:'+3' 3:'+1' 4:'' + >>> statusline + g/w/b:1/1/0 + g/w/b (in):1/1/0 + p/gopts1: b'' + inv: 0! TypeError + p/wopts1: None + inv: 0! TypeError + p/bopts1! KeyError + inv: 0! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: '1' + W: 1:'2' 2:'4' 3:'1' 4:'1' + B: 1:'2' 2:'4' 3:'1' 4:'1' + del bopts3! KeyError + G: '1' + W: 1:'2' 2:'1' 3:'1' 4:'1' + B: 1:'2' 2:'1' 3:'1' 4:'1' + >>> autoindent + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 2! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: False + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + >>> shiftwidth + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 3! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 3! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: 8 + G: 8 + W: 1:0 2:2 3:8 4:1 + B: 1:0 2:2 3:8 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 8 + W: 1:0 2:2 3:8 4:1 + B: 1:0 2:2 3:8 4:1 + >>> omnifunc + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 1! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 1! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: b'' + inv: 1! TypeError + G: '' + W: 1:'A' 2:'B' 3:'' 4:'C' + B: 1:'A' 2:'B' 3:'' 4:'C' + del wopts3! KeyError + del bopts3! ValueError + G: '' + W: 1:'A' 2:'B' 3:'' 4:'C' + B: 1:'A' 2:'B' 3:'' 4:'C' + >>> preserveindent + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 2! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: False + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + >>> path + g/w/b:1/0/1 + g/w/b (in):1/0/1 + p/gopts1: b'.,..,,' + inv: 0! TypeError + p/wopts1! KeyError + inv: 0! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: None + inv: 0! TypeError + G: '.,,' + W: 1:'.,,' 2:',,' 3:'.,,' 4:'.' + B: 1:'.,,' 2:',,' 3:'.,,' 4:'.' + del wopts3! KeyError + G: '.,,' + W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' + B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' + END + + call assert_equal(expected, g:res) + unlet g:res + + call assert_equal(0, py3eval("'' in mnv.options")) + + " use an empty key to index mnv.options + call AssertException(["let v = py3eval(\"mnv.options['']\")"], + \ 'MNV(let):ValueError: empty keys are not allowed') + call AssertException(["py3 mnv.current.window.options[''] = 0"], + \ 'MNV(py3):ValueError: empty keys are not allowed') + call AssertException(["py3 mnv.current.window.options[{}] = 0"], + \ 'MNV(py3):TypeError: expected bytes() or str() instance, but got dict') + + " set one of the number options to a very large number + let cmd = ["py3 mnv.options['previewheight'] = 9999999999999999"] + call AssertException(cmd, "MNV(py3):OverflowError:") + + " unset a global-local string option + call AssertException(["py3 del mnv.options['errorformat']"], + \ 'MNV(py3):ValueError: unable to unset global option errorformat') +endfunc + +" Test for mnv.buffer object +func Test_python3_buffer() + new + call setline(1, "Hello\nWorld") + call assert_fails("let x = py3eval('mnv.current.buffer[0]')", 'E859:') + %bw! + + edit Xfile1 + let bnr1 = bufnr() + py3 cb = mnv.current.buffer + vnew Xfile2 + let bnr2 = bufnr() + call setline(1, ['First line', 'Second line', 'Third line']) + py3 b = mnv.current.buffer + 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]')) + call AssertException(["py3 x = b[0:3:0]"], + \ 'MNV(py3):ValueError: slice step cannot be zero') + call AssertException(["py3 b[0:3:0] = 'abc'"], + \ 'MNV(py3):ValueError: slice step cannot be zero') + call AssertException(["py3 x = b[{}]"], + \ 'MNV(py3):TypeError: index must be int or slice, not dict') + call AssertException(["py3 b[{}] = 'abc'"], + \ 'MNV(py3):TypeError: index must be int or slice, not dict') + + " Test for getting lines using a range + call AssertException(["py3 x = b.range(0,3)[0:2:0]"], + \ "MNV(py3):ValueError: slice step cannot be zero") + call AssertException(["py3 b.range(0,3)[0:2:0] = 'abc'"], + \ "MNV(py3):ValueError: slice step cannot be zero") + + " Tests BufferAppend and BufferItem + py3 cb.append(b[0]) + call assert_equal(['First line'], getbufline(bnr1, 2)) + %d + + " Try to append using out-of-range line number + call AssertException(["py3 b.append('abc', 10)"], + \ 'MNV(py3):IndexError: line number out of range') + + " Append a non-string item + call AssertException(["py3 b.append([22])"], + \ 'MNV(py3):TypeError: expected bytes() or str() instance, but got int') + + " Tests BufferSlice and BufferAssSlice + py3 cb.append('abc5') # Will be overwritten + py3 cb[-1:] = b[:-2] + call assert_equal(['First line'], getbufline(bnr1, 2)) + %d + + " Test BufferLength and BufferAssSlice + py3 cb.append('def') # Will not be overwritten + py3 cb[len(cb):] = b[:] + call assert_equal(['def', 'First line', 'Second line', 'Third line'], + \ getbufline(bnr1, 2, '$')) + %d + + " Test BufferAssItem and BufferMark + call setbufline(bnr1, 1, ['one', 'two', 'three']) + call cursor(1, 3) + normal ma + py3 cb.append('ghi') # Will be overwritten + py3 cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1])) + call assert_equal(['(3, 2)'], getbufline(bnr1, 4)) + %d + + " Test BufferRepr + py3 cb.append(repr(cb) + repr(b)) + call assert_equal([''], getbufline(bnr1, 2)) + %d + + " Modify foreign buffer + py3 << trim EOF + b.append('foo') + b[0]='bar' + b[0:0]=['baz'] + mnv.command('call append("$", getbufline(%i, 1, "$"))' % b.number) + EOF + call assert_equal(['baz', 'bar', 'Second line', 'Third line', 'foo'], + \ getbufline(bnr2, 1, '$')) + %d + + " Test assigning to name property + augroup BUFS + autocmd BufFilePost * python3 cb.append(mnv.eval('expand("")') + ':BufFilePost:' + mnv.eval('bufnr("%")')) + autocmd BufFilePre * python3 cb.append(mnv.eval('expand("")') + ':BufFilePre:' + mnv.eval('bufnr("%")')) + augroup END + py3 << trim EOF + import os + old_name = cb.name + cb.name = 'foo' + cb.append(cb.name[-11:].replace(os.path.sep, '/')) + b.name = 'bar' + cb.append(b.name[-11:].replace(os.path.sep, '/')) + cb.name = old_name + cb.append(cb.name[-14:].replace(os.path.sep, '/')) + del old_name + EOF + call assert_equal([bnr1 .. ':BufFilePre:' .. bnr1, + \ bnr1 .. ':BufFilePost:' .. bnr1, + \ 'testdir/foo', + \ bnr2 .. ':BufFilePre:' .. bnr2, + \ bnr2 .. ':BufFilePost:' .. bnr2, + \ 'testdir/bar', + \ bnr1 .. ':BufFilePre:' .. bnr1, + \ bnr1 .. ':BufFilePost:' .. bnr1, + \ 'testdir/Xfile1'], getbufline(bnr1, 2, '$')) + %d + + " Test CheckBuffer + py3 << trim EOF + for _b in mnv.buffers: + if _b is not cb: + mnv.command('bwipeout! ' + str(_b.number)) + del _b + cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid))) + EOF + call assert_equal('valid: b:False, cb:True', getline(2)) + %d + + py3 << trim EOF + for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")'): + try: + exec(expr) + except mnv.error: + pass + else: + # Usually a SEGV here + # Should not happen in any case + cb.append('No exception for ' + expr) + mnv.command('cd .') + del b + EOF + call assert_equal([''], getline(1, '$')) + + " Delete all the lines in a buffer + call setline(1, ['a', 'b', 'c']) + py3 mnv.current.buffer[:] = [] + call assert_equal([''], getline(1, '$')) + + " Test for buffer marks + call assert_equal(v:none, py3eval("mnv.current.buffer.mark('r')")) + + " Test for modifying a 'nomodifiable' buffer + setlocal nomodifiable + call AssertException(["py3 mnv.current.buffer[0] = 'abc'"], + \ "MNV(py3):mnv.error: MNV:E21: Cannot make changes, 'modifiable' is off") + call AssertException(["py3 mnv.current.buffer[0] = None"], + \ "MNV(py3):mnv.error: MNV:E21: Cannot make changes, 'modifiable' is off") + call AssertException(["py3 mnv.current.buffer[:] = None"], + \ "MNV(py3):mnv.error: MNV:E21: Cannot make changes, 'modifiable' is off") + call AssertException(["py3 mnv.current.buffer[:] = []"], + \ "MNV(py3):mnv.error: MNV:E21: Cannot make changes, 'modifiable' is off") + call AssertException(["py3 mnv.current.buffer.append('abc')"], + \ "MNV(py3):mnv.error: MNV:E21: Cannot make changes, 'modifiable' is off") + call AssertException(["py3 mnv.current.buffer.append([])"], + \ "MNV(py3):mnv.error: MNV:E21: Cannot make changes, 'modifiable' is off") + setlocal modifiable + + augroup BUFS + autocmd! + augroup END + augroup! BUFS + %bw! + + " Range object for a deleted buffer + new Xp3buffile + call setline(1, ['one', 'two', 'three']) + py3 b = mnv.current.buffer + py3 r = mnv.current.buffer.range(0, 2) + call assert_equal('', py3eval('repr(r)')) + %bw! + call AssertException(['py3 r[:] = []'], + \ 'MNV(py3):mnv.error: attempt to refer to deleted buffer') + call assert_match('