blob: 65e59b77592e369ee09330e437344b61c688f554 [file] [log] [blame]
Bram Moolenaar877e9572016-08-04 20:05:50 +02001" Tests specifically for the GUI
2
Bram Moolenaar9f0139a2017-08-13 20:26:20 +02003source shared.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
5CheckCanRunGui
Bram Moolenaar877e9572016-08-04 20:05:50 +02006
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01007source setup_gui.vim
Bram Moolenaar13c724f2017-02-05 20:54:26 +01008
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01009func Setup()
10 call GUISetUpCommon()
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020011endfunc
12
13func TearDown()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010014 call GUITearDownCommon()
Bram Moolenaar877e9572016-08-04 20:05:50 +020015endfunc
16
17" Test for resetting "secure" flag after GUI has started.
Bram Moolenaar5d7ead32018-02-27 17:17:42 +010018" Must be run first, since it starts the GUI on Unix.
Bram Moolenaar877e9572016-08-04 20:05:50 +020019func Test_1_set_secure()
20 set exrc secure
21 gui -f
22 call assert_equal(1, has('gui_running'))
23endfunc
24
Bram Moolenaard5841f22017-03-05 13:27:25 +010025" As for non-GUI, a balloon_show() test was already added with patch 8.0.0401
26func Test_balloon_show()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020027 CheckFeature balloon_eval
28 " This won't do anything but must not crash either.
29 call balloon_show('hi!')
Bram Moolenaard5841f22017-03-05 13:27:25 +010030endfunc
31
Bram Moolenaar87748452017-03-12 17:10:33 +010032func Test_colorscheme()
Bram Moolenaaracc770a2020-04-12 15:11:06 +020033 call assert_equal('16777216', &t_Co)
34
Bram Moolenaar87748452017-03-12 17:10:33 +010035 let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
Bram Moolenaar60a68362018-04-30 15:40:48 +020036 let g:color_count = 0
37 augroup TestColors
38 au!
Bram Moolenaar5d09a402022-08-31 21:17:10 +010039 au ColorScheme * let g:color_count += 1
40 \ | let g:after_colors = g:color_count
41 \ | let g:color_after = expand('<amatch>')
42 au ColorSchemePre * let g:color_count += 1
43 \ | let g:before_colors = g:color_count
44 \ | let g:color_pre = expand('<amatch>')
Bram Moolenaar60a68362018-04-30 15:40:48 +020045 augroup END
Bram Moolenaar87748452017-03-12 17:10:33 +010046
47 colorscheme torte
48 redraw!
Bram Moolenaar87748452017-03-12 17:10:33 +010049 call assert_equal('dark', &background)
Bram Moolenaar60a68362018-04-30 15:40:48 +020050 call assert_equal(1, g:before_colors)
51 call assert_equal(2, g:after_colors)
Bram Moolenaar5d09a402022-08-31 21:17:10 +010052 call assert_equal('torte', g:color_pre)
53 call assert_equal('torte', g:color_after)
Bram Moolenaar6d4470b2019-01-08 21:05:51 +010054 call assert_equal("\ntorte", execute('colorscheme'))
55
56 let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g')
Bram Moolenaar98feace2022-05-14 12:34:43 +010057 " FIXME: temporarily check less while the colorscheme changes
58 " call assert_match("\nSearch xxx term=reverse cterm=reverse ctermfg=196 ctermbg=16 gui=reverse guifg=#ff0000 guibg=#000000", a)
59 call assert_match("\nSearch xxx term=reverse ", a)
Bram Moolenaar6d4470b2019-01-08 21:05:51 +010060
61 call assert_fails('colorscheme does_not_exist', 'E185:')
Bram Moolenaar5d09a402022-08-31 21:17:10 +010062 call assert_equal('does_not_exist', g:color_pre)
63 call assert_equal('torte', g:color_after)
Bram Moolenaar87748452017-03-12 17:10:33 +010064
65 exec 'colorscheme' colorscheme_saved
Bram Moolenaar60a68362018-04-30 15:40:48 +020066 augroup TestColors
67 au!
68 augroup END
69 unlet g:color_count g:after_colors g:before_colors
Bram Moolenaar87748452017-03-12 17:10:33 +010070 redraw!
71endfunc
72
Bram Moolenaar6f785742017-02-06 22:11:55 +010073func Test_getfontname_with_arg()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +010074 CheckX11BasedGui
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010075
Bram Moolenaar0b962e52022-04-03 18:02:37 +010076 if has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010077 " Invalid font name. The result should be an empty string.
78 call assert_equal('', getfontname('notexist'))
79
80 " Valid font name. This is usually the real name of 7x13 by default.
Bram Moolenaar87748452017-03-12 17:10:33 +010081 let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
82 call assert_match(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010083
84 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
85 " Invalid font name. The result should be the name plus the default size.
86 call assert_equal('notexist 10', getfontname('notexist'))
Bram Moolenaar0e05de42020-03-25 22:23:46 +010087 call assert_equal('', getfontname('*'))
Bram Moolenaar6f785742017-02-06 22:11:55 +010088
89 " Valid font name. This is usually the real name of Monospace by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010090 let fname = 'Bitstream Vera Sans Mono 12'
91 call assert_equal(fname, getfontname(fname))
92 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +010093endfunc
94
95func Test_getfontname_without_arg()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +010096 CheckX11BasedGui
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010097
98 let fname = getfontname()
99
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100100 if has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +0100101 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100102 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100103 elseif has('gui_motif')
Bram Moolenaar87748452017-03-12 17:10:33 +0100104 " 'expected' is DFLT_FONT of gui_x11.c or its real name.
105 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
106 call assert_match(pat, fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100107 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
108 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100109 call assert_equal('Monospace 10', fname)
110 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100111endfunc
112
Bram Moolenaar87748452017-03-12 17:10:33 +0100113func Test_getwinpos()
114 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
115 call assert_true(getwinposx() >= 0)
116 call assert_true(getwinposy() >= 0)
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200117 call assert_equal([getwinposx(), getwinposy()], getwinpos())
Bram Moolenaar87748452017-03-12 17:10:33 +0100118endfunc
119
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100120func Test_quoteplus()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100121 CheckX11BasedGui
122
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100123 let g:test_is_flaky = 1
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100124
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100125 let quoteplus_saved = @+
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100126
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100127 let test_call = 'Can you hear me?'
128 let test_response = 'Yes, I can.'
Bram Moolenaarde8be2b2022-06-16 14:45:41 +0100129 let testee = 'VIMRUNTIME=' .. $VIMRUNTIME .. '; export VIMRUNTIME;'
130 \ .. GetVimCommand() .. ' --noplugin --not-a-term -c ''%s'''
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100131 " Ignore the "failed to create input context" error.
132 let cmd = 'call test_ignore_error("E285") | '
133 \ . 'gui -f | '
134 \ . 'call feedkeys("'
135 \ . '\"+p'
136 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
137 \ . '\"+yis'
138 \ . ':q!\<CR>", "tx")'
139 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100140
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100141 " Set the quoteplus register to test_call, and another gvim will launched.
142 " Then, it first tries to paste the content of its own quotedplus register
143 " onto it. Second, it tries to substitute test_response for the pasted
144 " sentence. If the sentence is identical to test_call, the substitution
145 " should succeed. Third, it tries to yank the result of the substitution
146 " to its own quoteplus register, and last it quits. When system()
147 " returns, the content of the quoteplus register should be identical to
148 " test_response if those quoteplus registers are synchronized properly
149 " with/through the X11 clipboard.
150 let @+ = test_call
151 call system(run_vimtest)
152 call assert_equal(test_response, @+)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100153
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100154 let @+ = quoteplus_saved
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100155endfunc
156
Bram Moolenaard68a0042021-10-20 23:08:11 +0100157func Test_gui_read_stdin()
158 CheckUnix
159
160 call writefile(['some', 'lines'], 'Xstdin')
161 let script =<< trim END
162 call writefile(getline(1, '$'), 'XstdinOK')
163 qa!
164 END
165 call writefile(script, 'Xscript')
166
167 " Cannot use --not-a-term here, the "reading from stdin" message would not be
168 " displayed.
Bram Moolenaarb5912e02022-05-31 17:03:14 +0100169 " However, when using XIM we might get E285, do use it then.
170 if has('xim')
171 let vimcmd = GetVimCommand()
172 else
173 let vimcmd = substitute(GetVimCommand(), '--not-a-term', '', '')
174 endif
Bram Moolenaard68a0042021-10-20 23:08:11 +0100175
176 call system('cat Xstdin | ' .. vimcmd .. ' -f -g -S Xscript -')
177 call assert_equal(['some', 'lines'], readfile('XstdinOK'))
178
179 call delete('Xstdin')
180 call delete('XstdinOK')
181 call delete('Xscript')
182endfunc
183
Bram Moolenaar87748452017-03-12 17:10:33 +0100184func Test_set_background()
185 let background_saved = &background
186
187 set background&
188 call assert_equal('light', &background)
189
190 set background=dark
191 call assert_equal('dark', &background)
192
193 let &background = background_saved
194endfunc
195
Bram Moolenaard5841f22017-03-05 13:27:25 +0100196func Test_set_balloondelay()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200197 CheckOption balloondelay
Bram Moolenaard5841f22017-03-05 13:27:25 +0100198
199 let balloondelay_saved = &balloondelay
200
201 " Check if the default value is identical to that described in the manual.
202 set balloondelay&
203 call assert_equal(600, &balloondelay)
204
205 " Edge cases
206
207 " XXX This fact should be hidden so that people won't be tempted to write
208 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
209 " code.
210 set balloondelay=-1
211 call assert_equal(-1, &balloondelay)
212
213 " Though it's possible to interpret the zero delay to be 'as soon as
214 " possible' or even 'indefinite', its actual meaning depends on the GUI
215 " toolkit in use after all.
216 set balloondelay=0
217 call assert_equal(0, &balloondelay)
218
219 set balloondelay=1
220 call assert_equal(1, &balloondelay)
221
222 " Since p_bdelay is of type long currently, the upper bound can be
223 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100224 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
225 set balloondelay=2147483647
226 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100227
228 let &balloondelay = balloondelay_saved
229endfunc
230
231func Test_set_ballooneval()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200232 CheckOption ballooneval
Bram Moolenaard5841f22017-03-05 13:27:25 +0100233
234 let ballooneval_saved = &ballooneval
235
236 set ballooneval&
237 call assert_equal(0, &ballooneval)
238
239 set ballooneval
240 call assert_notequal(0, &ballooneval)
241
242 set noballooneval
243 call assert_equal(0, &ballooneval)
244
245 let &ballooneval = ballooneval_saved
246endfunc
247
248func Test_set_balloonexpr()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200249 CheckOption balloonexpr
Bram Moolenaard5841f22017-03-05 13:27:25 +0100250
251 let balloonexpr_saved = &balloonexpr
252
253 " Default value
254 set balloonexpr&
255 call assert_equal('', &balloonexpr)
256
257 " User-defined function
258 new
259 func MyBalloonExpr()
260 return 'Cursor is at line ' . v:beval_lnum .
261 \', column ' . v:beval_col .
262 \ ' of file ' . bufname(v:beval_bufnr) .
263 \ ' on word "' . v:beval_text . '"' .
264 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
265 endfunc
266 setl balloonexpr=MyBalloonExpr()
267 setl ballooneval
268 call assert_equal('MyBalloonExpr()', &balloonexpr)
269 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200270 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100271 " Also, check if textlock works as expected.
272 setl balloonexpr&
273 call assert_equal('', &balloonexpr)
274 delfunc MyBalloonExpr
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000275
276 " Using a script-local function
277 func s:NewBalloonExpr()
278 endfunc
279 set balloonexpr=s:NewBalloonExpr()
280 call assert_equal(expand('<SID>') .. 'NewBalloonExpr()', &balloonexpr)
281 set balloonexpr=<SID>NewBalloonExpr()
282 call assert_equal(expand('<SID>') .. 'NewBalloonExpr()', &balloonexpr)
283 delfunc s:NewBalloonExpr
Bram Moolenaard5841f22017-03-05 13:27:25 +0100284 bwipe!
285
286 " Multiline support
287 if has('balloon_multiline')
288 " Multiline balloon using NL
289 new
290 func MyBalloonFuncForMultilineUsingNL()
Dominique Pelle81b573d2022-03-22 21:14:55 +0000291 return "Multiline\nSupported\nBalloon\nusing NL"
Bram Moolenaard5841f22017-03-05 13:27:25 +0100292 endfunc
293 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
294 setl ballooneval
295 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
296 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200297 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100298 " expected. Also, check if textlock works as expected.
299 setl balloonexpr&
300 delfunc MyBalloonFuncForMultilineUsingNL
301 bwipe!
302
303 " Multiline balloon using List
304 new
305 func MyBalloonFuncForMultilineUsingList()
Dominique Pelle81b573d2022-03-22 21:14:55 +0000306 return [ 'Multiline', 'Supported', 'Balloon', 'using List' ]
Bram Moolenaard5841f22017-03-05 13:27:25 +0100307 endfunc
308 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
309 setl ballooneval
310 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
311 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200312 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100313 " expected. Also, check if textlock works as expected.
314 setl balloonexpr&
315 delfunc MyBalloonFuncForMultilineUsingList
316 bwipe!
317 endif
318
319 let &balloonexpr = balloonexpr_saved
320endfunc
321
Bram Moolenaar87748452017-03-12 17:10:33 +0100322" Invalid arguments are tested with test_options in conjunction with segfaults
323" caused by them (Patch 8.0.0357, 24922ec233).
324func Test_set_guicursor()
325 let guicursor_saved = &guicursor
326
327 let default = [
328 \ "n-v-c:block-Cursor/lCursor",
329 \ "ve:ver35-Cursor",
330 \ "o:hor50-Cursor",
331 \ "i-ci:ver25-Cursor/lCursor",
332 \ "r-cr:hor20-Cursor/lCursor",
333 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
334 \ ]
335
336 " Default Value
337 set guicursor&
338 call assert_equal(join(default, ','), &guicursor)
339
340 " Argument List Example 1
341 let opt_list = copy(default)
342 let opt_list[0] = "n-c-v:block-nCursor"
343 exec "set guicursor=" . join(opt_list, ',')
344 call assert_equal(join(opt_list, ','), &guicursor)
345 unlet opt_list
346
347 " Argument List Example 2
348 let opt_list = copy(default)
349 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
350 exec "set guicursor=" . join(opt_list, ',')
351 call assert_equal(join(opt_list, ','), &guicursor)
352 unlet opt_list
353
354 " 'a' Mode
355 set guicursor&
356 let &guicursor .= ',a:blinkon0'
357 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
358
359 let &guicursor = guicursor_saved
360endfunc
361
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100362func Test_set_guifont_errors()
363 if has('win32')
364 " Invalid font names are accepted in GTK GUI
365 call assert_fails('set guifont=xa1bc23d7f', 'E596:')
366 endif
367
368 " This only works if 'renderoptions' exists and does not work for Windows XP
369 " and older.
370 if exists('+renderoptions') && windowsversion() !~ '^[345]\.'
371 " doing this four times used to cause a crash
372 set renderoptions=type:directx
373 for i in range(5)
374 set guifont=
375 endfor
376 set renderoptions=
377 for i in range(5)
378 set guifont=
379 endfor
380 endif
381endfunc
382
Bram Moolenaar43dded82017-02-09 16:06:17 +0100383func Test_set_guifont()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100384 CheckX11BasedGui
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100385
386 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100387 if has('xfontset')
388 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100389 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100390 set guifontset=
391 endif
392
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100393 if has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100394 " Non-empty font list with invalid font names.
395 "
396 " This test is twofold: (1) It checks if the command fails as expected
397 " when there are no loadable fonts found in the list. (2) It checks if
398 " 'guifont' remains the same after the command loads none of the fonts
399 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100400 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100401 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100402 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100403
404 " Non-empty font list with a valid font name. Should pick up the first
405 " valid font.
406 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100407 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
408 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100409
410 " Empty list. Should fallback to the built-in default.
411 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100412 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
413 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100414
415 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
416 " For GTK, what we refer to as 'font names' in our manual are actually
417 " 'initial font patterns'. A valid font which matches the 'canonical font
418 " pattern' constructed from a given 'initial pattern' is to be looked up
419 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
420 " font names'.
421 "
422 " Non-empty list. Should always pick up the first element, no matter how
423 " strange it is, as explained above.
424 set guifont=(´・ω・`)\ 12,Courier\ 12
425 call assert_equal('(´・ω・`) 12', getfontname())
426
427 " Empty list. Should fallback to the built-in default.
428 set guifont=
429 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100430 endif
431
432 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100433 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100434 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100435 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100436endfunc
437
Bram Moolenaar10434672017-02-12 19:59:08 +0100438func Test_set_guifontset()
Bram Moolenaarce90e362019-09-08 18:58:44 +0200439 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100440 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100441
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200442 call assert_fails('set guifontset=*', 'E597:')
443
Bram Moolenaarce90e362019-09-08 18:58:44 +0200444 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100445
Bram Moolenaarce90e362019-09-08 18:58:44 +0200446 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
447 " be chosen meticulously.
448 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100449
Bram Moolenaarce90e362019-09-08 18:58:44 +0200450 let font_aw70 = font_head . '-130-75-75-c-70'
451 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100452
Bram Moolenaarce90e362019-09-08 18:58:44 +0200453 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
454 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100455
Bram Moolenaarce90e362019-09-08 18:58:44 +0200456 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
457 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
458 let singleton = font_head . '-*'
459 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100460
Bram Moolenaarce90e362019-09-08 18:58:44 +0200461 " Second, among 'locales', look up such a locale that gets 'set
462 " guifontset=' to work successfully with every fontset specified with
463 " 'fontsets'.
464 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
465 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100466
Bram Moolenaarce90e362019-09-08 18:58:44 +0200467 let feasible = 0
468 for locale in locales
469 try
470 exec 'language ctype' locale
471 catch /^Vim\%((\a\+)\)\=:E197/
472 continue
473 endtry
474 let done = 0
475 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100476 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200477 exec 'set guifontset=' . fontset
478 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
479 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100480 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200481 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100482 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200483 if done == len(fontsets)
484 let feasible = 1
485 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100486 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200487 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100488
Bram Moolenaarce90e362019-09-08 18:58:44 +0200489 " Third, give a set of tests if it is found feasible.
490 if !feasible
491 let skipped = g:not_hosted
492 else
493 " N.B. 'v:ctype' has already been set to an appropriate value in the
494 " previous loop.
495 for fontset in fontsets
496 exec 'set guifontset=' . fontset
497 call assert_equal(fontset, &guifontset)
498 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100499 endif
500
Bram Moolenaarce90e362019-09-08 18:58:44 +0200501 " Finally, restore ctype.
502 exec 'language ctype' ctype_saved
503
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100504 if !empty(skipped)
505 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100506 endif
507endfunc
508
509func Test_set_guifontwide()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100510 CheckX11BasedGui
Bram Moolenaar10434672017-02-12 19:59:08 +0100511
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100512 call assert_fails('set guifontwide=*', 'E533:')
513
514 if has('gui_gtk')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100515 let guifont_saved = &guifont
516 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100517
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100518 let fc_match = exepath('fc-match')
519 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100520 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100521 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100522 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
523 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
524 exec 'set guifontwide=' . fnameescape(wide)
525 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100526 endif
527
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100528 let &guifontwide = guifontwide_saved
529 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100530
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100531 elseif has('gui_motif')
Bram Moolenaar10434672017-02-12 19:59:08 +0100532 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100533 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100534 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100535 else
536 let encoding_saved = &encoding
537 let guifont_saved = &guifont
538 let guifontset_saved = &guifontset
539 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100540
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100541 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
542 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100543
544 set encoding=utf-8
545
546 " Case 1: guifontset is empty
547 set guifontset=
548
549 " Case 1-1: Automatic selection
550 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100551 exec 'set guifont=' . nfont
552 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100553
554 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100555 exec 'set guifontwide=' . wfont
556 exec 'set guifont=' . nfont
557 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100558
559 " Case 2: guifontset is invalid
560 try
561 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100562 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100563 catch
Bram Moolenaare2e40752020-09-04 21:18:46 +0200564 call assert_exception('E598:')
Bram Moolenaar10434672017-02-12 19:59:08 +0100565 endtry
Bram Moolenaar10434672017-02-12 19:59:08 +0100566
567 " Case 2-1: Automatic selection
568 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100569 exec 'set guifont=' . nfont
570 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100571
572 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100573 exec 'set guifontwide=' . wfont
574 exec 'set guifont=' . nfont
575 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100576
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100577 let &guifontwide = guifontwide_saved
578 let &guifontset = guifontset_saved
579 let &guifont = guifont_saved
580 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100581 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100582 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100583endfunc
584
Dusan Popovic4eeedc02021-10-16 20:52:05 +0100585func Test_set_guiligatures()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100586 CheckX11BasedGui
Dusan Popovic4eeedc02021-10-16 20:52:05 +0100587
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100588 if has('gui_gtk') || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
589 " Try correct value
590 set guiligatures=<>=ab
591 call assert_equal("<>=ab", &guiligatures)
592 " Try to throw error
593 try
594 set guiligatures=<>=šab
595 call assert_report("'set guiligatures=<>=šab should have failed")
596 catch
597 call assert_exception('E1243:')
598 endtry
Dusan Popovic4eeedc02021-10-16 20:52:05 +0100599 endif
600endfunc
601
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100602func Test_set_guiheadroom()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100603 CheckX11BasedGui
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100604
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100605 " Since this script is to be read together with '-U NONE', the default
606 " value must be preserved.
607 call assert_equal(50, &guiheadroom)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100608endfunc
609
Bram Moolenaar87748452017-03-12 17:10:33 +0100610func Test_set_guioptions()
611 let guioptions_saved = &guioptions
612 let duration = '200m'
613
614 if has('win32')
615 " Default Value
616 set guioptions&
617 call assert_equal('egmrLtT', &guioptions)
618
619 else
620 " Default Value
621 set guioptions&
622 call assert_equal('aegimrLtT', &guioptions)
623
624 " To activate scrollbars of type 'L' or 'R'.
625 wincmd v
626 redraw!
627
628 " Remove all default GUI ornaments
629 set guioptions-=T
630 exec 'sleep' . duration
631 call assert_equal('aegimrLt', &guioptions)
632 set guioptions-=t
633 exec 'sleep' . duration
634 call assert_equal('aegimrL', &guioptions)
635 set guioptions-=L
636 exec 'sleep' . duration
637 call assert_equal('aegimr', &guioptions)
638 set guioptions-=r
639 exec 'sleep' . duration
640 call assert_equal('aegim', &guioptions)
641 set guioptions-=m
642 exec 'sleep' . duration
643 call assert_equal('aegi', &guioptions)
644
645 " Try non-default GUI ornaments
646 set guioptions+=l
647 exec 'sleep' . duration
648 call assert_equal('aegil', &guioptions)
649 set guioptions-=l
650 exec 'sleep' . duration
651 call assert_equal('aegi', &guioptions)
652
653 set guioptions+=R
654 exec 'sleep' . duration
655 call assert_equal('aegiR', &guioptions)
656 set guioptions-=R
657 exec 'sleep' . duration
658 call assert_equal('aegi', &guioptions)
659
660 set guioptions+=b
661 exec 'sleep' . duration
662 call assert_equal('aegib', &guioptions)
663 set guioptions+=h
664 exec 'sleep' . duration
665 call assert_equal('aegibh', &guioptions)
666 set guioptions-=h
667 exec 'sleep' . duration
668 call assert_equal('aegib', &guioptions)
669 set guioptions-=b
670 exec 'sleep' . duration
671 call assert_equal('aegi', &guioptions)
672
673 set guioptions+=v
674 exec 'sleep' . duration
675 call assert_equal('aegiv', &guioptions)
676 set guioptions-=v
677 exec 'sleep' . duration
678 call assert_equal('aegi', &guioptions)
679
680 if has('gui_motif')
681 set guioptions+=F
682 exec 'sleep' . duration
683 call assert_equal('aegiF', &guioptions)
684 set guioptions-=F
685 exec 'sleep' . duration
686 call assert_equal('aegi', &guioptions)
687 endif
688
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200689 if has('gui_gtk3')
690 set guioptions+=d
691 exec 'sleep' . duration
692 call assert_equal('aegid', &guioptions)
693 set guioptions-=d
694 exec 'sleep' . duration
695 call assert_equal('aegi', &guioptions)
696 endif
697
Bram Moolenaar87748452017-03-12 17:10:33 +0100698 " Restore GUI ornaments to the default state.
699 set guioptions+=m
700 exec 'sleep' . duration
701 call assert_equal('aegim', &guioptions)
702 set guioptions+=r
703 exec 'sleep' . duration
704 call assert_equal('aegimr', &guioptions)
705 set guioptions+=L
706 exec 'sleep' . duration
707 call assert_equal('aegimrL', &guioptions)
708 set guioptions+=t
709 exec 'sleep' . duration
710 call assert_equal('aegimrLt', &guioptions)
711 set guioptions+=T
712 exec 'sleep' . duration
713 call assert_equal("aegimrLtT", &guioptions)
714
715 wincmd o
716 redraw!
717 endif
718
719 let &guioptions = guioptions_saved
720endfunc
721
Bram Moolenaarab186732018-09-14 21:27:06 +0200722func Test_scrollbars()
723 new
724 " buffer with 200 lines
725 call setline(1, repeat(['one', 'two'], 100))
726 set guioptions+=rlb
727
728 " scroll to move line 11 at top, moves the cursor there
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000729 let args = #{which: 'left', value: 10, dragging: 0}
730 call test_gui_event('scrollbar', args)
Bram Moolenaarab186732018-09-14 21:27:06 +0200731 redraw
732 call assert_equal(1, winline())
733 call assert_equal(11, line('.'))
734
735 " scroll to move line 1 at top, cursor stays in line 11
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000736 let args = #{which: 'right', value: 0, dragging: 0}
737 call test_gui_event('scrollbar', args)
Bram Moolenaarab186732018-09-14 21:27:06 +0200738 redraw
739 call assert_equal(11, winline())
740 call assert_equal(11, line('.'))
741
742 set nowrap
743 call setline(11, repeat('x', 150))
744 redraw
745 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200746 set number
747 redraw
748 call assert_equal(5, wincol())
749 set nonumber
750 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200751 call assert_equal(1, col('.'))
752
753 " scroll to character 11, cursor is moved
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000754 let args = #{which: 'hor', value: 10, dragging: 0}
755 call test_gui_event('scrollbar', args)
Bram Moolenaarab186732018-09-14 21:27:06 +0200756 redraw
757 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200758 set number
759 redraw
760 call assert_equal(5, wincol())
761 set nonumber
762 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200763 call assert_equal(11, col('.'))
764
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000765 " Invalid arguments
766 call assert_false(test_gui_event('scrollbar', {}))
767 call assert_false(test_gui_event('scrollbar', #{value: 10, dragging: 0}))
768 call assert_false(test_gui_event('scrollbar', #{which: 'hor', dragging: 0}))
769 call assert_false(test_gui_event('scrollbar', #{which: 'hor', value: 1}))
770 call assert_fails("call test_gui_event('scrollbar', #{which: 'a', value: 1, dragging: 0})", 'E475:')
771
Bram Moolenaarab186732018-09-14 21:27:06 +0200772 set guioptions&
773 set wrap&
774 bwipe!
775endfunc
776
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100777func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100778 CheckFeature quickfix
779
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100780 " Check Help menu exists
781 let help_menu = execute('menu Help')
782 call assert_match('Overview', help_menu)
783
784 " Check Help menu works
785 emenu Help.Overview
786 call assert_equal('help', &buftype)
787 close
788
789 " Check deleting menu doesn't cause trouble.
790 aunmenu Help
Bram Moolenaarb45cd362020-09-28 21:41:49 +0200791 if exists(':tlmenu')
792 tlunmenu Help
793 endif
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100794 call assert_fails('menu Help', 'E329:')
795endfunc
796
Bram Moolenaar87748452017-03-12 17:10:33 +0100797func Test_set_guipty()
798 let guipty_saved = &guipty
799
800 " Default Value
801 set guipty&
802 call assert_equal(1, &guipty)
803
804 set noguipty
805 call assert_equal(0, &guipty)
806
807 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100808endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100809
Bram Moolenaarc701f322019-03-28 21:49:21 +0100810func Test_encoding_conversion()
811 " GTK supports conversion between 'encoding' and "utf-8"
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200812 CheckFeature gui_gtk
813 let encoding_saved = &encoding
814 set encoding=latin1
Bram Moolenaarc701f322019-03-28 21:49:21 +0100815
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200816 " would be nice if we could take a screenshot
817 intro
818 " sets the window title
819 edit SomeFile
Bram Moolenaarc701f322019-03-28 21:49:21 +0100820
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200821 let &encoding = encoding_saved
Bram Moolenaarc701f322019-03-28 21:49:21 +0100822endfunc
823
Bram Moolenaar877e9572016-08-04 20:05:50 +0200824func Test_shell_command()
825 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200826 r !echo hello
827 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200828 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200829endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100830
Bram Moolenaar87748452017-03-12 17:10:33 +0100831func Test_syntax_colortest()
832 runtime syntax/colortest.vim
833 redraw!
834 sleep 200m
835 bwipe!
836endfunc
837
838func Test_set_term()
839 " It's enough to check the current value since setting 'term' to anything
840 " other than builtin_gui makes no sense at all.
841 call assert_equal('builtin_gui', &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200842 call assert_fails('set term=xterm', 'E530:')
Bram Moolenaar87748452017-03-12 17:10:33 +0100843endfunc
844
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100845func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100846 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100847 call assert_true(v:windowid > 0)
848 else
849 call assert_equal(0, v:windowid)
850 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100851endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200852
853" Test "vim -g" and also the GUIEnter autocommand.
854func Test_gui_dash_g()
855 let cmd = GetVimCommand('Xscriptgui')
856 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200857 let lines =<< trim END
858 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
859 au GUIEnter * qall
860 END
861 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200862 call system(cmd . ' -g')
863 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
864
865 call delete('Xscriptgui')
866 call delete('Xtestgui')
867endfunc
868
869" Test "vim -7" and also the GUIEnter autocommand.
870func Test_gui_dash_y()
871 let cmd = GetVimCommand('Xscriptgui')
872 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200873 let lines =<< trim END
874 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
875 au GUIEnter * qall
876 END
877 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200878 call system(cmd . ' -y')
879 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
880
881 call delete('Xscriptgui')
882 call delete('Xtestgui')
883endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100884
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200885" Test for "!" option in 'guioptions'. Use a terminal for running external
886" commands
887func Test_gui_run_cmd_in_terminal()
Bram Moolenaar4457e1d2020-05-15 22:46:44 +0200888 CheckFeature terminal
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200889 let save_guioptions = &guioptions
890 set guioptions+=!
891 if has('win32')
892 let cmd = 'type'
893 else
894 " assume all the other systems have a cat command
895 let cmd = 'cat'
896 endif
Bram Moolenaar98f16712020-05-22 13:34:01 +0200897 exe "silent !" . cmd . " test_gui.vim"
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200898 " TODO: how to check that the command ran in a separate terminal?
899 " Maybe check for $TERM (dumb vs xterm) in the spawned shell?
900 let &guioptions = save_guioptions
901endfunc
902
Bram Moolenaar46cd43b2020-06-04 22:22:11 +0200903func Test_gui_recursive_mapping()
904 nmap ' <C-W>
905 nmap <C-W>a :let didit = 1<CR>
906 call feedkeys("'a", 'xt')
907 call assert_equal(1, didit)
908
909 nunmap '
910 nunmap <C-W>a
911endfunc
912
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200913" Test GUI mouse events
914func Test_gui_mouse_event()
915 set mousemodel=extend
916 call test_override('no_query_mouse', 1)
917 new
918 call setline(1, ['one two three', 'four five six'])
919
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200920 " place the cursor using left click in normal mode
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200921 call cursor(1, 1)
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000922 let args = #{button: 0, row: 2, col: 4, multiclick: 0, modifiers: 0}
923 call test_gui_event('mouse', args)
924 let args.button = 3
925 eval 'mouse'->test_gui_event(args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200926 call feedkeys("\<Esc>", 'Lx!')
927 call assert_equal([0, 2, 4, 0], getpos('.'))
928
929 " select and yank a word
930 let @" = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000931 let args = #{button: 0, row: 1, col: 9, multiclick: 0, modifiers: 0}
932 call test_gui_event('mouse', args)
933 let args.multiclick = 1
934 call test_gui_event('mouse', args)
935 let args.button = 3
936 let args.multiclick = 0
937 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200938 call feedkeys("y", 'Lx!')
939 call assert_equal('three', @")
940
941 " create visual selection using right click
942 let @" = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000943 let args = #{button: 0, row: 2, col: 6, multiclick: 0, modifiers: 0}
944 call test_gui_event('mouse', args)
945 let args.button = 3
946 call test_gui_event('mouse', args)
947 let args = #{button: 2, row: 2, col: 13, multiclick: 0, modifiers: 0}
948 call test_gui_event('mouse', args)
949 let args.button = 3
950 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200951 call feedkeys("y", 'Lx!')
952 call assert_equal('five six', @")
953
954 " paste using middle mouse button
955 let @* = 'abc '
956 call feedkeys('""', 'Lx!')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000957 let args = #{button: 1, row: 1, col: 9, multiclick: 0, modifiers: 0}
958 call test_gui_event('mouse', args)
959 let args.button = 3
960 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200961 call feedkeys("\<Esc>", 'Lx!')
962 call assert_equal(['one two abc three', 'four five six'], getline(1, '$'))
963
964 " extend visual selection using right click in visual mode
965 let @" = ''
966 call cursor(1, 1)
967 call feedkeys('v', 'Lx!')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000968 let args = #{button: 2, row: 1, col: 17, multiclick: 0, modifiers: 0}
969 call test_gui_event('mouse', args)
970 let args.button = 3
971 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200972 call feedkeys("y", 'Lx!')
973 call assert_equal('one two abc three', @")
974
975 " extend visual selection using mouse drag
976 let @" = ''
977 call cursor(1, 1)
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000978 let args = #{button: 0, row: 2, col: 1, multiclick: 0, modifiers: 0}
979 call test_gui_event('mouse', args)
980 let args = #{button: 0x43, row: 2, col: 9, multiclick: 0, modifiers: 0}
981 call test_gui_event('mouse', args)
982 let args.button = 0x3
983 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200984 call feedkeys("y", 'Lx!')
985 call assert_equal('four five', @")
986
987 " select text by moving the mouse
988 let @" = ''
989 call cursor(1, 1)
990 redraw!
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000991 let args = #{button: 0, row: 1, col: 4, multiclick: 0, modifiers: 0}
992 call test_gui_event('mouse', args)
993 let args.button = 0x700
994 let args.col = 9
995 call test_gui_event('mouse', args)
996 let args.col = 13
997 call test_gui_event('mouse', args)
998 let args.button = 3
999 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001000 call feedkeys("y", 'Lx!')
1001 call assert_equal(' two abc t', @")
1002
1003 " Using mouse in insert mode
1004 call cursor(1, 1)
1005 call feedkeys('i', 't')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001006 let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0}
1007 call test_gui_event('mouse', args)
1008 let args.button = 3
1009 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001010 call feedkeys("po\<Esc>", 'Lx!')
1011 call assert_equal(['one two abc three', 'four five posix'], getline(1, '$'))
1012
1013 %d _
LemonBoyc27747e2022-05-07 12:25:40 +01001014 set scrolloff=0
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001015 call setline(1, range(1, 100))
1016 " scroll up
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001017 let args = #{button: 0x200, row: 2, col: 1, multiclick: 0, modifiers: 0}
1018 call test_gui_event('mouse', args)
1019 call test_gui_event('mouse', args)
1020 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001021 call feedkeys("H", 'Lx!')
1022 call assert_equal(10, line('.'))
1023
1024 " scroll down
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001025 let args = #{button: 0x100, row: 2, col: 1, multiclick: 0, modifiers: 0}
1026 call test_gui_event('mouse', args)
1027 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001028 call feedkeys("H", 'Lx!')
1029 call assert_equal(4, line('.'))
LemonBoyc27747e2022-05-07 12:25:40 +01001030 set scrolloff&
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001031
1032 %d _
1033 set nowrap
1034 call setline(1, range(10)->join('')->repeat(10))
1035 " scroll left
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001036 let args = #{button: 0x500, row: 1, col: 5, multiclick: 0, modifiers: 0}
1037 call test_gui_event('mouse', args)
1038 let args.col = 10
1039 call test_gui_event('mouse', args)
1040 let args.col = 15
1041 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001042 call feedkeys('g0', 'Lx!')
1043 call assert_equal(19, col('.'))
1044
1045 " scroll right
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001046 let args = #{button: 0x600, row: 1, col: 15, multiclick: 0, modifiers: 0}
1047 call test_gui_event('mouse', args)
1048 let args.col = 10
1049 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001050 call feedkeys('g0', 'Lx!')
1051 call assert_equal(7, col('.'))
1052 set wrap&
1053
1054 %d _
1055 call setline(1, repeat([repeat('a', 60)], 10))
1056
1057 " record various mouse events
1058 let mouseEventNames = [
1059 \ 'LeftMouse', 'LeftRelease', '2-LeftMouse', '3-LeftMouse',
1060 \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse',
1061 \ 'MiddleRelease', '2-MiddleMouse', '3-MiddleMouse',
1062 \ 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
1063 \ 'RightMouse', 'RightRelease', '2-RightMouse',
1064 \ '3-RightMouse', 'S-RightMouse', 'A-RightMouse', 'C-RightMouse',
1065 \ 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', 'C-X1Mouse', 'X2Mouse',
1066 \ 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'
1067 \ ]
1068 let mouseEventCodes = map(copy(mouseEventNames), "'<' .. v:val .. '>'")
1069 let g:events = []
1070 for e in mouseEventCodes
1071 exe 'nnoremap ' .. e .. ' <Cmd>call add(g:events, "' ..
1072 \ substitute(e, '[<>]', '', 'g') .. '")<CR>'
1073 endfor
1074
1075 " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1,
1076 " 0x300- X2)
1077 for button in [0, 1, 2, 0x300, 0x400]
1078 " Single click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001079 let args = #{button: button, row: 2, col: 5, multiclick: 0, modifiers: 0}
1080 call test_gui_event('mouse', args)
1081 let args.button = 3
1082 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001083
1084 " Double/Triple click is supported by only the Left/Middle/Right mouse
1085 " buttons
1086 if button <= 2
1087 " Double Click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001088 let args.button = button
1089 call test_gui_event('mouse', args)
1090 let args.multiclick = 1
1091 call test_gui_event('mouse', args)
1092 let args.button = 3
1093 let args.multiclick = 0
1094 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001095
1096 " Triple Click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001097 let args.button = button
1098 call test_gui_event('mouse', args)
1099 let args.multiclick = 1
1100 call test_gui_event('mouse', args)
1101 call test_gui_event('mouse', args)
1102 let args.button = 3
1103 let args.multiclick = 0
1104 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001105 endif
1106
1107 " Shift click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001108 let args = #{button: button, row: 3, col: 7, multiclick: 0, modifiers: 4}
1109 call test_gui_event('mouse', args)
1110 let args.button = 3
1111 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001112
1113 " Alt click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001114 let args.button = button
1115 let args.modifiers = 8
1116 call test_gui_event('mouse', args)
1117 let args.button = 3
1118 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001119
1120 " Ctrl click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001121 let args.button = button
1122 let args.modifiers = 16
1123 call test_gui_event('mouse', args)
1124 let args.button = 3
1125 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001126
1127 call feedkeys("\<Esc>", 'Lx!')
1128 endfor
1129
1130 call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse',
1131 \ 'LeftMouse', '2-LeftMouse', '3-LeftMouse', 'S-LeftMouse',
1132 \ 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', 'MiddleRelease',
1133 \ 'MiddleMouse', '2-MiddleMouse', 'MiddleMouse', '2-MiddleMouse',
1134 \ '3-MiddleMouse', 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
1135 \ 'RightMouse', 'RightRelease', 'RightMouse', '2-RightMouse',
1136 \ 'RightMouse', '2-RightMouse', '3-RightMouse', 'S-RightMouse',
1137 \ 'A-RightMouse', 'C-RightMouse', 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse',
1138 \ 'C-X1Mouse', 'X2Mouse', 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'],
1139 \ g:events)
1140
1141 for e in mouseEventCodes
1142 exe 'nunmap ' .. e
1143 endfor
1144
1145 " modeless selection
1146 set mouse=
1147 let save_guioptions = &guioptions
1148 set guioptions+=A
1149 %d _
1150 call setline(1, ['one two three', 'four five sixteen'])
1151 call cursor(1, 1)
1152 redraw!
1153 " Double click should select the word and copy it to clipboard
1154 let @* = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001155 let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0}
1156 call test_gui_event('mouse', args)
1157 let args.multiclick = 1
1158 call test_gui_event('mouse', args)
1159 let args.button = 3
1160 let args.multiclick = 0
1161 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001162 call feedkeys("\<Esc>", 'Lx!')
1163 call assert_equal([0, 1, 1, 0], getpos('.'))
1164 call assert_equal('sixteen', @*)
1165 " Right click should extend the selection from cursor
1166 call cursor(1, 6)
1167 redraw!
1168 let @* = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001169 let args = #{button: 2, row: 1, col: 11, multiclick: 0, modifiers: 0}
1170 call test_gui_event('mouse', args)
1171 let args.button = 3
1172 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001173 call feedkeys("\<Esc>", 'Lx!')
1174 call assert_equal([0, 1, 6, 0], getpos('.'))
1175 call assert_equal('wo thr', @*)
1176 " Middle click should paste the clipboard contents
1177 call cursor(2, 1)
1178 redraw!
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001179 let args = #{button: 1, row: 1, col: 11, multiclick: 0, modifiers: 0}
1180 call test_gui_event('mouse', args)
1181 let args.button = 3
1182 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001183 call feedkeys("\<Esc>", 'Lx!')
1184 call assert_equal([0, 2, 7, 0], getpos('.'))
1185 call assert_equal('wo thrfour five sixteen', getline(2))
1186 set mouse&
1187 let &guioptions = save_guioptions
1188
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001189 " Test invalid parameters for test_gui_event()
1190 let args = #{row: 2, col: 4, multiclick: 0, modifiers: 0}
1191 call assert_false(test_gui_event('mouse', args))
1192 let args = #{button: 0, col: 4, multiclick: 0, modifiers: 0}
1193 call assert_false(test_gui_event('mouse', args))
1194 let args = #{button: 0, row: 2, multiclick: 0, modifiers: 0}
1195 call assert_false(test_gui_event('mouse', args))
1196 let args = #{button: 0, row: 2, col: 4, modifiers: 0}
1197 call assert_false(test_gui_event('mouse', args))
1198 let args = #{button: 0, row: 2, col: 4, multiclick: 0}
1199 call assert_false(test_gui_event('mouse', args))
1200
1201 " Error cases for test_gui_event()
1202 call assert_fails("call test_gui_event('a1b2c3', args)", 'E475:')
1203 call assert_fails("call test_gui_event([], args)", 'E1174:')
1204 call assert_fails("call test_gui_event('abc', [])", 'E1206:')
1205 call assert_fails("call test_gui_event(test_null_string(), {})", 'E475:')
1206 call assert_false(test_gui_event('mouse', test_null_dict()))
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001207
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001208 bw!
1209 call test_override('no_query_mouse', 0)
1210 set mousemodel&
1211endfunc
1212
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001213" Move the mouse to the top-left in preparation for mouse events
1214func PrepareForMouseEvent(args)
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001215 call extend(a:args, #{row: 1, col: 1})
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001216 call test_gui_event('mouse', a:args)
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001217 let g:eventlist = []
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001218 call feedkeys('', 'Lx!')
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001219
1220 " Wait a bit for the event. I may not come if the mouse didn't move, wait up
1221 " to 100 msec.
1222 for n in range(10)
1223 if len(g:eventlist) > 0
1224 break
1225 endif
1226 sleep 10m
1227 endfor
1228 let g:eventlist = []
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001229endfunc
1230
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001231func MouseWasMoved()
1232 let pos = getmousepos()
1233 call add(g:eventlist, #{row: pos.screenrow, col: pos.screencol})
1234endfunc
1235
Ernie Raelc4cb5442022-04-03 15:47:28 +01001236func Test_gui_mouse_move_event()
1237 let args = #{move: 1, button: 0, multiclick: 0, modifiers: 0}
1238
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001239 " by default, no mouse move events are generated
Ernie Raelc4cb5442022-04-03 15:47:28 +01001240 set mousemev&
1241 call assert_false(&mousemev)
1242
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001243 let g:eventlist = []
1244 nnoremap <special> <silent> <MouseMove> :call MouseWasMoved()<CR>
Ernie Raelc4cb5442022-04-03 15:47:28 +01001245
1246 " start at mouse pos (1,1), clear counter
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001247 call PrepareForMouseEvent(args)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001248
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001249 call extend(args, #{row: 3, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001250 call test_gui_event('mouse', args)
1251 call feedkeys('', 'Lx!')
1252
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001253 call extend(args, #{row: 10, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001254 call test_gui_event('mouse', args)
1255 call feedkeys('', 'Lx!')
1256
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001257 " no events since 'mousemev' is off
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001258 call assert_equal([], g:eventlist)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001259
1260 " turn on mouse events and try the same thing
1261 set mousemev
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001262 call PrepareForMouseEvent(args)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001263
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001264 call extend(args, #{row: 3, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001265 call test_gui_event('mouse', args)
1266 call feedkeys('', 'Lx!')
1267
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001268 call extend(args, #{row: 10, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001269 call test_gui_event('mouse', args)
1270 call feedkeys('', 'Lx!')
1271
Bram Moolenaar3c25a862022-05-16 17:07:41 +01001272 " FIXME: on MS-Windows we get a stray event first
1273 if has('win32') && len(g:eventlist) == 3
Bram Moolenaare5162e72022-05-16 16:41:35 +01001274 let g:eventlist = g:eventlist[1 : ]
1275 endif
1276
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001277 call assert_equal([#{row: 4, col: 31}, #{row: 11, col: 31}], g:eventlist)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001278
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001279 " wiggle the mouse around within a screen cell, shouldn't trigger events
1280 call extend(args, #{cell: v:false})
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001281 call PrepareForMouseEvent(args)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001282
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001283 call extend(args, #{row: 1, col: 2, cell: v:false})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001284 call test_gui_event('mouse', args)
1285 call feedkeys('', 'Lx!')
1286
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001287 call extend(args, #{row: 2, col: 2, cell: v:false})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001288 call test_gui_event('mouse', args)
1289 call feedkeys('', 'Lx!')
1290
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001291 call extend(args, #{row: 2, col: 1, cell: v:false})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001292 call test_gui_event('mouse', args)
1293 call feedkeys('', 'Lx!')
1294
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001295 call assert_equal([], g:eventlist)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001296
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001297 unlet g:eventlist
Ernie Raelc4cb5442022-04-03 15:47:28 +01001298 unmap <MouseMove>
1299 set mousemev&
1300endfunc
1301
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001302" Test for 'guitablabel' and 'guitabtooltip' options
1303func TestGuiTabLabel()
1304 call add(g:TabLabels, v:lnum + 100)
1305 let bufnrlist = tabpagebuflist(v:lnum)
1306 return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
1307endfunc
1308
1309func TestGuiTabToolTip()
1310 call add(g:TabToolTips, v:lnum + 200)
1311 let bufnrlist = tabpagebuflist(v:lnum)
1312 return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
1313endfunc
1314
1315func Test_gui_tablabel_tooltip()
1316 %bw!
1317 " Removing the tabline at the end of this test, reduces the window height by
1318 " one. Save and restore it after the test.
1319 let save_lines = &lines
1320 edit one
1321 set modified
1322 tabnew two
1323 set modified
1324 tabnew three
1325 set modified
1326 let g:TabLabels = []
1327 set guitablabel=%{TestGuiTabLabel()}
1328 call test_override('starting', 1)
1329 redrawtabline
1330 call test_override('starting', 0)
1331 call assert_true(index(g:TabLabels, 101) != -1)
1332 call assert_true(index(g:TabLabels, 102) != -1)
1333 call assert_true(index(g:TabLabels, 103) != -1)
1334 set guitablabel&
1335 unlet g:TabLabels
1336
1337 if has('gui_gtk')
1338 " Only on GTK+, the tooltip function is called even if the mouse is not
1339 " on the tabline. on Win32 and Motif, the tooltip function is called only
1340 " when the mouse pointer is over the tabline.
1341 let g:TabToolTips = []
1342 set guitabtooltip=%{TestGuiTabToolTip()}
1343 call test_override('starting', 1)
1344 redrawtabline
1345 call test_override('starting', 0)
1346 call assert_true(index(g:TabToolTips, 201) != -1)
1347 call assert_true(index(g:TabToolTips, 202) != -1)
1348 call assert_true(index(g:TabToolTips, 203) != -1)
1349 set guitabtooltip&
1350 unlet g:TabToolTips
1351 endif
1352 %bw!
1353 let &lines = save_lines
1354endfunc
1355
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001356" Test for dropping files into a window in GUI
1357func DropFilesInCmdLine()
1358 call feedkeys(":\"", 'L')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001359 let d = #{files: ['a.c', 'b.c'], row: &lines, col: 1, modifiers: 0}
1360 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001361 call feedkeys("\<CR>", 'L')
1362endfunc
1363
1364func Test_gui_drop_files()
Bram Moolenaar1d1ce612021-06-27 19:02:52 +02001365 CheckFeature drop_file
1366
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001367 %bw!
1368 %argdelete
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001369 let d = #{files: [], row: 1, col: 1, modifiers: 0}
1370 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001371 call assert_equal([], argv())
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001372 let d = #{files: [1, 2], row: 1, col: 1, modifiers: 0}
1373 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001374 call assert_equal([], argv())
1375
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001376 let d = #{files: ['a.c', 'b.c'], row: 1, col: 1, modifiers: 0}
1377 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001378 call assert_equal(['a.c', 'b.c'], argv())
1379 %bw!
1380 %argdelete
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001381 let d = #{files: [], row: 1, col: 1, modifiers: 0}
1382 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001383 call assert_equal([], argv())
1384 %bw!
1385 " if the buffer in the window is modified, then the file should be opened in
1386 " a new window
1387 set modified
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001388 let d = #{files: ['x.c', 'y.c'], row: 1, col: 1, modifiers: 0}
1389 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001390 call assert_equal(['x.c', 'y.c'], argv())
1391 call assert_equal(2, winnr('$'))
1392 call assert_equal('x.c', bufname(winbufnr(1)))
1393 %bw!
1394 %argdelete
1395 " if Ctrl is pressed, then the file should be opened in a new window
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001396 let d = #{files: ['s.py', 't.py'], row: 1, col: 1, modifiers: 0x10}
1397 eval 'dropfiles'->test_gui_event(d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001398 call assert_equal(['s.py', 't.py'], argv())
1399 call assert_equal(2, winnr('$'))
1400 call assert_equal('s.py', bufname(winbufnr(1)))
1401 %bw!
1402 %argdelete
1403 " drop the files in a non-current window
1404 belowright new
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001405 let d = #{files: ['a.py', 'b.py'], row: 1, col: 1, modifiers: 0}
1406 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001407 call assert_equal(['a.py', 'b.py'], argv())
1408 call assert_equal(2, winnr('$'))
1409 call assert_equal(1, winnr())
1410 call assert_equal('a.py', bufname(winbufnr(1)))
1411 %bw!
1412 %argdelete
1413 " pressing shift when dropping files should change directory
1414 let save_cwd = getcwd()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001415 call mkdir('Xdropdir1')
1416 call writefile([], 'Xdropdir1/Xfile1')
1417 call writefile([], 'Xdropdir1/Xfile2')
1418 let d = #{files: ['Xdropdir1/Xfile1', 'Xdropdir1/Xfile2'], row: 1, col: 1,
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001419 \ modifiers: 0x4}
1420 call test_gui_event('dropfiles', d)
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001421 call assert_equal('Xdropdir1', fnamemodify(getcwd(), ':t'))
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001422 call assert_equal('Xfile1', @%)
1423 call chdir(save_cwd)
1424 " pressing shift when dropping directory and files should change directory
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001425 let d = #{files: ['Xdropdir1', 'Xdropdir1/Xfile2'], row: 1, col: 1, modifiers: 0x4}
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001426 call test_gui_event('dropfiles', d)
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001427 call assert_equal('Xdropdir1', fnamemodify(getcwd(), ':t'))
1428 call assert_equal('Xdropdir1', fnamemodify(@%, ':t'))
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001429 call chdir(save_cwd)
1430 %bw!
1431 %argdelete
1432 " dropping a directory should edit it
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001433 let d = #{files: ['Xdropdir1'], row: 1, col: 1, modifiers: 0}
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001434 call test_gui_event('dropfiles', d)
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001435 call assert_equal('Xdropdir1', @%)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001436 %bw!
1437 %argdelete
1438 " dropping only a directory name with Shift should ignore it
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001439 let d = #{files: ['Xdropdir1'], row: 1, col: 1, modifiers: 0x4}
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001440 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001441 call assert_equal('', @%)
1442 %bw!
1443 %argdelete
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001444 call delete('Xdropdir1', 'rf')
Bram Moolenaar00d4cee2022-08-28 13:38:43 +01001445
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001446 " drop files in the command line. The GUI drop files adds the file names to
1447 " the low level input buffer. So need to use a cmdline map and feedkeys()
1448 " with 'Lx!' to process it in this function itself.
Bram Moolenaar00d4cee2022-08-28 13:38:43 +01001449 " This sometimes fails, e.g. when using valgrind.
1450 let g:test_is_flaky = 1
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001451 cnoremap <expr> <buffer> <F4> DropFilesInCmdLine()
1452 call feedkeys(":\"\<F4>\<CR>", 'xt')
1453 call feedkeys('k', 'Lx!')
1454 call assert_equal('"a.c b.c', @:)
1455 cunmap <buffer> <F4>
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001456
1457 " Invalid arguments
1458 call assert_false(test_gui_event("dropfiles", {}))
1459 let d = #{row: 1, col: 1, modifiers: 0}
1460 call assert_false(test_gui_event("dropfiles", d))
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +00001461 let d = #{files: 1, row: 1, col: 1, modifiers: 0}
1462 call assert_false(test_gui_event("dropfiles", d))
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001463 let d = #{files: test_null_list(), row: 1, col: 1, modifiers: 0}
1464 call assert_false(test_gui_event("dropfiles", d))
1465 let d = #{files: [test_null_string()], row: 1, col: 1, modifiers: 0}
1466 call assert_true(test_gui_event("dropfiles", d))
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001467endfunc
1468
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001469" Test for generating a GUI tabline event to select a tab page
1470func Test_gui_tabline_event()
1471 %bw!
1472 edit Xfile1
1473 tabedit Xfile2
1474 tabedit Xfile3
1475
1476 tabfirst
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001477 call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 2}))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001478 call feedkeys("y", "Lx!")
1479 call assert_equal(2, tabpagenr())
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001480 call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 3}))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001481 call feedkeys("y", "Lx!")
1482 call assert_equal(3, tabpagenr())
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001483 call assert_equal(v:false, 'tabline'->test_gui_event(#{tabnr: 3}))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001484
1485 " From the cmdline window, tabline event should not be handled
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001486 call feedkeys("q::let t = test_gui_event('tabline', #{tabnr: 2})\<CR>:q\<CR>", 'x!')
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001487 call assert_equal(v:false, t)
1488
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001489 " Invalid arguments
1490 call assert_false(test_gui_event('tabline', {}))
1491 call assert_false(test_gui_event('tabline', #{abc: 1}))
1492
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001493 %bw!
1494endfunc
1495
1496" Test for generating a GUI tabline menu event to execute an action
1497func Test_gui_tabmenu_event()
1498 %bw!
1499
1500 " Try to close the last tab page
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001501 call test_gui_event('tabmenu', #{tabnr: 1, item: 1})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001502 call feedkeys("y", "Lx!")
1503
1504 edit Xfile1
1505 tabedit Xfile2
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001506 call test_gui_event('tabmenu', #{tabnr: 1, item: 1})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001507 call feedkeys("y", "Lx!")
1508 call assert_equal(1, tabpagenr('$'))
1509 call assert_equal('Xfile2', bufname())
1510
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001511 eval 'tabmenu'->test_gui_event(#{tabnr: 1, item: 2})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001512 call feedkeys("y", "Lx!")
1513 call assert_equal(2, tabpagenr('$'))
1514
1515 " If tabnr is 0, then the current tabpage should be used.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001516 call test_gui_event('tabmenu', #{tabnr: 0, item: 2})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001517 call feedkeys("y", "Lx!")
1518 call assert_equal(3, tabpagenr('$'))
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001519 call test_gui_event('tabmenu', #{tabnr: 0, item: 1})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001520 call feedkeys("y", "Lx!")
1521 call assert_equal(2, tabpagenr('$'))
1522
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001523 " Invalid arguments
1524 call assert_false(test_gui_event('tabmenu', {}))
1525 call assert_false(test_gui_event('tabmenu', #{tabnr: 1}))
1526 call assert_false(test_gui_event('tabmenu', #{item: 1}))
1527 call assert_false(test_gui_event('tabmenu', #{abc: 1}))
1528
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001529 %bw!
1530endfunc
1531
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001532" Test for find/replace text dialog event
1533func Test_gui_findrepl()
Yegappan Lakshmanan08238042022-03-07 16:57:22 +00001534 " Find/Replace dialog is supported only on GTK, Motif and MS-Windows.
1535 if !has('gui_gtk') && !has('gui_motif') && !has('gui_win32')
1536 return
1537 endif
1538
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001539 new
1540 call setline(1, ['one two one', 'Twoo One two oneo'])
1541
1542 " Replace all instances of a string with another
1543 let args = #{find_text: 'one', repl_text: 'ONE', flags: 0x4, forward: 1}
1544 call test_gui_event('findrepl', args)
1545 call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
1546
1547 " Replace all instances of a whole string with another
1548 call cursor(1, 1)
1549 let args = #{find_text: 'two', repl_text: 'TWO', flags: 0xC, forward: 1}
1550 call test_gui_event('findrepl', args)
1551 call assert_equal(['ONE TWO ONE', 'Twoo ONE TWO ONEo'], getline(1, '$'))
1552
Dominique Pelle81b573d2022-03-22 21:14:55 +00001553 " Find next occurrence of a string (in a find dialog)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001554 call cursor(1, 11)
1555 let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 1}
1556 call test_gui_event('findrepl', args)
1557 call assert_equal([2, 10], [line('.'), col('.')])
1558
Dominique Pelle81b573d2022-03-22 21:14:55 +00001559 " Find previous occurrences of a string (in a find dialog)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001560 call cursor(1, 11)
1561 let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 0}
1562 call test_gui_event('findrepl', args)
1563 call assert_equal([1, 5], [line('.'), col('.')])
1564
Dominique Pelle81b573d2022-03-22 21:14:55 +00001565 " Find next occurrence of a string (in a replace dialog)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001566 call cursor(1, 1)
1567 let args = #{find_text: 'Twoo', repl_text: '', flags: 0x2, forward: 1}
1568 call test_gui_event('findrepl', args)
1569 call assert_equal([2, 1], [line('.'), col('.')])
1570
Dominique Pelle81b573d2022-03-22 21:14:55 +00001571 " Replace only the next occurrence of a string (once)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001572 call cursor(1, 5)
1573 let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x3, forward: 1}
1574 call test_gui_event('findrepl', args)
1575 call assert_equal(['ONE two ONE', 'Twoo ONE TWO ONEo'], getline(1, '$'))
1576
1577 " Replace all instances of a whole string with another matching case
1578 call cursor(1, 1)
1579 let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x1C, forward: 1}
1580 call test_gui_event('findrepl', args)
1581 call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +00001582
matveyt2834ebd2022-09-06 17:00:15 +01001583 " Replace all instances with sub-replace specials
1584 call cursor(1, 1)
1585 let args = #{find_text: 'ONE', repl_text: '&~&', flags: 0x4, forward: 1}
1586 call test_gui_event('findrepl', args)
1587 call assert_equal(['&~& two &~&', 'Twoo &~& two &~&o'], getline(1, '$'))
1588
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +00001589 " Invalid arguments
1590 call assert_false(test_gui_event('findrepl', {}))
1591 let args = #{repl_text: 'a', flags: 1, forward: 1}
1592 call assert_false(test_gui_event('findrepl', args))
1593 let args = #{find_text: 'a', flags: 1, forward: 1}
1594 call assert_false(test_gui_event('findrepl', args))
1595 let args = #{find_text: 'a', repl_text: 'b', forward: 1}
1596 call assert_false(test_gui_event('findrepl', args))
1597 let args = #{find_text: 'a', repl_text: 'b', flags: 1}
1598 call assert_false(test_gui_event('findrepl', args))
1599
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001600 bw!
1601endfunc
1602
zeertzjqbad8a012022-04-29 16:44:00 +01001603func Test_gui_CTRL_SHIFT_V()
1604 call feedkeys(":let g:str = '\<*C-S-V>\<*C-S-I>\<*C-S-V>\<*C-S-@>'\<CR>", 'tx')
zeertzjq758a8d12022-04-29 11:06:34 +01001605 call assert_equal('<C-S-I><C-S-@>', g:str)
1606 unlet g:str
1607endfunc
1608
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001609func Test_gui_dialog_file()
K.Takatae68f1342022-09-07 13:01:11 +01001610 " make sure the file does not exist, otherwise a dialog makes Vim hang
1611 call delete('Xdialfile')
1612
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001613 let lines =<< trim END
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001614 file Xdialfile
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001615 normal axxx
1616 confirm qa
1617 END
K.Takatae68f1342022-09-07 13:01:11 +01001618 call writefile(lines, 'Xlines', 'D')
Bram Moolenaara2726242022-06-16 16:36:43 +01001619 let prefix = '!'
1620 if has('win32')
1621 let prefix = '!start '
1622 endif
1623 execute prefix .. GetVimCommand() .. ' -g -f --clean --gui-dialog-file Xdialog -S Xlines'
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001624
1625 call WaitForAssert({-> assert_true(filereadable('Xdialog'))})
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001626 call assert_match('Question: Save changes to "Xdialfile"?', readfile('Xdialog')->join('<NL>'))
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001627
1628 call delete('Xdialog')
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001629 call delete('Xdialfile')
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001630endfunc
1631
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001632" Test for sending low level key presses
1633func SendKeys(keylist)
1634 for k in a:keylist
1635 call test_gui_event("sendevent", #{event: "keydown", keycode: k})
1636 endfor
1637 for k in reverse(a:keylist)
1638 call test_gui_event("sendevent", #{event: "keyup", keycode: k})
1639 endfor
1640endfunc
1641
1642func Test_gui_lowlevel_keyevent()
1643 CheckMSWindows
1644 new
1645
1646 " Test for <Ctrl-A> to <Ctrl-Z> keys
1647 for kc in range(65, 90)
1648 call SendKeys([0x11, kc])
1649 let ch = getcharstr()
1650 call assert_equal(nr2char(kc - 64), ch)
1651 endfor
1652
1653 " Test for the various Ctrl and Shift key combinations.
Yegappan Lakshmanan0adae2d2022-09-09 17:39:02 +01001654 " Refer to the following page for the virtual key codes:
1655 " https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001656 let keytests = [
Yegappan Lakshmanan0adae2d2022-09-09 17:39:02 +01001657 \ [[0x10, 0x21], "S-Pageup", 2],
1658 \ [[0xA0, 0x21], "S-Pageup", 2],
1659 \ [[0xA1, 0x21], "S-Pageup", 2],
1660 \ [[0x11, 0x21], "C-Pageup", 4],
1661 \ [[0xA2, 0x21], "C-Pageup", 4],
1662 \ [[0xA3, 0x21], "C-Pageup", 4],
1663 \ [[0x11, 0x10, 0x21], "C-S-Pageup", 6],
1664 \ [[0x10, 0x22], "S-PageDown", 2],
1665 \ [[0xA0, 0x22], "S-PageDown", 2],
1666 \ [[0xA1, 0x22], "S-PageDown", 2],
1667 \ [[0x11, 0x22], "C-PageDown", 4],
1668 \ [[0xA2, 0x22], "C-PageDown", 4],
1669 \ [[0xA3, 0x22], "C-PageDown", 4],
1670 \ [[0x11, 0x10, 0x22], "C-S-PageDown", 6],
1671 \ [[0x10, 0x23], "S-End", 0],
1672 \ [[0x11, 0x23], "C-End", 0],
1673 \ [[0x11, 0x10, 0x23], "C-S-End", 4],
1674 \ [[0x10, 0x24], "S-Home", 0],
1675 \ [[0x11, 0x24], "C-Home", 0],
1676 \ [[0x11, 0x10, 0x24], "C-S-Home", 4],
1677 \ [[0x10, 0x25], "S-Left", 0],
1678 \ [[0x11, 0x25], "C-Left", 0],
1679 \ [[0x11, 0x10, 0x25], "C-S-Left", 4],
1680 \ [[0x10, 0x26], "S-Up", 0],
1681 \ [[0x11, 0x26], "C-Up", 4],
1682 \ [[0x11, 0x10, 0x26], "C-S-Up", 4],
1683 \ [[0x10, 0x27], "S-Right", 0],
1684 \ [[0x11, 0x27], "C-Right", 0],
1685 \ [[0x11, 0x10, 0x27], "C-S-Right", 4],
1686 \ [[0x10, 0x28], "S-Down", 0],
1687 \ [[0x11, 0x28], "C-Down", 4],
1688 \ [[0x11, 0x10, 0x28], "C-S-Down", 4],
1689 \ [[0x11, 0x30], "C-0", 4],
1690 \ [[0x11, 0x31], "C-1", 4],
1691 \ [[0x11, 0x32], "C-2", 4],
1692 \ [[0x11, 0x33], "C-3", 4],
1693 \ [[0x11, 0x34], "C-4", 4],
1694 \ [[0x11, 0x35], "C-5", 4],
1695 \ [[0x11, 0x36], "C-^", 0],
1696 \ [[0x11, 0x37], "C-7", 4],
1697 \ [[0x11, 0x38], "C-8", 4],
1698 \ [[0x11, 0x39], "C-9", 4],
1699 \ [[0x11, 0x60], "C-0", 4],
1700 \ [[0x11, 0x61], "C-1", 4],
1701 \ [[0x11, 0x62], "C-2", 4],
1702 \ [[0x11, 0x63], "C-3", 4],
1703 \ [[0x11, 0x64], "C-4", 4],
1704 \ [[0x11, 0x65], "C-5", 4],
1705 \ [[0x11, 0x66], "C-6", 4],
1706 \ [[0x11, 0x67], "C-7", 4],
1707 \ [[0x11, 0x68], "C-8", 4],
1708 \ [[0x11, 0x69], "C-9", 4],
1709 \ [[0x11, 0x6A], "C-*", 4],
1710 \ [[0x11, 0x6B], "C-+", 4],
1711 \ [[0x11, 0x6D], "C--", 4],
1712 \ [[0x11, 0x70], "C-F1", 4],
1713 \ [[0x11, 0x10, 0x70], "C-S-F1", 4],
1714 \ [[0x11, 0x71], "C-F2", 4],
1715 \ [[0x11, 0x10, 0x71], "C-S-F2", 4],
1716 \ [[0x11, 0x72], "C-F3", 4],
1717 \ [[0x11, 0x10, 0x72], "C-S-F3", 4],
1718 \ [[0x11, 0x73], "C-F4", 4],
1719 \ [[0x11, 0x10, 0x73], "C-S-F4", 4],
1720 \ [[0x11, 0x74], "C-F5", 4],
1721 \ [[0x11, 0x10, 0x74], "C-S-F5", 4],
1722 \ [[0x11, 0x75], "C-F6", 4],
1723 \ [[0x11, 0x10, 0x75], "C-S-F6", 4],
1724 \ [[0x11, 0x76], "C-F7", 4],
1725 \ [[0x11, 0x10, 0x76], "C-S-F7", 4],
1726 \ [[0x11, 0x77], "C-F8", 4],
1727 \ [[0x11, 0x10, 0x77], "C-S-F8", 4],
1728 \ [[0x11, 0x78], "C-F9", 4],
1729 \ [[0x11, 0x10, 0x78], "C-S-F9", 4],
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001730 \ ]
1731
1732 for [kcodes, kstr, kmod] in keytests
1733 call SendKeys(kcodes)
1734 let ch = getcharstr()
1735 let mod = getcharmod()
Yegappan Lakshmanan0adae2d2022-09-09 17:39:02 +01001736 let keycode = eval('"\<' .. kstr .. '>"')
1737 call assert_equal(keycode, ch, $"key = {kstr}")
1738 call assert_equal(kmod, mod, $"key = {kstr}")
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001739 endfor
1740
1741 bw!
1742endfunc
1743
Bram Moolenaar0e05de42020-03-25 22:23:46 +01001744" vim: shiftwidth=2 sts=2 expandtab