comparison src/testdir/test_popupwin.vim @ 17123:efc6f5e3b543 v8.1.1561

patch 8.1.1561: popup_setoptions() is not implemented yet commit https://github.com/vim/vim/commit/ae943150d3a2868a89df802c9f530331474451ec Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 16 22:54:14 2019 +0200 patch 8.1.1561: popup_setoptions() is not implemented yet Problem: Popup_setoptions() is not implemented yet. Solution: Implement popup_setoptions(). Also add more fields to popup_getoptions().
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Jun 2019 23:00:05 +0200
parents 808ea76535a9
children b4eb06233448
comparison
equal deleted inserted replaced
17122:310e8655d123 17123:efc6f5e3b543
127 \ 'height': 3, 127 \ 'height': 3,
128 \ 'core_height': 1, 128 \ 'core_height': 1,
129 \ 'visible': 1} 129 \ 'visible': 1}
130 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", 130 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
131 call assert_equal(with_border_or_padding, popup_getpos(winid)) 131 call assert_equal(with_border_or_padding, popup_getpos(winid))
132 132 let options = popup_getoptions(winid)
133 let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []}) 133 call assert_equal([], options.border)
134 call assert_false(has_key(options, "padding"))
135
136 let winid = popup_create('hello padding', {'line': 2, 'col': 3, 'padding': []})
137 let with_border_or_padding.width = 15
138 let with_border_or_padding.core_width = 13
134 call assert_equal(with_border_or_padding, popup_getpos(winid)) 139 call assert_equal(with_border_or_padding, popup_getpos(winid))
140 let options = popup_getoptions(winid)
141 call assert_false(has_key(options, "border"))
142 call assert_equal([], options.padding)
143
144 call popup_setoptions(winid, {
145 \ 'padding': [1, 2, 3, 4],
146 \ 'border': [4, 0, 7, 8],
147 \ 'borderhighlight': ['Top', 'Right', 'Bottom', 'Left'],
148 \ 'borderchars': ['1', '^', '2', '>', '3', 'v', '4', '<'],
149 \ })
150 let options = popup_getoptions(winid)
151 call assert_equal([1, 0, 1, 1], options.border)
152 call assert_equal([1, 2, 3, 4], options.padding)
153 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
154 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
135 155
136 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []}) 156 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
137 call assert_equal({ 157 call assert_equal({
138 \ 'line': 3, 158 \ 'line': 3,
139 \ 'core_line': 5, 159 \ 'core_line': 5,
142 \ 'width': 14, 162 \ 'width': 14,
143 \ 'core_width': 10, 163 \ 'core_width': 10,
144 \ 'height': 5, 164 \ 'height': 5,
145 \ 'core_height': 1, 165 \ 'core_height': 1,
146 \ 'visible': 1}, popup_getpos(winid)) 166 \ 'visible': 1}, popup_getpos(winid))
167
168 call popup_clear()
147 endfunc 169 endfunc
148 170
149 func Test_popup_with_syntax_win_execute() 171 func Test_popup_with_syntax_win_execute()
150 if !CanRunVimInTerminal() 172 if !CanRunVimInTerminal()
151 throw 'Skipped: cannot make screendumps' 173 throw 'Skipped: cannot make screendumps'
286 call VerifyScreenDump(buf, 'Test_popupwin_firstline', {}) 308 call VerifyScreenDump(buf, 'Test_popupwin_firstline', {})
287 309
288 " clean up 310 " clean up
289 call StopVimInTerminal(buf) 311 call StopVimInTerminal(buf)
290 call delete('XtestPopupFirstline') 312 call delete('XtestPopupFirstline')
313
314 let winid = popup_create(['1111', '222222', '33333', '44444'], {
315 \ 'maxheight': 2,
316 \ 'firstline': 3,
317 \ })
318 call assert_equal(3, popup_getoptions(winid).firstline)
319 call popup_setoptions(winid, {'firstline': 1})
320 call assert_equal(1, popup_getoptions(winid).firstline)
321
322 call popup_close(winid)
291 endfunc 323 endfunc
292 324
293 func Test_popup_drag() 325 func Test_popup_drag()
294 if !CanRunVimInTerminal() 326 if !CanRunVimInTerminal()
295 throw 'Skipped: cannot make screendumps' 327 throw 'Skipped: cannot make screendumps'
976 call VerifyScreenDump(buf, 'Test_popupwin_title', {}) 1008 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
977 1009
978 " clean up 1010 " clean up
979 call StopVimInTerminal(buf) 1011 call StopVimInTerminal(buf)
980 call delete('XtestPopupTitle') 1012 call delete('XtestPopupTitle')
1013
1014 let winid = popup_create('something', {'title': 'Some Title'})
1015 call assert_equal('Some Title', popup_getoptions(winid).title)
1016 call popup_setoptions(winid, {'title': 'Another Title'})
1017 call assert_equal('Another Title', popup_getoptions(winid).title)
1018
1019 call popup_clear()
981 endfunc 1020 endfunc
982 1021
983 func Test_popup_close_callback() 1022 func Test_popup_close_callback()
984 func PopupDone(id, result) 1023 func PopupDone(id, result)
985 let g:result = a:result 1024 let g:result = a:result
1228 1267
1229 exe "normal gg0/word\<CR>" 1268 exe "normal gg0/word\<CR>"
1230 let winid = popup_atcursor('text', {'moved': 'any'}) 1269 let winid = popup_atcursor('text', {'moved': 'any'})
1231 redraw 1270 redraw
1232 call assert_equal(1, popup_getpos(winid).visible) 1271 call assert_equal(1, popup_getpos(winid).visible)
1272 call assert_equal([4, 4], popup_getoptions(winid).moved)
1233 " trigger the check for last_cursormoved by going into insert mode 1273 " trigger the check for last_cursormoved by going into insert mode
1234 call feedkeys("li\<Esc>", 'xt') 1274 call feedkeys("li\<Esc>", 'xt')
1235 call assert_equal({}, popup_getpos(winid)) 1275 call assert_equal({}, popup_getpos(winid))
1236 call popup_clear() 1276 call popup_clear()
1237 1277
1238 exe "normal gg0/word\<CR>" 1278 exe "normal gg0/word\<CR>"
1239 let winid = popup_atcursor('text', {'moved': 'word'}) 1279 let winid = popup_atcursor('text', {'moved': 'word'})
1240 redraw 1280 redraw
1241 call assert_equal(1, popup_getpos(winid).visible) 1281 call assert_equal(1, popup_getpos(winid).visible)
1282 call assert_equal([4, 7], popup_getoptions(winid).moved)
1242 call feedkeys("hi\<Esc>", 'xt') 1283 call feedkeys("hi\<Esc>", 'xt')
1243 call assert_equal({}, popup_getpos(winid)) 1284 call assert_equal({}, popup_getpos(winid))
1244 call popup_clear() 1285 call popup_clear()
1245 1286
1246 exe "normal gg0/word\<CR>" 1287 exe "normal gg0/word\<CR>"
1247 let winid = popup_atcursor('text', {'moved': 'word'}) 1288 let winid = popup_atcursor('text', {'moved': 'word'})
1248 redraw 1289 redraw
1249 call assert_equal(1, popup_getpos(winid).visible) 1290 call assert_equal(1, popup_getpos(winid).visible)
1291 call assert_equal([4, 7], popup_getoptions(winid).moved)
1250 call feedkeys("li\<Esc>", 'xt') 1292 call feedkeys("li\<Esc>", 'xt')
1251 call assert_equal(1, popup_getpos(winid).visible) 1293 call assert_equal(1, popup_getpos(winid).visible)
1252 call feedkeys("ei\<Esc>", 'xt') 1294 call feedkeys("ei\<Esc>", 'xt')
1253 call assert_equal(1, popup_getpos(winid).visible) 1295 call assert_equal(1, popup_getpos(winid).visible)
1254 call feedkeys("eli\<Esc>", 'xt') 1296 call feedkeys("eli\<Esc>", 'xt')
1258 " WORD is the default 1300 " WORD is the default
1259 exe "normal gg0/WORD\<CR>" 1301 exe "normal gg0/WORD\<CR>"
1260 let winid = popup_atcursor('text', {}) 1302 let winid = popup_atcursor('text', {})
1261 redraw 1303 redraw
1262 call assert_equal(1, popup_getpos(winid).visible) 1304 call assert_equal(1, popup_getpos(winid).visible)
1305 call assert_equal([2, 15], popup_getoptions(winid).moved)
1263 call feedkeys("eli\<Esc>", 'xt') 1306 call feedkeys("eli\<Esc>", 'xt')
1264 call assert_equal(1, popup_getpos(winid).visible) 1307 call assert_equal(1, popup_getpos(winid).visible)
1265 call feedkeys("wi\<Esc>", 'xt') 1308 call feedkeys("wi\<Esc>", 'xt')
1266 call assert_equal(1, popup_getpos(winid).visible) 1309 call assert_equal(1, popup_getpos(winid).visible)
1267 call feedkeys("Eli\<Esc>", 'xt') 1310 call feedkeys("Eli\<Esc>", 'xt')
1375 \ 'filter': 'popup_filter_yesno', 1418 \ 'filter': 'popup_filter_yesno',
1376 \ 'callback': 'QuitCallback', 1419 \ 'callback': 'QuitCallback',
1377 \ }) 1420 \ })
1378 redraw 1421 redraw
1379 call assert_equal(0, popup_getpos(winid).visible) 1422 call assert_equal(0, popup_getpos(winid).visible)
1423 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1424 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
1380 exe "normal anot used by filter\<Esc>" 1425 exe "normal anot used by filter\<Esc>"
1381 call assert_equal('not used by filter', getline(1)) 1426 call assert_equal('not used by filter', getline(1))
1382 1427
1383 call popup_show(winid) 1428 call popup_show(winid)
1384 call feedkeys('y', "xt") 1429 call feedkeys('y', "xt")
1385 call assert_equal(1, s:cb_res) 1430 call assert_equal(1, s:cb_res)
1386 1431
1387 bwipe! 1432 bwipe!
1388 delfunc QuitCallback 1433 delfunc QuitCallback
1389 endfunc 1434 endfunc
1435
1436 " Test options not checked elsewhere
1437 func Test_set_get_options()
1438 let winid = popup_create('some text', {'highlight': 'Beautiful'})
1439 let options = popup_getoptions(winid)
1440 call assert_equal(1, options.wrap)
1441 call assert_equal(0, options.drag)
1442 call assert_equal('Beautiful', options.highlight)
1443
1444 call popup_setoptions(winid, {'wrap': 0, 'drag': 1, 'highlight': 'Another'})
1445 let options = popup_getoptions(winid)
1446 call assert_equal(0, options.wrap)
1447 call assert_equal(1, options.drag)
1448 call assert_equal('Another', options.highlight)
1449
1450 call popup_close(winid)
1451 endfunc