|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
def test_buffer(vim): |
|
5
|
|
|
assert vim.current.buffer == vim.windows[0].buffer |
|
6
|
|
|
vim.command('new') |
|
7
|
|
|
vim.current.window = vim.windows[1] |
|
8
|
|
|
assert vim.current.buffer == vim.windows[1].buffer |
|
9
|
|
|
assert vim.windows[0].buffer != vim.windows[1].buffer |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
def test_cursor(vim): |
|
13
|
|
|
assert vim.current.window.cursor == [1, 0] |
|
14
|
|
|
vim.command('normal ityping\033o some text') |
|
15
|
|
|
assert vim.current.buffer[:] == ['typing', ' some text'] |
|
16
|
|
|
assert vim.current.window.cursor == [2, 10] |
|
17
|
|
|
vim.current.window.cursor = [2, 6] |
|
18
|
|
|
vim.command('normal i dumb') |
|
19
|
|
|
assert vim.current.buffer[:] == ['typing', ' some dumb text'] |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
def test_height(vim): |
|
23
|
|
|
vim.command('vsplit') |
|
24
|
|
|
assert vim.windows[1].height == vim.windows[0].height |
|
25
|
|
|
vim.current.window = vim.windows[1] |
|
26
|
|
|
vim.command('split') |
|
27
|
|
|
assert vim.windows[1].height == vim.windows[0].height // 2 |
|
28
|
|
|
vim.windows[1].height = 2 |
|
29
|
|
|
assert vim.windows[1].height == 2 |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def test_width(vim): |
|
33
|
|
|
vim.command('split') |
|
34
|
|
|
assert vim.windows[1].width == vim.windows[0].width |
|
35
|
|
|
vim.current.window = vim.windows[1] |
|
36
|
|
|
vim.command('vsplit') |
|
37
|
|
|
assert vim.windows[1].width == vim.windows[0].width // 2 |
|
38
|
|
|
vim.windows[1].width = 2 |
|
39
|
|
|
assert vim.windows[1].width == 2 |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
def test_vars(vim): |
|
|
|
|
|
|
43
|
|
|
vim.current.window.vars['python'] = [1, 2, {'3': 1}] |
|
44
|
|
|
assert vim.current.window.vars['python'] == [1, 2, {'3': 1}] |
|
45
|
|
|
assert vim.eval('w:python') == [1, 2, {'3': 1}] |
|
46
|
|
|
assert vim.current.window.vars.get('python') == [1, 2, {'3': 1}] |
|
47
|
|
|
|
|
48
|
|
|
del vim.current.window.vars['python'] |
|
49
|
|
|
with pytest.raises(KeyError): |
|
50
|
|
|
vim.current.window.vars['python'] |
|
51
|
|
|
assert vim.eval('exists("w:python")') == 0 |
|
52
|
|
|
|
|
53
|
|
|
with pytest.raises(KeyError): |
|
54
|
|
|
del vim.current.window.vars['python'] |
|
55
|
|
|
|
|
56
|
|
|
assert vim.current.window.vars.get('python', 'default') == 'default' |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
def test_options(vim): |
|
|
|
|
|
|
60
|
|
|
vim.current.window.options['colorcolumn'] = '4,3' |
|
61
|
|
|
assert vim.current.window.options['colorcolumn'] == '4,3' |
|
62
|
|
|
# global-local option |
|
63
|
|
|
vim.current.window.options['statusline'] = 'window-status' |
|
64
|
|
|
assert vim.current.window.options['statusline'] == 'window-status' |
|
65
|
|
|
assert vim.options['statusline'] == '' |
|
66
|
|
|
|
|
67
|
|
|
with pytest.raises(KeyError) as excinfo: |
|
68
|
|
|
vim.current.window.options['doesnotexist'] |
|
69
|
|
|
assert excinfo.value.args == ("Invalid option name: 'doesnotexist'",) |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
def test_position(vim): |
|
73
|
|
|
height = vim.windows[0].height |
|
74
|
|
|
width = vim.windows[0].width |
|
75
|
|
|
vim.command('split') |
|
76
|
|
|
vim.command('vsplit') |
|
77
|
|
|
assert (vim.windows[0].row, vim.windows[0].col) == (0, 0) |
|
78
|
|
|
vsplit_pos = width / 2 |
|
79
|
|
|
split_pos = height / 2 |
|
80
|
|
|
assert vim.windows[1].row == 0 |
|
81
|
|
|
assert vsplit_pos - 1 <= vim.windows[1].col <= vsplit_pos + 1 |
|
82
|
|
|
assert split_pos - 1 <= vim.windows[2].row <= split_pos + 1 |
|
83
|
|
|
assert vim.windows[2].col == 0 |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
def test_tabpage(vim): |
|
87
|
|
|
vim.command('tabnew') |
|
88
|
|
|
vim.command('vsplit') |
|
89
|
|
|
assert vim.windows[0].tabpage == vim.tabpages[0] |
|
90
|
|
|
assert vim.windows[1].tabpage == vim.tabpages[1] |
|
91
|
|
|
assert vim.windows[2].tabpage == vim.tabpages[1] |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
def test_valid(vim): |
|
95
|
|
|
vim.command('split') |
|
96
|
|
|
window = vim.windows[1] |
|
97
|
|
|
vim.current.window = window |
|
98
|
|
|
assert window.valid |
|
99
|
|
|
vim.command('q') |
|
100
|
|
|
assert not window.valid |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
def test_number(vim): |
|
104
|
|
|
curnum = vim.current.window.number |
|
105
|
|
|
vim.command('bot split') |
|
106
|
|
|
assert vim.current.window.number == curnum + 1 |
|
107
|
|
|
vim.command('bot split') |
|
108
|
|
|
assert vim.current.window.number == curnum + 2 |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
def test_handle(vim): |
|
112
|
|
|
hnd1 = vim.current.window.handle |
|
113
|
|
|
vim.command('bot split') |
|
114
|
|
|
hnd2 = vim.current.window.handle |
|
115
|
|
|
assert hnd2 != hnd1 |
|
116
|
|
|
vim.command('bot split') |
|
117
|
|
|
hnd3 = vim.current.window.handle |
|
118
|
|
|
assert hnd1 != hnd2 != hnd3 |
|
119
|
|
|
vim.command('wincmd w') |
|
120
|
|
|
assert vim.current.window.handle == hnd1 |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
def test_repr(vim): |
|
124
|
|
|
assert repr(vim.current.window) == "<Window(handle=1000)>" |
|
125
|
|
|
|