forked from neovim/pynvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_events.py
58 lines (47 loc) · 1.88 KB
/
test_events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest
from pynvim.api import Nvim
def test_receiving_events(vim: Nvim) -> None:
vim.command('call rpcnotify(%d, "test-event", 1, 2, 3)' % vim.channel_id)
event = vim.next_message()
assert event[1] == 'test-event'
assert 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()
assert event[1] == 'py!'
assert event[2] == [vim.current.buffer.number]
def test_sending_notify(vim: Nvim) -> None:
# 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()
assert event[1] == 'test-event'
assert event[2] == [3]
# request after notify
vim.command("let g:data = 'xyz'", async_=True)
assert vim.eval('g:data') == 'xyz'
def test_async_error(vim: Nvim) -> None:
# Invoke a bogus Ex command via notify (async).
vim.command("lolwut", async_=True)
event = vim.next_message()
assert event[1] == 'nvim_error_event'
def test_broadcast(vim: Nvim) -> None:
if (vim.version.major, vim.version.minor) < (0, 11):
# see #570, neovim/neovim#28487
pytest.skip("neovim/neovim#28487")
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()
assert event[1] == 'event1'
assert event[2] == [1, 2, 3]
event = vim.next_message()
assert event[1] == 'event2'
assert event[2] == [4, 5, 6]
vim.command('call rpcnotify(0, "event2", 10, 11, 12)')
vim.command('call rpcnotify(0, "event1", 13, 14, 15)')
msg = vim.next_message()
assert msg[1] == 'event2'
assert msg[2] == [7, 8, 9]