Mercurial > vim
comparison src/testdir/test_termcodes.vim @ 16300:f3d579f009d1 v8.1.1155
patch 8.1.1155: termcodes tests can be improved
commit https://github.com/vim/vim/commit/3fbd2d7c316eaeea463b2f84f29b36d439306bf9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 11 23:56:16 2019 +0200
patch 8.1.1155: termcodes tests can be improved
Problem: Termcodes tests can be improved.
Solution: Add helper functions to simplify tests. Dragging statusline for
xterm and sgr. (Dominique Pelle, closes #4237)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 12 Apr 2019 00:00:05 +0200 |
parents | ed5172ae1c32 |
children | 5b8b849dc3aa |
comparison
equal
deleted
inserted
replaced
16299:5b592d4eb23a | 16300:f3d579f009d1 |
---|---|
3 " This only works for Unix in a terminal | 3 " This only works for Unix in a terminal |
4 if has('gui_running') || !has('unix') | 4 if has('gui_running') || !has('unix') |
5 finish | 5 finish |
6 endif | 6 endif |
7 | 7 |
8 " Helper function to emit a terminal escape code. | |
9 func TerminalEscapeCode(code_xterm, code_sgr, row, col, m) | |
10 if &ttymouse ==# 'xterm' | |
11 " need to use byte encoding here. | |
12 let str = list2str([a:code_xterm, a:col + 0x20, a:row + 0x20]) | |
13 if has('iconv') | |
14 let bytes = iconv(str, 'utf-8', 'latin1') | |
15 else | |
16 " Hopefully the numbers are not too big. | |
17 let bytes = str | |
18 endif | |
19 call feedkeys("\<Esc>[M" .. bytes, 'Lx!') | |
20 elseif &ttymouse ==# 'sgr' | |
21 call feedkeys(printf("\<Esc>[<%d;%d;%d%s", a:code_sgr, a:col, a:row, a:m), 'Lx!') | |
22 endif | |
23 endfunc | |
24 | |
25 func MouseLeftClick(row, col) | |
26 call TerminalEscapeCode(0x20, 0, a:row, a:col, 'M') | |
27 endfunc | |
28 | |
29 func MouseLeftRelease(row, col) | |
30 call TerminalEscapeCode(0x23, 3, a:row, a:col, 'm') | |
31 endfunc | |
32 | |
33 func MouseLeftDrag(row, col) | |
34 call TerminalEscapeCode(0x43, 0x20, a:row, a:col, 'M') | |
35 endfunc | |
36 | |
37 func MouseWheelUp(row, col) | |
38 call TerminalEscapeCode(0x40, 0x40, a:row, a:col, 'M') | |
39 endfunc | |
40 | |
41 func MouseWheelDown(row, col) | |
42 call TerminalEscapeCode(0x41, 0x41, a:row, a:col, 'M') | |
43 endfunc | |
44 | |
8 func Test_xterm_mouse_click() | 45 func Test_xterm_mouse_click() |
9 new | 46 new |
10 let save_mouse = &mouse | 47 let save_mouse = &mouse |
11 let save_term = &term | 48 let save_term = &term |
12 let save_ttymouse = &ttymouse | 49 let save_ttymouse = &ttymouse |
13 set mouse=a | 50 set mouse=a term=xterm |
14 set term=xterm | |
15 call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer']) | 51 call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer']) |
16 redraw | |
17 | 52 |
18 " Xterm mouse click | 53 for ttymouse_val in ['xterm', 'sgr'] |
19 set ttymouse=xterm | 54 exe 'set ttymouse=' . ttymouse_val |
20 let button = 0x20 " left down | 55 go |
21 let row = 2 + 32 | 56 call assert_equal([0, 1, 1, 0], getpos('.')) |
22 let col = 6 + 32 | 57 let row = 2 |
23 call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!') | 58 let col = 6 |
24 | 59 call MouseLeftClick(row, col) |
25 let button = 0x23 " release | 60 call MouseLeftRelease(row, col) |
26 call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!') | 61 call assert_equal([0, 2, 6, 0], getpos('.')) |
27 | 62 endfor |
28 call assert_equal([0, 2, 6, 0], getpos('.')) | |
29 | |
30 " SGR mouse click | |
31 set ttymouse=sgr | |
32 let button = 0 " left down | |
33 let row = 3 | |
34 let col = 9 | |
35 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
36 | |
37 let button = 3 " release | |
38 call feedkeys(printf("\<Esc>[<%d;%d;%dm", button, col, row), 'Lx!') | |
39 | |
40 call assert_equal([0, 3, 9, 0], getpos('.')) | |
41 | 63 |
42 let &mouse = save_mouse | 64 let &mouse = save_mouse |
43 let &term = save_term | 65 let &term = save_term |
44 let &ttymouse = save_ttymouse | 66 let &ttymouse = save_ttymouse |
45 bwipe! | 67 bwipe! |
48 func Test_xterm_mouse_wheel() | 70 func Test_xterm_mouse_wheel() |
49 new | 71 new |
50 let save_mouse = &mouse | 72 let save_mouse = &mouse |
51 let save_term = &term | 73 let save_term = &term |
52 let save_ttymouse = &ttymouse | 74 let save_ttymouse = &ttymouse |
53 set mouse=a | 75 set mouse=a term=xterm |
54 set term=xterm | |
55 call setline(1, range(1, 100)) | 76 call setline(1, range(1, 100)) |
56 | 77 |
57 " Test Xterm mouse wheel. | 78 for ttymouse_val in ['xterm', 'sgr'] |
58 set ttymouse=xterm | 79 exe 'set ttymouse=' . ttymouse_val |
59 let button = 0x41 " wheel down. | 80 go |
60 let row = 1 + 32 " cursor position for mouse wheel is not relevant. | 81 call assert_equal(1, line('w0')) |
61 let col = 1 + 32 | 82 call assert_equal([0, 1, 1, 0], getpos('.')) |
62 | 83 |
63 call assert_equal(1, line('w0')) | 84 call MouseWheelDown(1, 1) |
64 call assert_equal([0, 1, 1, 0], getpos('.')) | 85 call assert_equal(4, line('w0')) |
65 call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!') | 86 call assert_equal([0, 4, 1, 0], getpos('.')) |
66 call assert_equal(4, line('w0')) | |
67 call assert_equal([0, 4, 1, 0], getpos('.')) | |
68 call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!') | |
69 call assert_equal(7, line('w0')) | |
70 call assert_equal([0, 7, 1, 0], getpos('.')) | |
71 | 87 |
72 let button = 0x40 " wheel up. | 88 call MouseWheelDown(1, 1) |
89 call assert_equal(7, line('w0')) | |
90 call assert_equal([0, 7, 1, 0], getpos('.')) | |
73 | 91 |
74 call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!') | 92 call MouseWheelUp(1, 1) |
75 call assert_equal(4, line('w0')) | 93 call assert_equal(4, line('w0')) |
76 call assert_equal([0, 7, 1, 0], getpos('.')) | 94 call assert_equal([0, 7, 1, 0], getpos('.')) |
77 call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!') | |
78 call assert_equal(1, line('w0')) | |
79 call assert_equal([0, 7, 1, 0], getpos('.')) | |
80 | 95 |
81 " Test SGR mouse wheel. | 96 call MouseWheelUp(1, 1) |
82 set ttymouse=sgr | 97 call assert_equal(1, line('w0')) |
83 go | 98 call assert_equal([0, 7, 1, 0], getpos('.')) |
84 let button = 0x41 " wheel down. | 99 endfor |
85 let row = 1 " cursor position for mouse wheel is not relevant. | |
86 let col = 1 | |
87 | |
88 call assert_equal(1, line('w0')) | |
89 call assert_equal([0, 1, 1, 0], getpos('.')) | |
90 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
91 call assert_equal(4, line('w0')) | |
92 call assert_equal([0, 4, 1, 0], getpos('.')) | |
93 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
94 call assert_equal(7, line('w0')) | |
95 call assert_equal([0, 7, 1, 0], getpos('.')) | |
96 | |
97 let button = 0x40 " wheel up. | |
98 | |
99 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
100 call assert_equal(4, line('w0')) | |
101 call assert_equal([0, 7, 1, 0], getpos('.')) | |
102 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
103 call assert_equal(1, line('w0')) | |
104 call assert_equal([0, 7, 1, 0], getpos('.')) | |
105 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
106 call assert_equal(1, line('w0')) | |
107 call assert_equal([0, 7, 1, 0], getpos('.')) | |
108 | 100 |
109 let &mouse = save_mouse | 101 let &mouse = save_mouse |
110 let &term = save_term | 102 let &term = save_term |
111 let &ttymouse = save_ttymouse | 103 let &ttymouse = save_ttymouse |
112 bwipe! | 104 bwipe! |
114 | 106 |
115 func Test_xterm_mouse_drag_window_separator() | 107 func Test_xterm_mouse_drag_window_separator() |
116 let save_mouse = &mouse | 108 let save_mouse = &mouse |
117 let save_term = &term | 109 let save_term = &term |
118 let save_ttymouse = &ttymouse | 110 let save_ttymouse = &ttymouse |
119 set mouse=a | 111 set mouse=a term=xterm |
120 set term=xterm | |
121 set ttymouse=sgr | |
122 | 112 |
123 " Split horizontally and test dragging the horizontal window separator. | 113 for ttymouse_val in ['xterm', 'sgr'] |
124 split | 114 exe 'set ttymouse=' . ttymouse_val |
125 let rowseparator = winheight(0) + 1 | |
126 | 115 |
127 let button = 0 " left down. | 116 " Split horizontally and test dragging the horizontal window separator. |
128 let row = rowseparator | 117 split |
129 let col = 1 | 118 let rowseparator = winheight(0) + 1 |
130 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | 119 let row = rowseparator |
120 let col = 1 | |
121 call MouseLeftClick(row, col) | |
131 | 122 |
132 let drag = 32 | 123 let row -= 1 |
133 let row -= 1 | 124 call MouseLeftDrag(row, col) |
134 call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!') | 125 call assert_equal(rowseparator - 1, winheight(0) + 1) |
135 call assert_equal(rowseparator - 1, winheight(0) + 1) | 126 let row += 1 |
136 let row += 1 | 127 call MouseLeftDrag(row, col) |
137 call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!') | 128 call assert_equal(rowseparator, winheight(0) + 1) |
138 call assert_equal(rowseparator, winheight(0) + 1) | 129 call MouseLeftRelease(row, col) |
130 call assert_equal(rowseparator, winheight(0) + 1) | |
139 | 131 |
140 let release = 3 | 132 bwipe! |
141 call feedkeys(printf("\<Esc>[<%d;%d;%dm", release, col, row), 'Lx!') | |
142 call assert_equal(rowseparator, winheight(0) + 1) | |
143 | 133 |
144 bwipe! | 134 " Split vertically and test dragging the vertical window separator. |
135 vsplit | |
136 let colseparator = winwidth(0) + 1 | |
145 | 137 |
146 " Split vertically and test dragging the vertical window separator. | 138 let row = 1 |
147 vsplit | 139 let col = colseparator |
148 let colseparator = winwidth(0) + 1 | 140 call MouseLeftClick(row, col) |
141 let col -= 1 | |
142 call MouseLeftDrag(row, col) | |
143 call assert_equal(colseparator - 1, winwidth(0) + 1) | |
144 let col += 1 | |
145 call MouseLeftDrag(row, col) | |
146 call assert_equal(colseparator, winwidth(0) + 1) | |
147 call MouseLeftRelease(row, col) | |
148 call assert_equal(colseparator, winwidth(0) + 1) | |
149 | 149 |
150 let button = 0 | 150 bwipe! |
151 let row = 1 | 151 endfor |
152 let col = colseparator | |
153 call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!') | |
154 | 152 |
155 let drag = 32 | |
156 let col -= 1 | |
157 call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!') | |
158 call assert_equal(colseparator - 1, winwidth(0) + 1) | |
159 let col += 1 | |
160 call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!') | |
161 call assert_equal(colseparator, winwidth(0) + 1) | |
162 | |
163 let release = 3 | |
164 call feedkeys(printf("\<Esc>[<%d;%d;%dm", release, col, row), 'Lx!') | |
165 call assert_equal(colseparator, winwidth(0) + 1) | |
166 | |
167 bwipe! | |
168 let &mouse = save_mouse | 153 let &mouse = save_mouse |
169 let &term = save_term | 154 let &term = save_term |
170 let &ttymouse = save_ttymouse | 155 let &ttymouse = save_ttymouse |
171 endfunc | 156 endfunc |
157 | |
158 func Test_xterm_mouse_drag_statusline() | |
159 let save_mouse = &mouse | |
160 let save_term = &term | |
161 let save_ttymouse = &ttymouse | |
162 set mouse=a term=xterm | |
163 | |
164 for ttymouse_val in ['xterm', 'sgr'] | |
165 exe 'set ttymouse=' . ttymouse_val | |
166 | |
167 call assert_equal(1, &cmdheight) | |
168 let rowstatusline = winheight(0) + 1 | |
169 let row = rowstatusline | |
170 let col = 1 | |
171 call MouseLeftClick(row, col) | |
172 let row -= 1 | |
173 call MouseLeftDrag(row, col) | |
174 call assert_equal(2, &cmdheight) | |
175 call assert_equal(rowstatusline - 1, winheight(0) + 1) | |
176 let row += 1 | |
177 call MouseLeftDrag(row, col) | |
178 call assert_equal(1, &cmdheight) | |
179 call assert_equal(rowstatusline, winheight(0) + 1) | |
180 call MouseLeftRelease(row, col) | |
181 call assert_equal(1, &cmdheight) | |
182 call assert_equal(rowstatusline, winheight(0) + 1) | |
183 endfor | |
184 | |
185 let &mouse = save_mouse | |
186 let &term = save_term | |
187 let &ttymouse = save_ttymouse | |
188 endfunc |