Exemplo n.º 1
0
def test_valid():
    vim.command('split')
    window = vim.windows[1]
    vim.current.window = window
    ok(window.valid)
    vim.command('q')
    ok(not window.valid)
Exemplo n.º 2
0
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])
Exemplo n.º 3
0
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'])
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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'])
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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'])
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
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()
Exemplo n.º 16
0
 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
Exemplo n.º 17
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.session.stop()
Exemplo n.º 18
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.session.stop()
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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])
Exemplo n.º 22
0
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])
Exemplo n.º 23
0
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)
Exemplo n.º 24
0
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)
Exemplo n.º 25
0
 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
Exemplo n.º 26
0
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))
Exemplo n.º 27
0
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))
Exemplo n.º 28
0
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])
Exemplo n.º 29
0
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)
Exemplo n.º 30
0
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])
Exemplo n.º 31
0
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")
Exemplo n.º 32
0
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)
Exemplo n.º 33
0
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")
Exemplo n.º 34
0
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')
Exemplo n.º 35
0
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')
Exemplo n.º 36
0
def test_valid():
    vim.command('new')
    buffer = vim.current.buffer
    ok(buffer.valid)
    vim.command('bw!')
    ok(not buffer.valid)
Exemplo n.º 37
0
def source(code):
    fd, fname = tempfile.mkstemp()
    with os.fdopen(fd,'w') as f:
        f.write(code)
    vim.command('source '+fname)
    os.unlink(fname)
Exemplo n.º 38
0
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)
Exemplo n.º 39
0
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])
Exemplo n.º 40
0
 def request_cb(name, args):
     vim.command('let g:result2 = [7, 8, 9]')
     return vim.vars['result2']
Exemplo n.º 41
0
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)
Exemplo n.º 42
0
 def request_cb(name, args):
     vim.command('let g:result2 = [7, 8, 9]')
     return vim.vars['result2']
Exemplo n.º 43
0
def test_valid():
    vim.command('new')
    buffer = vim.current.buffer
    ok(buffer.valid)
    vim.command('bw!')
    ok(not buffer.valid)
Exemplo n.º 44
0
def source(code):
    fd, fname = tempfile.mkstemp()
    with os.fdopen(fd, 'w') as f:
        f.write(code)
    vim.command('source ' + fname)
    os.unlink(fname)
Exemplo n.º 45
0
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}]})
Exemplo n.º 46
0
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])
Exemplo n.º 47
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)
Exemplo n.º 48
0
 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()
Exemplo n.º 49
0
def test_valid():
    vim.command('tabnew')
    tabpage = vim.tabpages[1]
    ok(tabpage.valid)
    vim.command('tabclose')
    ok(not tabpage.valid)
Exemplo n.º 50
0
 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()
Exemplo n.º 51
0
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])