def test_chdir(): pwd = vim.eval('getcwd()') root = os.path.abspath(os.sep) # We can chdir to '/' on Windows, but then the pwd will be the root drive vim.chdir('/') eq(vim.eval('getcwd()'), root) vim.chdir(pwd) eq(vim.eval('getcwd()'), pwd)
def test_invalid_utf8(): vim.command('normal "=printf("%c", 0xFF)\np') eq(vim.eval("char2nr(getline(1))"), 0xFF) eq(vim.current.buffer[:], ['\udcff'] if IS_PYTHON3 else ['\xff']) vim.current.line += 'x' eq(vim.eval("getline(1)", decode=False), b'\xFFx') eq(vim.current.buffer[:], ['\udcffx'] if IS_PYTHON3 else ['\xffx'])
def test_api(): vim.current.buffer.api.set_var('myvar', 'thetext') eq(vim.current.buffer.api.get_var('myvar'), 'thetext') eq(vim.eval('b:myvar'), 'thetext') vim.current.buffer.api.set_lines(0, -1, True, ['alpha', 'beta']) eq(vim.current.buffer.api.get_lines(0, -1, True), ['alpha', 'beta']) eq(vim.current.buffer[:], ['alpha', 'beta'])
def test_name(): vim.command('new') eq(vim.current.buffer.name, '') new_name = vim.eval('resolve(tempname())') vim.current.buffer.name = new_name eq(vim.current.buffer.name, new_name) vim.command('silent w!') ok(os.path.isfile(new_name)) os.unlink(new_name)
def test_exception_in_threadsafe_call(): # an exception in a threadsafe_call shouldn't crash the entire host msgs = [] vim.async_call(lambda: [vim.eval("3"), undefined_variable]) timer = Timer(0.5, lambda: vim.async_call(lambda: vim.stop_loop())) timer.start() vim.run_loop(None, None, err_cb=msgs.append) eq(len(msgs), 1) msgs[0].index('NameError') msgs[0].index('undefined_variable')
def test_sending_notify(): # notify after notify vim.command("let g:test = 3", async=True) cmd = 'call rpcnotify(%d, "test-event", g:test)' % vim.channel_id vim.command(cmd, async=True) event = vim.next_message() eq(event[1], 'test-event') eq(event[2], [3]) # request after notify vim.command("let g:data = 'xyz'", async=True) eq(vim.eval('g:data'), 'xyz')
def test_vars(): vim.current.buffer.vars['python'] = [1, 2, {'3': 1}] eq(vim.current.buffer.vars['python'], [1, 2, {'3': 1}]) eq(vim.eval('b:python'), [1, 2, {'3': 1}])
def test_eval(): vim.command('let g:v1 = "a"') vim.command('let g:v2 = [1, 2, {"v3": 3}]') eq(vim.eval('g:'), {'v1': 'a', 'v2': [1, 2, {'v3': 3}]})
def test_vars(): vim.current.tabpage.vars["python"] = [1, 2, {"3": 1}] eq(vim.current.tabpage.vars["python"], [1, 2, {"3": 1}]) eq(vim.eval("t:python"), [1, 2, {"3": 1}])
def test_chdir(): pwd = vim.eval('getcwd()') vim.chdir('/') eq(vim.eval('getcwd()'), '/') vim.chdir(pwd) eq(vim.eval('getcwd()'), pwd)
def test_vars(): vim.current.window.vars['python'] = [1, 2, {'3': 1}] eq(vim.current.window.vars['python'], [1, 2, {'3': 1}]) eq(vim.eval('w:python'), [1, 2, {'3': 1}])
def test_vars(): vim.vars['python'] = [1, 2, {'3': 1}] eq(vim.vars['python'], [1, 2, {'3': 1}]) eq(vim.eval('g:python'), [1, 2, {'3': 1}])
def test_vars(): vim.current.tabpage.vars['python'] = [1, 2, {'3': 1}] eq(vim.current.tabpage.vars['python'], [1, 2, {'3': 1}]) eq(vim.eval('t:python'), [1, 2, {'3': 1}])
def test_exception_in_threadsafe_call(): # an exception in a threadsafe_call shouldn't crash the entire host vim.session.threadsafe_call(lambda: [vim.eval("3"), undefined_variable]) vim.session.threadsafe_call(lambda: vim.session.stop()) vim.session.run(None, None)