test_events.test_broadcast()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 18
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nop 1
dl 0
loc 18
rs 9.5
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
3
4
def test_receiving_events(vim):
5
    vim.command('call rpcnotify(%d, "test-event", 1, 2, 3)' % vim.channel_id)
6
    event = vim.next_message()
7
    assert event[1] == 'test-event'
8
    assert event[2] == [1, 2, 3]
9
    vim.command('au FileType python call rpcnotify(%d, "py!", bufnr("$"))' %
10
                vim.channel_id)
11
    vim.command('set filetype=python')
12
    event = vim.next_message()
13
    assert event[1] == 'py!'
14
    assert event[2] == [vim.current.buffer.number]
15
16
17
def test_sending_notify(vim):
18
    # notify after notify
19
    vim.command("let g:test = 3", async_=True)
20
    cmd = 'call rpcnotify(%d, "test-event", g:test)' % vim.channel_id
21
    vim.command(cmd, async_=True)
22
    event = vim.next_message()
23
    assert event[1] == 'test-event'
24
    assert event[2] == [3]
25
26
    # request after notify
27
    vim.command("let g:data = 'xyz'", async_=True)
28
    assert vim.eval('g:data') == 'xyz'
29
30
31
def test_broadcast(vim):
32
    vim.subscribe('event2')
33
    vim.command('call rpcnotify(0, "event1", 1, 2, 3)')
34
    vim.command('call rpcnotify(0, "event2", 4, 5, 6)')
35
    vim.command('call rpcnotify(0, "event2", 7, 8, 9)')
36
    event = vim.next_message()
37
    assert event[1] == 'event2'
38
    assert event[2] == [4, 5, 6]
39
    event = vim.next_message()
40
    assert event[1] == 'event2'
41
    assert event[2] == [7, 8, 9]
42
    vim.unsubscribe('event2')
43
    vim.subscribe('event1')
44
    vim.command('call rpcnotify(0, "event2", 10, 11, 12)')
45
    vim.command('call rpcnotify(0, "event1", 13, 14, 15)')
46
    msg = vim.next_message()
47
    assert msg[1] == 'event1'
48
    assert msg[2] == [13, 14, 15]
49