def test_valid(): vim.command('split') window = vim.windows[1] vim.current.window = window ok(window.valid) vim.command('q') ok(not window.valid)
def test_windows(): vim.command('tabnew') vim.command('vsplit') eq(list(vim.tabpages[0].windows), [vim.windows[0]]) eq(list(vim.tabpages[1].windows), [vim.windows[1], vim.windows[2]]) eq(vim.tabpages[1].window, vim.windows[1]) vim.current.window = vim.windows[2] eq(vim.tabpages[1].window, vim.windows[2])
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_buffers(): eq(len(vim.buffers), 1) eq(vim.buffers[0], vim.current.buffer) vim.command('new') eq(len(vim.buffers), 2) eq(vim.buffers[1], vim.current.buffer) vim.current.buffer = vim.buffers[0] eq(vim.buffers[0], vim.current.buffer)
def test_width(): vim.command('split') eq(vim.windows[1].width, vim.windows[0].width) vim.current.window = vim.windows[1] vim.command('vsplit') eq(vim.windows[1].width, vim.windows[0].width // 2) vim.windows[1].width = 2 eq(vim.windows[1].width, 2)
def test_height(): vim.command('vsplit') eq(vim.windows[1].height, vim.windows[0].height) vim.current.window = vim.windows[1] vim.command('split') eq(vim.windows[1].height, vim.windows[0].height // 2) vim.windows[1].height = 2 eq(vim.windows[1].height, 2)
def test_cursor(): eq(vim.current.window.cursor, [1, 0]) vim.command('normal ityping\033o some text') eq(vim.current.buffer[:], ['typing', ' some text']) eq(vim.current.window.cursor, [2, 10]) vim.current.window.cursor = [2, 6] vim.command('normal i dumb') eq(vim.current.buffer[:], ['typing', ' some dumb text'])
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_windows(): eq(len(vim.windows), 1) eq(vim.windows[0], vim.current.window) vim.command('vsplit') vim.command('split') eq(len(vim.windows), 3) eq(vim.windows[0], vim.current.window) vim.current.window = vim.windows[1] eq(vim.windows[1], vim.current.window)
def test_position(): height = vim.windows[0].height width = vim.windows[0].width vim.command('split') vim.command('vsplit') eq((vim.windows[0].row, vim.windows[0].col), (0, 0)) vsplit_pos = width / 2 split_pos = height / 2 eq(vim.windows[1].row, 0) ok(vsplit_pos - 1 <= vim.windows[1].col <= vsplit_pos + 1) ok(split_pos - 1 <= vim.windows[2].row <= split_pos + 1) eq(vim.windows[2].col, 0)
def setup_cb(): vim.vars["result1"] = 0 vim.vars["result2"] = 0 vim.vars["result3"] = 0 vim.vars["result4"] = 0 cmd = 'let g:result1 = rpcrequest(%d, "call", %d)' % (cid, 2) vim.command(cmd) eq(vim.vars["result1"], 4) eq(vim.vars["result2"], 8) eq(vim.vars["result3"], 16) eq(vim.vars["result4"], 32) vim.stop_loop()
def request_cb(name, args): n = args[0] n *= 2 if n <= 16: if n == 4: cmd = 'let g:result2 = rpcrequest(%d, "call", %d)' % (cid, n,) elif n == 8: cmd = 'let g:result3 = rpcrequest(%d, "call", %d)' % (cid, n,) elif n == 16: cmd = 'let g:result4 = rpcrequest(%d, "call", %d)' % (cid, n,) vim.command(cmd) return n
def setup_cb(): vim.vars['result1'] = 0 vim.vars['result2'] = 0 vim.vars['result3'] = 0 vim.vars['result4'] = 0 cmd = 'let g:result1 = rpcrequest(%d, "call", %d)' % (cid, 2,) vim.command(cmd) eq(vim.vars['result1'], 4) eq(vim.vars['result2'], 8) eq(vim.vars['result3'], 16) eq(vim.vars['result4'], 32) vim.session.stop()
def setup_cb(): vim.vars['result1'] = 0 vim.vars['result2'] = 0 vim.vars['result3'] = 0 vim.vars['result4'] = 0 cmd = 'let g:result1 = rpcrequest(%d, "call", %d)' % ( cid, 2, ) vim.command(cmd) eq(vim.vars['result1'], 4) eq(vim.vars['result2'], 8) eq(vim.vars['result3'], 16) eq(vim.vars['result4'], 32) vim.session.stop()
def test_tabpages(): eq(len(vim.tabpages), 1) eq(vim.tabpages[0], vim.current.tabpage) vim.command('tabnew') eq(len(vim.tabpages), 2) eq(len(vim.windows), 2) eq(vim.windows[1], vim.current.window) eq(vim.tabpages[1], vim.current.tabpage) vim.current.window = vim.windows[0] # Switching window also switches tabpages if necessary(this probably # isn't the current behavior, but compatibility will be handled in the # python client with an optional parameter) eq(vim.tabpages[0], vim.current.tabpage) eq(vim.windows[0], vim.current.window) vim.current.tabpage = vim.tabpages[1] eq(vim.tabpages[1], vim.current.tabpage) eq(vim.windows[1], vim.current.window)
def test_broadcast(): vim.subscribe('event2') vim.command('call rpcnotify(0, "event1", 1, 2, 3)') vim.command('call rpcnotify(0, "event2", 4, 5, 6)') vim.command('call rpcnotify(0, "event2", 7, 8, 9)') event = vim.next_message() eq(event[1], 'event2') eq(event[2], [4, 5, 6]) event = vim.next_message() eq(event[1], 'event2') eq(event[2], [7, 8, 9]) vim.unsubscribe('event2') vim.subscribe('event1') vim.command('call rpcnotify(0, "event2", 10, 11, 12)') vim.command('call rpcnotify(0, "event1", 13, 14, 15)') msg = vim.next_message() eq(msg[1], 'event1') eq(msg[2], [13, 14, 15])
def test_command(): fname = tempfile.mkstemp()[1] vim.command('new') vim.command('edit %s' % fname) # skip the "press return" state, which does not handle deferred calls vim.input('\r') vim.command('normal itesting\npython\napi') vim.command('w') ok(os.path.isfile(fname)) eq(open(fname).read(), 'testing\npython\napi\n') os.unlink(fname)
def request_cb(name, args): n = args[0] n *= 2 if n <= 16: if n == 4: cmd = 'let g:result2 = rpcrequest(%d, "call", %d)' % ( cid, n, ) elif n == 8: cmd = 'let g:result3 = rpcrequest(%d, "call", %d)' % ( cid, n, ) elif n == 16: cmd = 'let g:result4 = rpcrequest(%d, "call", %d)' % ( cid, n, ) vim.command(cmd) return n
def test_buffers(): buffers = [] # Number of elements eq(len(vim.buffers), 1) # Indexing (by buffer number) eq(vim.buffers[vim.current.buffer.number], vim.current.buffer) buffers.append(vim.current.buffer) vim.command('new') eq(len(vim.buffers), 2) buffers.append(vim.current.buffer) eq(vim.buffers[vim.current.buffer.number], vim.current.buffer) vim.current.buffer = buffers[0] eq(vim.buffers[vim.current.buffer.number], buffers[0]) # Membership test ok(buffers[0] in vim.buffers) ok(buffers[1] in vim.buffers) ok({} not in vim.buffers) # Iteration eq(buffers, list(vim.buffers))
def test_receiving_events(): vim.command('call rpcnotify(%d, "test-event", 1, 2, 3)' % vim.channel_id) event = vim.next_message() eq(event[1], 'test-event') eq(event[2], [1, 2, 3]) vim.command('au FileType python call rpcnotify(%d, "py!", bufnr("$"))' % vim.channel_id) vim.command('set filetype=python') event = vim.next_message() eq(event[1], 'py!') eq(event[2], [vim.current.buffer.number])
def test_handle(): hnd1 = vim.current.window.handle vim.command('bot split') hnd2 = vim.current.window.handle ok(hnd2 != hnd1) vim.command('bot split') hnd3 = vim.current.window.handle ok(hnd3 != hnd1) ok(hnd3 != hnd2) vim.command('wincmd w') eq(vim.current.window.handle,hnd1)
def test_hash(): d = {} d[vim.current.buffer] = "alpha" eq(d[vim.current.buffer], "alpha") vim.command('new') d[vim.current.buffer] = "beta" eq(d[vim.current.buffer], "beta") vim.command('winc w') eq(d[vim.current.buffer], "alpha") vim.command('winc w') eq(d[vim.current.buffer], "beta")
def test_handle(): hnd1 = vim.current.window.handle vim.command('bot split') hnd2 = vim.current.window.handle ok(hnd2 != hnd1) vim.command('bot split') hnd3 = vim.current.window.handle ok(hnd3 != hnd1) ok(hnd3 != hnd2) vim.command('wincmd w') eq(vim.current.window.handle, hnd1)
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_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_valid(): vim.command('new') buffer = vim.current.buffer ok(buffer.valid) vim.command('bw!') ok(not buffer.valid)
def source(code): fd, fname = tempfile.mkstemp() with os.fdopen(fd,'w') as f: f.write(code) vim.command('source '+fname) os.unlink(fname)
def test_number(): curnum = vim.current.buffer.number vim.command('new') eq(vim.current.buffer.number, curnum + 1) vim.command('new') eq(vim.current.buffer.number, curnum + 2)
def test_tabpage(): vim.command('tabnew') vim.command('vsplit') eq(vim.windows[0].tabpage, vim.tabpages[0]) eq(vim.windows[1].tabpage, vim.tabpages[1]) eq(vim.windows[2].tabpage, vim.tabpages[1])
def request_cb(name, args): vim.command('let g:result2 = [7, 8, 9]') return vim.vars['result2']
def source(code): fd, fname = tempfile.mkstemp() with os.fdopen(fd, 'w') as f: f.write(code) vim.command('source ' + fname) os.unlink(fname)
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_mark(): vim.current.buffer.append(['a', 'bit of', 'text']) vim.current.window.cursor = [3, 4] vim.command('mark V') eq(vim.current.buffer.mark('V'), [3, 0])
def test_buffer(): eq(vim.current.buffer, vim.windows[0].buffer) vim.command('new') vim.current.window = vim.windows[1] eq(vim.current.buffer, vim.windows[1].buffer) ok(vim.windows[0].buffer != vim.windows[1].buffer)
def setup_cb(): cmd = 'let g:result = rpcrequest(%d, "client-call", 1, 2, 3)' % cid vim.command(cmd) eq(vim.vars['result'], [4, 5, 6]) vim.session.stop()
def test_valid(): vim.command('tabnew') tabpage = vim.tabpages[1] ok(tabpage.valid) vim.command('tabclose') ok(not tabpage.valid)