comparison src/testdir/test_popupwin.vim @ 16857:4de94f6161f2 v8.1.1430

patch 8.1.1430: popup window option "wrap" not supported commit https://github.com/vim/vim/commit/402502d0e4019ca97330eff40b9fb13736304896 Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 30 22:07:36 2019 +0200 patch 8.1.1430: popup window option "wrap" not supported Problem: Popup window option "wrap" not supported. Solution: Implement it.
author Bram Moolenaar <Bram@vim.org>
date Thu, 30 May 2019 22:15:06 +0200
parents e6bcccccbf7b
children 0154363d3b98
comparison
equal deleted inserted replaced
16856:04692a1fa962 16857:4de94f6161f2
82 82
83 func Test_popup_with_syntax_setbufvar() 83 func Test_popup_with_syntax_setbufvar()
84 if !CanRunVimInTerminal() 84 if !CanRunVimInTerminal()
85 return 85 return
86 endif 86 endif
87 call writefile([ 87 let lines =<< trim END
88 \ "call setline(1, range(1, 100))", 88 call setline(1, range(1, 100))
89 \ "hi PopupColor ctermbg=lightgrey", 89 hi PopupColor ctermbg=lightgrey
90 \ "let winid = popup_create([", 90 let winid = popup_create([
91 \ "\\ '#include <stdio.h>',", 91 \ '#include <stdio.h>',
92 \ "\\ 'int main(void)',", 92 \ 'int main(void)',
93 \ "\\ '{',", 93 \ '{',
94 \ "\\ ' printf(567);',", 94 \ ' printf(567);',
95 \ "\\ '}',", 95 \ '}',
96 \ "\\], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})", 96 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
97 \ "call setbufvar(winbufnr(winid), '&syntax', 'cpp')", 97 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
98 \], 'XtestPopup') 98 END
99 call writefile(lines, 'XtestPopup')
99 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) 100 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
100 call VerifyScreenDump(buf, 'Test_popupwin_11', {}) 101 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
102
103 " clean up
104 call StopVimInTerminal(buf)
105 call delete('XtestPopup')
106 endfunc
107
108 func Test_popup_with_wrap()
109 if !CanRunVimInTerminal()
110 return
111 endif
112 let lines =<< trim END
113 call setline(1, range(1, 100))
114 let winid = popup_create(
115 \ 'a long line that wont fit',
116 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
117 END
118 call writefile(lines, 'XtestPopup')
119 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
120 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
121
122 " clean up
123 call StopVimInTerminal(buf)
124 call delete('XtestPopup')
125 endfunc
126
127 func Test_popup_without_wrap()
128 if !CanRunVimInTerminal()
129 return
130 endif
131 let lines =<< trim END
132 call setline(1, range(1, 100))
133 let winid = popup_create(
134 \ 'a long line that wont fit',
135 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
136 END
137 call writefile(lines, 'XtestPopup')
138 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
139 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
101 140
102 " clean up 141 " clean up
103 call StopVimInTerminal(buf) 142 call StopVimInTerminal(buf)
104 call delete('XtestPopup') 143 call delete('XtestPopup')
105 endfunc 144 endfunc
154 \ 'minwidth': 20, 193 \ 'minwidth': 20,
155 \}) 194 \})
156 redraw 195 redraw
157 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') 196 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
158 call assert_equal('world', line) 197 call assert_equal('world', line)
159 call assert_equal(1, popup_getposition(winid).visible) 198 call assert_equal(1, popup_getpos(winid).visible)
160 199
161 call popup_hide(winid) 200 call popup_hide(winid)
162 redraw 201 redraw
163 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') 202 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
164 call assert_equal('hello', line) 203 call assert_equal('hello', line)
165 call assert_equal(0, popup_getposition(winid).visible) 204 call assert_equal(0, popup_getpos(winid).visible)
166 205
167 call popup_show(winid) 206 call popup_show(winid)
168 redraw 207 redraw
169 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') 208 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
170 call assert_equal('world', line) 209 call assert_equal('world', line)
171 call assert_equal(1, popup_getposition(winid).visible) 210 call assert_equal(1, popup_getpos(winid).visible)
172 211
173 212
174 call popup_close(winid) 213 call popup_close(winid)
175 redraw 214 redraw
176 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') 215 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
214 call popup_close(winid) 253 call popup_close(winid)
215 254
216 bwipe! 255 bwipe!
217 endfunc 256 endfunc
218 257
219 func Test_popup_getposition() 258 func Test_popup_getpos()
220 let winid = popup_create('hello', { 259 let winid = popup_create('hello', {
221 \ 'line': 2, 260 \ 'line': 2,
222 \ 'col': 3, 261 \ 'col': 3,
223 \ 'minwidth': 10, 262 \ 'minwidth': 10,
224 \ 'minheight': 11, 263 \ 'minheight': 11,
225 \}) 264 \})
226 redraw 265 redraw
227 let res = popup_getposition(winid) 266 let res = popup_getpos(winid)
228 call assert_equal(2, res.line) 267 call assert_equal(2, res.line)
229 call assert_equal(3, res.col) 268 call assert_equal(3, res.col)
230 call assert_equal(10, res.width) 269 call assert_equal(10, res.width)
231 call assert_equal(11, res.height) 270 call assert_equal(11, res.height)
232 call assert_equal(1, res.visible) 271 call assert_equal(1, res.visible)
244 \ ] 283 \ ]
245 284
246 for test in tests 285 for test in tests
247 let winid = popup_create(test[0], {'line': 2, 'col': 3}) 286 let winid = popup_create(test[0], {'line': 2, 'col': 3})
248 redraw 287 redraw
249 let position = popup_getposition(winid) 288 let position = popup_getpos(winid)
250 call assert_equal(test[1], position.width) 289 call assert_equal(test[1], position.width)
251 call popup_close(winid) 290 call popup_close(winid)
252 endfor 291 endfor
253 endfunc 292 endfunc
254 293
260 \ ] 299 \ ]
261 for test in tests 300 for test in tests
262 let winid = popup_create(test[0], 301 let winid = popup_create(test[0],
263 \ {'line': 2, 'col': 3, 'maxwidth': 12}) 302 \ {'line': 2, 'col': 3, 'maxwidth': 12})
264 redraw 303 redraw
265 let position = popup_getposition(winid) 304 let position = popup_getpos(winid)
266 call assert_equal(test[1], position.width) 305 call assert_equal(test[1], position.width)
267 call assert_equal(test[2], position.height) 306 call assert_equal(test[2], position.height)
268 307
269 call popup_close(winid) 308 call popup_close(winid)
270 call assert_equal({}, popup_getposition(winid)) 309 call assert_equal({}, popup_getpos(winid))
271 endfor 310 endfor
272 endfunc 311 endfunc
273 312
274 func Test_popup_getoptions() 313 func Test_popup_getoptions()
275 let winid = popup_create('hello', { 314 let winid = popup_create('hello', {
380 redraw 419 redraw
381 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') 420 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
382 call assert_equal('xvimxxxxxxxxxxxxx', line) 421 call assert_equal('xvimxxxxxxxxxxxxx', line)
383 call popup_close(winid) 422 call popup_close(winid)
384 423
424 " just enough room above
425 call cursor(3, 3)
426 redraw
427 let winid = popup_atcursor(['vim', 'is great'], {})
428 redraw
429 let pos = popup_getpos(winid)
430 call assert_equal(1, pos.line)
431 call popup_close(winid)
432
433 " not enough room above, popup goes below the cursor
434 call cursor(3, 3)
435 redraw
436 let winid = popup_atcursor(['vim', 'is', 'great'], {})
437 redraw
438 let pos = popup_getpos(winid)
439 call assert_equal(4, pos.line)
440 call popup_close(winid)
441
385 bwipe! 442 bwipe!
386 endfunc 443 endfunc