blob: 447eee86529b0023839994a40c5f59cbc6475ece [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
Bram Moolenaar572a4432022-09-28 21:07:03 +0100160 call writefile(['some', 'lines'], 'Xstdin', 'D')
Bram Moolenaard68a0042021-10-20 23:08:11 +0100161 let script =<< trim END
162 call writefile(getline(1, '$'), 'XstdinOK')
163 qa!
164 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100165 call writefile(script, 'Xscript', 'D')
Bram Moolenaard68a0042021-10-20 23:08:11 +0100166
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
Bram Moolenaard68a0042021-10-20 23:08:11 +0100179 call delete('XstdinOK')
Bram Moolenaard68a0042021-10-20 23:08:11 +0100180endfunc
181
Bram Moolenaar87748452017-03-12 17:10:33 +0100182func Test_set_background()
183 let background_saved = &background
184
185 set background&
186 call assert_equal('light', &background)
187
188 set background=dark
189 call assert_equal('dark', &background)
190
191 let &background = background_saved
192endfunc
193
Bram Moolenaard5841f22017-03-05 13:27:25 +0100194func Test_set_balloondelay()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200195 CheckOption balloondelay
Bram Moolenaard5841f22017-03-05 13:27:25 +0100196
197 let balloondelay_saved = &balloondelay
198
199 " Check if the default value is identical to that described in the manual.
200 set balloondelay&
201 call assert_equal(600, &balloondelay)
202
203 " Edge cases
204
205 " XXX This fact should be hidden so that people won't be tempted to write
206 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
207 " code.
208 set balloondelay=-1
209 call assert_equal(-1, &balloondelay)
210
211 " Though it's possible to interpret the zero delay to be 'as soon as
212 " possible' or even 'indefinite', its actual meaning depends on the GUI
213 " toolkit in use after all.
214 set balloondelay=0
215 call assert_equal(0, &balloondelay)
216
217 set balloondelay=1
218 call assert_equal(1, &balloondelay)
219
220 " Since p_bdelay is of type long currently, the upper bound can be
221 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100222 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
223 set balloondelay=2147483647
224 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100225
226 let &balloondelay = balloondelay_saved
227endfunc
228
229func Test_set_ballooneval()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200230 CheckOption ballooneval
Bram Moolenaard5841f22017-03-05 13:27:25 +0100231
232 let ballooneval_saved = &ballooneval
233
234 set ballooneval&
235 call assert_equal(0, &ballooneval)
236
237 set ballooneval
238 call assert_notequal(0, &ballooneval)
239
240 set noballooneval
241 call assert_equal(0, &ballooneval)
242
243 let &ballooneval = ballooneval_saved
244endfunc
245
246func Test_set_balloonexpr()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200247 CheckOption balloonexpr
Bram Moolenaard5841f22017-03-05 13:27:25 +0100248
249 let balloonexpr_saved = &balloonexpr
250
251 " Default value
252 set balloonexpr&
253 call assert_equal('', &balloonexpr)
254
255 " User-defined function
256 new
257 func MyBalloonExpr()
258 return 'Cursor is at line ' . v:beval_lnum .
259 \', column ' . v:beval_col .
260 \ ' of file ' . bufname(v:beval_bufnr) .
261 \ ' on word "' . v:beval_text . '"' .
262 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
263 endfunc
264 setl balloonexpr=MyBalloonExpr()
265 setl ballooneval
266 call assert_equal('MyBalloonExpr()', &balloonexpr)
267 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200268 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100269 " Also, check if textlock works as expected.
270 setl balloonexpr&
271 call assert_equal('', &balloonexpr)
272 delfunc MyBalloonExpr
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000273
274 " Using a script-local function
275 func s:NewBalloonExpr()
276 endfunc
277 set balloonexpr=s:NewBalloonExpr()
278 call assert_equal(expand('<SID>') .. 'NewBalloonExpr()', &balloonexpr)
279 set balloonexpr=<SID>NewBalloonExpr()
280 call assert_equal(expand('<SID>') .. 'NewBalloonExpr()', &balloonexpr)
281 delfunc s:NewBalloonExpr
Bram Moolenaard5841f22017-03-05 13:27:25 +0100282 bwipe!
283
284 " Multiline support
285 if has('balloon_multiline')
286 " Multiline balloon using NL
287 new
288 func MyBalloonFuncForMultilineUsingNL()
Dominique Pelle81b573d2022-03-22 21:14:55 +0000289 return "Multiline\nSupported\nBalloon\nusing NL"
Bram Moolenaard5841f22017-03-05 13:27:25 +0100290 endfunc
291 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
292 setl ballooneval
293 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
294 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200295 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100296 " expected. Also, check if textlock works as expected.
297 setl balloonexpr&
298 delfunc MyBalloonFuncForMultilineUsingNL
299 bwipe!
300
301 " Multiline balloon using List
302 new
303 func MyBalloonFuncForMultilineUsingList()
Dominique Pelle81b573d2022-03-22 21:14:55 +0000304 return [ 'Multiline', 'Supported', 'Balloon', 'using List' ]
Bram Moolenaard5841f22017-03-05 13:27:25 +0100305 endfunc
306 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
307 setl ballooneval
308 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
309 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200310 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100311 " expected. Also, check if textlock works as expected.
312 setl balloonexpr&
313 delfunc MyBalloonFuncForMultilineUsingList
314 bwipe!
315 endif
316
317 let &balloonexpr = balloonexpr_saved
318endfunc
319
Bram Moolenaar87748452017-03-12 17:10:33 +0100320" Invalid arguments are tested with test_options in conjunction with segfaults
321" caused by them (Patch 8.0.0357, 24922ec233).
322func Test_set_guicursor()
323 let guicursor_saved = &guicursor
324
325 let default = [
326 \ "n-v-c:block-Cursor/lCursor",
327 \ "ve:ver35-Cursor",
328 \ "o:hor50-Cursor",
329 \ "i-ci:ver25-Cursor/lCursor",
330 \ "r-cr:hor20-Cursor/lCursor",
331 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
332 \ ]
333
334 " Default Value
335 set guicursor&
336 call assert_equal(join(default, ','), &guicursor)
337
338 " Argument List Example 1
339 let opt_list = copy(default)
340 let opt_list[0] = "n-c-v:block-nCursor"
341 exec "set guicursor=" . join(opt_list, ',')
342 call assert_equal(join(opt_list, ','), &guicursor)
343 unlet opt_list
344
345 " Argument List Example 2
346 let opt_list = copy(default)
347 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
348 exec "set guicursor=" . join(opt_list, ',')
349 call assert_equal(join(opt_list, ','), &guicursor)
350 unlet opt_list
351
352 " 'a' Mode
353 set guicursor&
354 let &guicursor .= ',a:blinkon0'
355 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
356
357 let &guicursor = guicursor_saved
358endfunc
359
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100360func Test_set_guifont_errors()
361 if has('win32')
362 " Invalid font names are accepted in GTK GUI
363 call assert_fails('set guifont=xa1bc23d7f', 'E596:')
364 endif
365
366 " This only works if 'renderoptions' exists and does not work for Windows XP
367 " and older.
368 if exists('+renderoptions') && windowsversion() !~ '^[345]\.'
369 " doing this four times used to cause a crash
370 set renderoptions=type:directx
371 for i in range(5)
372 set guifont=
373 endfor
374 set renderoptions=
375 for i in range(5)
376 set guifont=
377 endfor
378 endif
379endfunc
380
Bram Moolenaar43dded82017-02-09 16:06:17 +0100381func Test_set_guifont()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100382 CheckX11BasedGui
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100383
384 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100385 if has('xfontset')
386 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100387 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100388 set guifontset=
389 endif
390
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100391 if has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100392 " Non-empty font list with invalid font names.
393 "
394 " This test is twofold: (1) It checks if the command fails as expected
395 " when there are no loadable fonts found in the list. (2) It checks if
396 " 'guifont' remains the same after the command loads none of the fonts
397 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100398 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100399 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100400 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100401
402 " Non-empty font list with a valid font name. Should pick up the first
403 " valid font.
404 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100405 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
406 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100407
408 " Empty list. Should fallback to the built-in default.
409 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100410 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
411 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100412
413 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
414 " For GTK, what we refer to as 'font names' in our manual are actually
415 " 'initial font patterns'. A valid font which matches the 'canonical font
416 " pattern' constructed from a given 'initial pattern' is to be looked up
417 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
418 " font names'.
419 "
420 " Non-empty list. Should always pick up the first element, no matter how
421 " strange it is, as explained above.
422 set guifont=(´・ω・`)\ 12,Courier\ 12
423 call assert_equal('(´・ω・`) 12', getfontname())
424
425 " Empty list. Should fallback to the built-in default.
426 set guifont=
427 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100428 endif
429
430 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100431 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100432 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100433 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100434endfunc
435
Bram Moolenaar10434672017-02-12 19:59:08 +0100436func Test_set_guifontset()
Bram Moolenaarce90e362019-09-08 18:58:44 +0200437 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100438 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100439
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200440 call assert_fails('set guifontset=*', 'E597:')
441
Bram Moolenaarce90e362019-09-08 18:58:44 +0200442 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100443
Bram Moolenaarce90e362019-09-08 18:58:44 +0200444 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
445 " be chosen meticulously.
446 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100447
Bram Moolenaarce90e362019-09-08 18:58:44 +0200448 let font_aw70 = font_head . '-130-75-75-c-70'
449 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100450
Bram Moolenaarce90e362019-09-08 18:58:44 +0200451 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
452 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100453
Bram Moolenaarce90e362019-09-08 18:58:44 +0200454 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
455 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
456 let singleton = font_head . '-*'
457 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100458
Bram Moolenaarce90e362019-09-08 18:58:44 +0200459 " Second, among 'locales', look up such a locale that gets 'set
460 " guifontset=' to work successfully with every fontset specified with
461 " 'fontsets'.
462 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
463 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100464
Bram Moolenaarce90e362019-09-08 18:58:44 +0200465 let feasible = 0
466 for locale in locales
467 try
468 exec 'language ctype' locale
469 catch /^Vim\%((\a\+)\)\=:E197/
470 continue
471 endtry
472 let done = 0
473 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100474 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200475 exec 'set guifontset=' . fontset
476 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
477 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100478 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200479 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100480 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200481 if done == len(fontsets)
482 let feasible = 1
483 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100484 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200485 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100486
Bram Moolenaarce90e362019-09-08 18:58:44 +0200487 " Third, give a set of tests if it is found feasible.
488 if !feasible
489 let skipped = g:not_hosted
490 else
491 " N.B. 'v:ctype' has already been set to an appropriate value in the
492 " previous loop.
493 for fontset in fontsets
494 exec 'set guifontset=' . fontset
495 call assert_equal(fontset, &guifontset)
496 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100497 endif
498
Bram Moolenaarce90e362019-09-08 18:58:44 +0200499 " Finally, restore ctype.
500 exec 'language ctype' ctype_saved
501
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100502 if !empty(skipped)
503 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100504 endif
505endfunc
506
507func Test_set_guifontwide()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100508 CheckX11BasedGui
Bram Moolenaar10434672017-02-12 19:59:08 +0100509
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100510 call assert_fails('set guifontwide=*', 'E533:')
511
512 if has('gui_gtk')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100513 let guifont_saved = &guifont
514 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100515
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100516 let fc_match = exepath('fc-match')
517 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100518 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100519 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100520 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
521 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
522 exec 'set guifontwide=' . fnameescape(wide)
523 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100524 endif
525
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100526 let &guifontwide = guifontwide_saved
527 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100528
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100529 elseif has('gui_motif')
Bram Moolenaar10434672017-02-12 19:59:08 +0100530 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100531 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100532 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100533 else
534 let encoding_saved = &encoding
535 let guifont_saved = &guifont
536 let guifontset_saved = &guifontset
537 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100538
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100539 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
540 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100541
542 set encoding=utf-8
543
544 " Case 1: guifontset is empty
545 set guifontset=
546
547 " Case 1-1: Automatic selection
548 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100549 exec 'set guifont=' . nfont
550 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100551
552 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100553 exec 'set guifontwide=' . wfont
554 exec 'set guifont=' . nfont
555 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100556
557 " Case 2: guifontset is invalid
558 try
559 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100560 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100561 catch
Bram Moolenaare2e40752020-09-04 21:18:46 +0200562 call assert_exception('E598:')
Bram Moolenaar10434672017-02-12 19:59:08 +0100563 endtry
Bram Moolenaar10434672017-02-12 19:59:08 +0100564
565 " Case 2-1: Automatic selection
566 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100567 exec 'set guifont=' . nfont
568 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100569
570 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100571 exec 'set guifontwide=' . wfont
572 exec 'set guifont=' . nfont
573 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100574
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100575 let &guifontwide = guifontwide_saved
576 let &guifontset = guifontset_saved
577 let &guifont = guifont_saved
578 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100579 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100580 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100581endfunc
582
Dusan Popovic4eeedc02021-10-16 20:52:05 +0100583func Test_set_guiligatures()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100584 CheckX11BasedGui
Dusan Popovic4eeedc02021-10-16 20:52:05 +0100585
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100586 if has('gui_gtk') || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
587 " Try correct value
588 set guiligatures=<>=ab
589 call assert_equal("<>=ab", &guiligatures)
590 " Try to throw error
591 try
592 set guiligatures=<>=šab
593 call assert_report("'set guiligatures=<>=šab should have failed")
594 catch
595 call assert_exception('E1243:')
596 endtry
Dusan Popovic4eeedc02021-10-16 20:52:05 +0100597 endif
598endfunc
599
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100600func Test_set_guiheadroom()
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100601 CheckX11BasedGui
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100602
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100603 " Since this script is to be read together with '-U NONE', the default
604 " value must be preserved.
605 call assert_equal(50, &guiheadroom)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100606endfunc
607
Bram Moolenaar87748452017-03-12 17:10:33 +0100608func Test_set_guioptions()
609 let guioptions_saved = &guioptions
610 let duration = '200m'
611
612 if has('win32')
613 " Default Value
614 set guioptions&
615 call assert_equal('egmrLtT', &guioptions)
616
617 else
618 " Default Value
619 set guioptions&
620 call assert_equal('aegimrLtT', &guioptions)
621
622 " To activate scrollbars of type 'L' or 'R'.
623 wincmd v
624 redraw!
625
626 " Remove all default GUI ornaments
627 set guioptions-=T
628 exec 'sleep' . duration
629 call assert_equal('aegimrLt', &guioptions)
630 set guioptions-=t
631 exec 'sleep' . duration
632 call assert_equal('aegimrL', &guioptions)
633 set guioptions-=L
634 exec 'sleep' . duration
635 call assert_equal('aegimr', &guioptions)
636 set guioptions-=r
637 exec 'sleep' . duration
638 call assert_equal('aegim', &guioptions)
639 set guioptions-=m
640 exec 'sleep' . duration
641 call assert_equal('aegi', &guioptions)
642
643 " Try non-default GUI ornaments
644 set guioptions+=l
645 exec 'sleep' . duration
646 call assert_equal('aegil', &guioptions)
647 set guioptions-=l
648 exec 'sleep' . duration
649 call assert_equal('aegi', &guioptions)
650
651 set guioptions+=R
652 exec 'sleep' . duration
653 call assert_equal('aegiR', &guioptions)
654 set guioptions-=R
655 exec 'sleep' . duration
656 call assert_equal('aegi', &guioptions)
657
658 set guioptions+=b
659 exec 'sleep' . duration
660 call assert_equal('aegib', &guioptions)
661 set guioptions+=h
662 exec 'sleep' . duration
663 call assert_equal('aegibh', &guioptions)
664 set guioptions-=h
665 exec 'sleep' . duration
666 call assert_equal('aegib', &guioptions)
667 set guioptions-=b
668 exec 'sleep' . duration
669 call assert_equal('aegi', &guioptions)
670
671 set guioptions+=v
672 exec 'sleep' . duration
673 call assert_equal('aegiv', &guioptions)
674 set guioptions-=v
675 exec 'sleep' . duration
676 call assert_equal('aegi', &guioptions)
677
678 if has('gui_motif')
679 set guioptions+=F
680 exec 'sleep' . duration
681 call assert_equal('aegiF', &guioptions)
682 set guioptions-=F
683 exec 'sleep' . duration
684 call assert_equal('aegi', &guioptions)
685 endif
686
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200687 if has('gui_gtk3')
688 set guioptions+=d
689 exec 'sleep' . duration
690 call assert_equal('aegid', &guioptions)
691 set guioptions-=d
692 exec 'sleep' . duration
693 call assert_equal('aegi', &guioptions)
694 endif
695
Bram Moolenaar87748452017-03-12 17:10:33 +0100696 " Restore GUI ornaments to the default state.
697 set guioptions+=m
698 exec 'sleep' . duration
699 call assert_equal('aegim', &guioptions)
700 set guioptions+=r
701 exec 'sleep' . duration
702 call assert_equal('aegimr', &guioptions)
703 set guioptions+=L
704 exec 'sleep' . duration
705 call assert_equal('aegimrL', &guioptions)
706 set guioptions+=t
707 exec 'sleep' . duration
708 call assert_equal('aegimrLt', &guioptions)
709 set guioptions+=T
710 exec 'sleep' . duration
711 call assert_equal("aegimrLtT", &guioptions)
712
713 wincmd o
714 redraw!
715 endif
716
717 let &guioptions = guioptions_saved
718endfunc
719
Bram Moolenaarab186732018-09-14 21:27:06 +0200720func Test_scrollbars()
721 new
722 " buffer with 200 lines
723 call setline(1, repeat(['one', 'two'], 100))
724 set guioptions+=rlb
725
726 " scroll to move line 11 at top, moves the cursor there
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000727 let args = #{which: 'left', value: 10, dragging: 0}
728 call test_gui_event('scrollbar', args)
Bram Moolenaarab186732018-09-14 21:27:06 +0200729 redraw
730 call assert_equal(1, winline())
731 call assert_equal(11, line('.'))
732
733 " scroll to move line 1 at top, cursor stays in line 11
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000734 let args = #{which: 'right', value: 0, dragging: 0}
735 call test_gui_event('scrollbar', args)
Bram Moolenaarab186732018-09-14 21:27:06 +0200736 redraw
737 call assert_equal(11, winline())
738 call assert_equal(11, line('.'))
739
740 set nowrap
741 call setline(11, repeat('x', 150))
742 redraw
743 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200744 set number
745 redraw
746 call assert_equal(5, wincol())
747 set nonumber
748 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200749 call assert_equal(1, col('.'))
750
751 " scroll to character 11, cursor is moved
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000752 let args = #{which: 'hor', value: 10, dragging: 0}
753 call test_gui_event('scrollbar', args)
Bram Moolenaarab186732018-09-14 21:27:06 +0200754 redraw
755 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200756 set number
757 redraw
758 call assert_equal(5, wincol())
759 set nonumber
760 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200761 call assert_equal(11, col('.'))
762
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +0000763 " Invalid arguments
764 call assert_false(test_gui_event('scrollbar', {}))
765 call assert_false(test_gui_event('scrollbar', #{value: 10, dragging: 0}))
766 call assert_false(test_gui_event('scrollbar', #{which: 'hor', dragging: 0}))
767 call assert_false(test_gui_event('scrollbar', #{which: 'hor', value: 1}))
768 call assert_fails("call test_gui_event('scrollbar', #{which: 'a', value: 1, dragging: 0})", 'E475:')
769
Bram Moolenaarab186732018-09-14 21:27:06 +0200770 set guioptions&
771 set wrap&
772 bwipe!
773endfunc
774
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100775func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100776 CheckFeature quickfix
777
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100778 " Check Help menu exists
779 let help_menu = execute('menu Help')
780 call assert_match('Overview', help_menu)
781
782 " Check Help menu works
783 emenu Help.Overview
784 call assert_equal('help', &buftype)
785 close
786
787 " Check deleting menu doesn't cause trouble.
788 aunmenu Help
Bram Moolenaarb45cd362020-09-28 21:41:49 +0200789 if exists(':tlmenu')
790 tlunmenu Help
791 endif
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100792 call assert_fails('menu Help', 'E329:')
793endfunc
794
Bram Moolenaar87748452017-03-12 17:10:33 +0100795func Test_set_guipty()
796 let guipty_saved = &guipty
797
798 " Default Value
799 set guipty&
800 call assert_equal(1, &guipty)
801
802 set noguipty
803 call assert_equal(0, &guipty)
804
805 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100806endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100807
Bram Moolenaarc701f322019-03-28 21:49:21 +0100808func Test_encoding_conversion()
809 " GTK supports conversion between 'encoding' and "utf-8"
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200810 CheckFeature gui_gtk
811 let encoding_saved = &encoding
812 set encoding=latin1
Bram Moolenaarc701f322019-03-28 21:49:21 +0100813
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200814 " would be nice if we could take a screenshot
815 intro
816 " sets the window title
817 edit SomeFile
Bram Moolenaarc701f322019-03-28 21:49:21 +0100818
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200819 let &encoding = encoding_saved
Bram Moolenaarc701f322019-03-28 21:49:21 +0100820endfunc
821
Bram Moolenaar877e9572016-08-04 20:05:50 +0200822func Test_shell_command()
823 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200824 r !echo hello
825 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200826 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200827endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100828
Bram Moolenaar87748452017-03-12 17:10:33 +0100829func Test_syntax_colortest()
830 runtime syntax/colortest.vim
831 redraw!
832 sleep 200m
833 bwipe!
834endfunc
835
836func Test_set_term()
837 " It's enough to check the current value since setting 'term' to anything
838 " other than builtin_gui makes no sense at all.
839 call assert_equal('builtin_gui', &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200840 call assert_fails('set term=xterm', 'E530:')
Bram Moolenaar87748452017-03-12 17:10:33 +0100841endfunc
842
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100843func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100844 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100845 call assert_true(v:windowid > 0)
846 else
847 call assert_equal(0, v:windowid)
848 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100849endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200850
851" Test "vim -g" and also the GUIEnter autocommand.
852func Test_gui_dash_g()
853 let cmd = GetVimCommand('Xscriptgui')
Bram Moolenaar572a4432022-09-28 21:07:03 +0100854 call writefile([""], "Xtestgui", 'D')
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200855 let lines =<< trim END
856 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
857 au GUIEnter * qall
858 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100859 call writefile(lines, 'Xscriptgui', 'D')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200860 call system(cmd . ' -g')
861 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200862endfunc
863
864" Test "vim -7" and also the GUIEnter autocommand.
865func Test_gui_dash_y()
866 let cmd = GetVimCommand('Xscriptgui')
Bram Moolenaar572a4432022-09-28 21:07:03 +0100867 call writefile([""], "Xtestgui", 'D')
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200868 let lines =<< trim END
869 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
870 au GUIEnter * qall
871 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100872 call writefile(lines, 'Xscriptgui', 'D')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200873 call system(cmd . ' -y')
874 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200875endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100876
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200877" Test for "!" option in 'guioptions'. Use a terminal for running external
878" commands
879func Test_gui_run_cmd_in_terminal()
Bram Moolenaar4457e1d2020-05-15 22:46:44 +0200880 CheckFeature terminal
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200881 let save_guioptions = &guioptions
882 set guioptions+=!
883 if has('win32')
884 let cmd = 'type'
885 else
886 " assume all the other systems have a cat command
887 let cmd = 'cat'
888 endif
Bram Moolenaar98f16712020-05-22 13:34:01 +0200889 exe "silent !" . cmd . " test_gui.vim"
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200890 " TODO: how to check that the command ran in a separate terminal?
891 " Maybe check for $TERM (dumb vs xterm) in the spawned shell?
892 let &guioptions = save_guioptions
893endfunc
894
Bram Moolenaar46cd43b2020-06-04 22:22:11 +0200895func Test_gui_recursive_mapping()
896 nmap ' <C-W>
897 nmap <C-W>a :let didit = 1<CR>
898 call feedkeys("'a", 'xt')
899 call assert_equal(1, didit)
900
901 nunmap '
902 nunmap <C-W>a
903endfunc
904
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200905" Test GUI mouse events
906func Test_gui_mouse_event()
907 set mousemodel=extend
908 call test_override('no_query_mouse', 1)
909 new
910 call setline(1, ['one two three', 'four five six'])
911
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200912 " place the cursor using left click in normal mode
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200913 call cursor(1, 1)
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000914 let args = #{button: 0, row: 2, col: 4, multiclick: 0, modifiers: 0}
915 call test_gui_event('mouse', args)
916 let args.button = 3
917 eval 'mouse'->test_gui_event(args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200918 call feedkeys("\<Esc>", 'Lx!')
919 call assert_equal([0, 2, 4, 0], getpos('.'))
920
921 " select and yank a word
922 let @" = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000923 let args = #{button: 0, row: 1, col: 9, multiclick: 0, modifiers: 0}
924 call test_gui_event('mouse', args)
925 let args.multiclick = 1
926 call test_gui_event('mouse', args)
927 let args.button = 3
928 let args.multiclick = 0
929 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200930 call feedkeys("y", 'Lx!')
931 call assert_equal('three', @")
932
933 " create visual selection using right click
934 let @" = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000935 let args = #{button: 0, row: 2, col: 6, multiclick: 0, modifiers: 0}
936 call test_gui_event('mouse', args)
937 let args.button = 3
938 call test_gui_event('mouse', args)
939 let args = #{button: 2, row: 2, col: 13, multiclick: 0, modifiers: 0}
940 call test_gui_event('mouse', args)
941 let args.button = 3
942 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200943 call feedkeys("y", 'Lx!')
944 call assert_equal('five six', @")
945
946 " paste using middle mouse button
947 let @* = 'abc '
948 call feedkeys('""', 'Lx!')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000949 let args = #{button: 1, row: 1, col: 9, multiclick: 0, modifiers: 0}
950 call test_gui_event('mouse', args)
951 let args.button = 3
952 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200953 call feedkeys("\<Esc>", 'Lx!')
954 call assert_equal(['one two abc three', 'four five six'], getline(1, '$'))
955
956 " extend visual selection using right click in visual mode
957 let @" = ''
958 call cursor(1, 1)
959 call feedkeys('v', 'Lx!')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000960 let args = #{button: 2, row: 1, col: 17, multiclick: 0, modifiers: 0}
961 call test_gui_event('mouse', args)
962 let args.button = 3
963 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200964 call feedkeys("y", 'Lx!')
965 call assert_equal('one two abc three', @")
966
967 " extend visual selection using mouse drag
968 let @" = ''
969 call cursor(1, 1)
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000970 let args = #{button: 0, row: 2, col: 1, multiclick: 0, modifiers: 0}
971 call test_gui_event('mouse', args)
972 let args = #{button: 0x43, row: 2, col: 9, multiclick: 0, modifiers: 0}
973 call test_gui_event('mouse', args)
974 let args.button = 0x3
975 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200976 call feedkeys("y", 'Lx!')
977 call assert_equal('four five', @")
978
979 " select text by moving the mouse
980 let @" = ''
981 call cursor(1, 1)
982 redraw!
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000983 let args = #{button: 0, row: 1, col: 4, multiclick: 0, modifiers: 0}
984 call test_gui_event('mouse', args)
985 let args.button = 0x700
986 let args.col = 9
987 call test_gui_event('mouse', args)
988 let args.col = 13
989 call test_gui_event('mouse', args)
990 let args.button = 3
991 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200992 call feedkeys("y", 'Lx!')
993 call assert_equal(' two abc t', @")
994
995 " Using mouse in insert mode
996 call cursor(1, 1)
997 call feedkeys('i', 't')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000998 let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0}
999 call test_gui_event('mouse', args)
1000 let args.button = 3
1001 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001002 call feedkeys("po\<Esc>", 'Lx!')
1003 call assert_equal(['one two abc three', 'four five posix'], getline(1, '$'))
1004
1005 %d _
LemonBoyc27747e2022-05-07 12:25:40 +01001006 set scrolloff=0
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001007 call setline(1, range(1, 100))
1008 " scroll up
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001009 let args = #{button: 0x200, row: 2, col: 1, multiclick: 0, modifiers: 0}
1010 call test_gui_event('mouse', args)
1011 call test_gui_event('mouse', args)
1012 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001013 call feedkeys("H", 'Lx!')
1014 call assert_equal(10, line('.'))
1015
1016 " scroll down
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001017 let args = #{button: 0x100, row: 2, col: 1, multiclick: 0, modifiers: 0}
1018 call test_gui_event('mouse', args)
1019 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001020 call feedkeys("H", 'Lx!')
1021 call assert_equal(4, line('.'))
LemonBoyc27747e2022-05-07 12:25:40 +01001022 set scrolloff&
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001023
1024 %d _
1025 set nowrap
1026 call setline(1, range(10)->join('')->repeat(10))
1027 " scroll left
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001028 let args = #{button: 0x500, row: 1, col: 5, multiclick: 0, modifiers: 0}
1029 call test_gui_event('mouse', args)
1030 let args.col = 10
1031 call test_gui_event('mouse', args)
1032 let args.col = 15
1033 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001034 call feedkeys('g0', 'Lx!')
1035 call assert_equal(19, col('.'))
1036
1037 " scroll right
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001038 let args = #{button: 0x600, row: 1, col: 15, multiclick: 0, modifiers: 0}
1039 call test_gui_event('mouse', args)
1040 let args.col = 10
1041 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001042 call feedkeys('g0', 'Lx!')
1043 call assert_equal(7, col('.'))
1044 set wrap&
1045
1046 %d _
1047 call setline(1, repeat([repeat('a', 60)], 10))
1048
1049 " record various mouse events
1050 let mouseEventNames = [
1051 \ 'LeftMouse', 'LeftRelease', '2-LeftMouse', '3-LeftMouse',
1052 \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse',
1053 \ 'MiddleRelease', '2-MiddleMouse', '3-MiddleMouse',
1054 \ 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
1055 \ 'RightMouse', 'RightRelease', '2-RightMouse',
1056 \ '3-RightMouse', 'S-RightMouse', 'A-RightMouse', 'C-RightMouse',
1057 \ 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', 'C-X1Mouse', 'X2Mouse',
1058 \ 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'
1059 \ ]
1060 let mouseEventCodes = map(copy(mouseEventNames), "'<' .. v:val .. '>'")
1061 let g:events = []
1062 for e in mouseEventCodes
1063 exe 'nnoremap ' .. e .. ' <Cmd>call add(g:events, "' ..
1064 \ substitute(e, '[<>]', '', 'g') .. '")<CR>'
1065 endfor
1066
1067 " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1,
1068 " 0x300- X2)
1069 for button in [0, 1, 2, 0x300, 0x400]
1070 " Single click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001071 let args = #{button: button, row: 2, col: 5, multiclick: 0, modifiers: 0}
1072 call test_gui_event('mouse', args)
1073 let args.button = 3
1074 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001075
1076 " Double/Triple click is supported by only the Left/Middle/Right mouse
1077 " buttons
1078 if button <= 2
1079 " Double Click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001080 let args.button = button
1081 call test_gui_event('mouse', args)
1082 let args.multiclick = 1
1083 call test_gui_event('mouse', args)
1084 let args.button = 3
1085 let args.multiclick = 0
1086 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001087
1088 " Triple Click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001089 let args.button = button
1090 call test_gui_event('mouse', args)
1091 let args.multiclick = 1
1092 call test_gui_event('mouse', args)
1093 call test_gui_event('mouse', args)
1094 let args.button = 3
1095 let args.multiclick = 0
1096 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001097 endif
1098
1099 " Shift click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001100 let args = #{button: button, row: 3, col: 7, multiclick: 0, modifiers: 4}
1101 call test_gui_event('mouse', args)
1102 let args.button = 3
1103 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001104
1105 " Alt click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001106 let args.button = button
1107 let args.modifiers = 8
1108 call test_gui_event('mouse', args)
1109 let args.button = 3
1110 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001111
1112 " Ctrl click
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001113 let args.button = button
1114 let args.modifiers = 16
1115 call test_gui_event('mouse', args)
1116 let args.button = 3
1117 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001118
1119 call feedkeys("\<Esc>", 'Lx!')
1120 endfor
1121
1122 call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse',
1123 \ 'LeftMouse', '2-LeftMouse', '3-LeftMouse', 'S-LeftMouse',
1124 \ 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', 'MiddleRelease',
1125 \ 'MiddleMouse', '2-MiddleMouse', 'MiddleMouse', '2-MiddleMouse',
1126 \ '3-MiddleMouse', 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
1127 \ 'RightMouse', 'RightRelease', 'RightMouse', '2-RightMouse',
1128 \ 'RightMouse', '2-RightMouse', '3-RightMouse', 'S-RightMouse',
1129 \ 'A-RightMouse', 'C-RightMouse', 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse',
1130 \ 'C-X1Mouse', 'X2Mouse', 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'],
1131 \ g:events)
1132
1133 for e in mouseEventCodes
1134 exe 'nunmap ' .. e
1135 endfor
1136
1137 " modeless selection
1138 set mouse=
1139 let save_guioptions = &guioptions
1140 set guioptions+=A
1141 %d _
1142 call setline(1, ['one two three', 'four five sixteen'])
1143 call cursor(1, 1)
1144 redraw!
1145 " Double click should select the word and copy it to clipboard
1146 let @* = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001147 let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0}
1148 call test_gui_event('mouse', args)
1149 let args.multiclick = 1
1150 call test_gui_event('mouse', args)
1151 let args.button = 3
1152 let args.multiclick = 0
1153 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001154 call feedkeys("\<Esc>", 'Lx!')
1155 call assert_equal([0, 1, 1, 0], getpos('.'))
1156 call assert_equal('sixteen', @*)
1157 " Right click should extend the selection from cursor
1158 call cursor(1, 6)
1159 redraw!
1160 let @* = ''
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001161 let args = #{button: 2, row: 1, col: 11, multiclick: 0, modifiers: 0}
1162 call test_gui_event('mouse', args)
1163 let args.button = 3
1164 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001165 call feedkeys("\<Esc>", 'Lx!')
1166 call assert_equal([0, 1, 6, 0], getpos('.'))
1167 call assert_equal('wo thr', @*)
1168 " Middle click should paste the clipboard contents
1169 call cursor(2, 1)
1170 redraw!
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001171 let args = #{button: 1, row: 1, col: 11, multiclick: 0, modifiers: 0}
1172 call test_gui_event('mouse', args)
1173 let args.button = 3
1174 call test_gui_event('mouse', args)
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001175 call feedkeys("\<Esc>", 'Lx!')
1176 call assert_equal([0, 2, 7, 0], getpos('.'))
1177 call assert_equal('wo thrfour five sixteen', getline(2))
1178 set mouse&
1179 let &guioptions = save_guioptions
1180
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001181 " Test invalid parameters for test_gui_event()
1182 let args = #{row: 2, col: 4, multiclick: 0, modifiers: 0}
1183 call assert_false(test_gui_event('mouse', args))
1184 let args = #{button: 0, col: 4, multiclick: 0, modifiers: 0}
1185 call assert_false(test_gui_event('mouse', args))
1186 let args = #{button: 0, row: 2, multiclick: 0, modifiers: 0}
1187 call assert_false(test_gui_event('mouse', args))
1188 let args = #{button: 0, row: 2, col: 4, modifiers: 0}
1189 call assert_false(test_gui_event('mouse', args))
1190 let args = #{button: 0, row: 2, col: 4, multiclick: 0}
1191 call assert_false(test_gui_event('mouse', args))
1192
1193 " Error cases for test_gui_event()
1194 call assert_fails("call test_gui_event('a1b2c3', args)", 'E475:')
1195 call assert_fails("call test_gui_event([], args)", 'E1174:')
1196 call assert_fails("call test_gui_event('abc', [])", 'E1206:')
1197 call assert_fails("call test_gui_event(test_null_string(), {})", 'E475:')
1198 call assert_false(test_gui_event('mouse', test_null_dict()))
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001199
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +02001200 bw!
1201 call test_override('no_query_mouse', 0)
1202 set mousemodel&
1203endfunc
1204
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001205" Move the mouse to the top-left in preparation for mouse events
1206func PrepareForMouseEvent(args)
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001207 call extend(a:args, #{row: 1, col: 1})
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001208 call test_gui_event('mouse', a:args)
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001209 let g:eventlist = []
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001210 call feedkeys('', 'Lx!')
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001211
1212 " Wait a bit for the event. I may not come if the mouse didn't move, wait up
1213 " to 100 msec.
1214 for n in range(10)
1215 if len(g:eventlist) > 0
1216 break
1217 endif
1218 sleep 10m
1219 endfor
1220 let g:eventlist = []
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001221endfunc
1222
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001223func MouseWasMoved()
1224 let pos = getmousepos()
1225 call add(g:eventlist, #{row: pos.screenrow, col: pos.screencol})
1226endfunc
1227
Ernie Raelc4cb5442022-04-03 15:47:28 +01001228func Test_gui_mouse_move_event()
1229 let args = #{move: 1, button: 0, multiclick: 0, modifiers: 0}
1230
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001231 " by default, no mouse move events are generated
Ernie Raelc4cb5442022-04-03 15:47:28 +01001232 set mousemev&
1233 call assert_false(&mousemev)
1234
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001235 let g:eventlist = []
1236 nnoremap <special> <silent> <MouseMove> :call MouseWasMoved()<CR>
Ernie Raelc4cb5442022-04-03 15:47:28 +01001237
1238 " start at mouse pos (1,1), clear counter
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001239 call PrepareForMouseEvent(args)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001240
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001241 call extend(args, #{row: 3, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001242 call test_gui_event('mouse', args)
1243 call feedkeys('', 'Lx!')
1244
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001245 call extend(args, #{row: 10, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001246 call test_gui_event('mouse', args)
1247 call feedkeys('', 'Lx!')
1248
Bram Moolenaar36eb14f2022-09-01 14:38:01 +01001249 " no events since 'mousemev' is off
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001250 call assert_equal([], g:eventlist)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001251
1252 " turn on mouse events and try the same thing
1253 set mousemev
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001254 call PrepareForMouseEvent(args)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001255
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001256 call extend(args, #{row: 3, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001257 call test_gui_event('mouse', args)
1258 call feedkeys('', 'Lx!')
1259
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001260 call extend(args, #{row: 10, col: 30, cell: v:true})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001261 call test_gui_event('mouse', args)
1262 call feedkeys('', 'Lx!')
1263
Bram Moolenaar3c25a862022-05-16 17:07:41 +01001264 " FIXME: on MS-Windows we get a stray event first
1265 if has('win32') && len(g:eventlist) == 3
Bram Moolenaare5162e72022-05-16 16:41:35 +01001266 let g:eventlist = g:eventlist[1 : ]
1267 endif
1268
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001269 call assert_equal([#{row: 4, col: 31}, #{row: 11, col: 31}], g:eventlist)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001270
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001271 " wiggle the mouse around within a screen cell, shouldn't trigger events
1272 call extend(args, #{cell: v:false})
Bram Moolenaar3b675c22022-05-16 13:34:44 +01001273 call PrepareForMouseEvent(args)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001274
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001275 call extend(args, #{row: 1, col: 2, cell: v:false})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001276 call test_gui_event('mouse', args)
1277 call feedkeys('', 'Lx!')
1278
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001279 call extend(args, #{row: 2, col: 2, cell: v:false})
Ernie Raelc4cb5442022-04-03 15:47:28 +01001280 call test_gui_event('mouse', args)
1281 call feedkeys('', 'Lx!')
1282
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001283 call extend(args, #{row: 2, col: 1, 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 assert_equal([], g:eventlist)
Ernie Raelc4cb5442022-04-03 15:47:28 +01001288
Bram Moolenaar7add8d32022-05-16 15:27:46 +01001289 unlet g:eventlist
Ernie Raelc4cb5442022-04-03 15:47:28 +01001290 unmap <MouseMove>
1291 set mousemev&
1292endfunc
1293
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001294" Test for 'guitablabel' and 'guitabtooltip' options
1295func TestGuiTabLabel()
1296 call add(g:TabLabels, v:lnum + 100)
1297 let bufnrlist = tabpagebuflist(v:lnum)
1298 return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
1299endfunc
1300
1301func TestGuiTabToolTip()
1302 call add(g:TabToolTips, v:lnum + 200)
1303 let bufnrlist = tabpagebuflist(v:lnum)
1304 return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
1305endfunc
1306
1307func Test_gui_tablabel_tooltip()
1308 %bw!
1309 " Removing the tabline at the end of this test, reduces the window height by
1310 " one. Save and restore it after the test.
1311 let save_lines = &lines
1312 edit one
1313 set modified
1314 tabnew two
1315 set modified
1316 tabnew three
1317 set modified
1318 let g:TabLabels = []
1319 set guitablabel=%{TestGuiTabLabel()}
1320 call test_override('starting', 1)
1321 redrawtabline
1322 call test_override('starting', 0)
1323 call assert_true(index(g:TabLabels, 101) != -1)
1324 call assert_true(index(g:TabLabels, 102) != -1)
1325 call assert_true(index(g:TabLabels, 103) != -1)
1326 set guitablabel&
1327 unlet g:TabLabels
1328
1329 if has('gui_gtk')
1330 " Only on GTK+, the tooltip function is called even if the mouse is not
1331 " on the tabline. on Win32 and Motif, the tooltip function is called only
1332 " when the mouse pointer is over the tabline.
1333 let g:TabToolTips = []
1334 set guitabtooltip=%{TestGuiTabToolTip()}
1335 call test_override('starting', 1)
1336 redrawtabline
1337 call test_override('starting', 0)
1338 call assert_true(index(g:TabToolTips, 201) != -1)
1339 call assert_true(index(g:TabToolTips, 202) != -1)
1340 call assert_true(index(g:TabToolTips, 203) != -1)
1341 set guitabtooltip&
1342 unlet g:TabToolTips
1343 endif
1344 %bw!
1345 let &lines = save_lines
1346endfunc
1347
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001348" Test for dropping files into a window in GUI
1349func DropFilesInCmdLine()
1350 call feedkeys(":\"", 'L')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001351 let d = #{files: ['a.c', 'b.c'], row: &lines, col: 1, modifiers: 0}
1352 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001353 call feedkeys("\<CR>", 'L')
1354endfunc
1355
1356func Test_gui_drop_files()
Bram Moolenaar1d1ce612021-06-27 19:02:52 +02001357 CheckFeature drop_file
1358
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001359 %bw!
1360 %argdelete
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001361 let d = #{files: [], row: 1, col: 1, modifiers: 0}
1362 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001363 call assert_equal([], argv())
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001364 let d = #{files: [1, 2], row: 1, col: 1, modifiers: 0}
1365 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001366 call assert_equal([], argv())
1367
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001368 let d = #{files: ['a.c', 'b.c'], row: 1, col: 1, modifiers: 0}
1369 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001370 call assert_equal(['a.c', 'b.c'], argv())
1371 %bw!
1372 %argdelete
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001373 let d = #{files: [], row: 1, col: 1, modifiers: 0}
1374 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001375 call assert_equal([], argv())
1376 %bw!
1377 " if the buffer in the window is modified, then the file should be opened in
1378 " a new window
1379 set modified
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001380 let d = #{files: ['x.c', 'y.c'], row: 1, col: 1, modifiers: 0}
1381 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001382 call assert_equal(['x.c', 'y.c'], argv())
1383 call assert_equal(2, winnr('$'))
1384 call assert_equal('x.c', bufname(winbufnr(1)))
1385 %bw!
1386 %argdelete
1387 " if Ctrl is pressed, then the file should be opened in a new window
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001388 let d = #{files: ['s.py', 't.py'], row: 1, col: 1, modifiers: 0x10}
1389 eval 'dropfiles'->test_gui_event(d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001390 call assert_equal(['s.py', 't.py'], argv())
1391 call assert_equal(2, winnr('$'))
1392 call assert_equal('s.py', bufname(winbufnr(1)))
1393 %bw!
1394 %argdelete
1395 " drop the files in a non-current window
1396 belowright new
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001397 let d = #{files: ['a.py', 'b.py'], row: 1, col: 1, modifiers: 0}
1398 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001399 call assert_equal(['a.py', 'b.py'], argv())
1400 call assert_equal(2, winnr('$'))
1401 call assert_equal(1, winnr())
1402 call assert_equal('a.py', bufname(winbufnr(1)))
1403 %bw!
1404 %argdelete
1405 " pressing shift when dropping files should change directory
1406 let save_cwd = getcwd()
Bram Moolenaar572a4432022-09-28 21:07:03 +01001407 call mkdir('Xdropdir1', 'R')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001408 call writefile([], 'Xdropdir1/Xfile1')
1409 call writefile([], 'Xdropdir1/Xfile2')
1410 let d = #{files: ['Xdropdir1/Xfile1', 'Xdropdir1/Xfile2'], row: 1, col: 1,
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001411 \ modifiers: 0x4}
1412 call test_gui_event('dropfiles', d)
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001413 call assert_equal('Xdropdir1', fnamemodify(getcwd(), ':t'))
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001414 call assert_equal('Xfile1', @%)
1415 call chdir(save_cwd)
1416 " pressing shift when dropping directory and files should change directory
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001417 let d = #{files: ['Xdropdir1', 'Xdropdir1/Xfile2'], row: 1, col: 1, modifiers: 0x4}
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001418 call test_gui_event('dropfiles', d)
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001419 call assert_equal('Xdropdir1', fnamemodify(getcwd(), ':t'))
1420 call assert_equal('Xdropdir1', fnamemodify(@%, ':t'))
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001421 call chdir(save_cwd)
1422 %bw!
1423 %argdelete
1424 " dropping a directory should edit it
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001425 let d = #{files: ['Xdropdir1'], row: 1, col: 1, modifiers: 0}
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', @%)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001428 %bw!
1429 %argdelete
1430 " dropping only a directory name with Shift should ignore it
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001431 let d = #{files: ['Xdropdir1'], row: 1, col: 1, modifiers: 0x4}
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001432 call test_gui_event('dropfiles', d)
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001433 call assert_equal('', @%)
1434 %bw!
1435 %argdelete
Bram Moolenaar00d4cee2022-08-28 13:38:43 +01001436
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001437 " drop files in the command line. The GUI drop files adds the file names to
1438 " the low level input buffer. So need to use a cmdline map and feedkeys()
1439 " with 'Lx!' to process it in this function itself.
Bram Moolenaar00d4cee2022-08-28 13:38:43 +01001440 " This sometimes fails, e.g. when using valgrind.
1441 let g:test_is_flaky = 1
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001442 cnoremap <expr> <buffer> <F4> DropFilesInCmdLine()
1443 call feedkeys(":\"\<F4>\<CR>", 'xt')
1444 call feedkeys('k', 'Lx!')
1445 call assert_equal('"a.c b.c', @:)
1446 cunmap <buffer> <F4>
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001447
1448 " Invalid arguments
1449 call assert_false(test_gui_event("dropfiles", {}))
1450 let d = #{row: 1, col: 1, modifiers: 0}
1451 call assert_false(test_gui_event("dropfiles", d))
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +00001452 let d = #{files: 1, row: 1, col: 1, modifiers: 0}
1453 call assert_false(test_gui_event("dropfiles", d))
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001454 let d = #{files: test_null_list(), row: 1, col: 1, modifiers: 0}
1455 call assert_false(test_gui_event("dropfiles", d))
1456 let d = #{files: [test_null_string()], row: 1, col: 1, modifiers: 0}
1457 call assert_true(test_gui_event("dropfiles", d))
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +02001458endfunc
1459
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001460" Test for generating a GUI tabline event to select a tab page
1461func Test_gui_tabline_event()
1462 %bw!
1463 edit Xfile1
1464 tabedit Xfile2
1465 tabedit Xfile3
1466
1467 tabfirst
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001468 call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 2}))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001469 call feedkeys("y", "Lx!")
1470 call assert_equal(2, tabpagenr())
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001471 call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 3}))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001472 call feedkeys("y", "Lx!")
1473 call assert_equal(3, tabpagenr())
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001474 call assert_equal(v:false, 'tabline'->test_gui_event(#{tabnr: 3}))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001475
1476 " From the cmdline window, tabline event should not be handled
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001477 call feedkeys("q::let t = test_gui_event('tabline', #{tabnr: 2})\<CR>:q\<CR>", 'x!')
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001478 call assert_equal(v:false, t)
1479
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001480 " Invalid arguments
1481 call assert_false(test_gui_event('tabline', {}))
1482 call assert_false(test_gui_event('tabline', #{abc: 1}))
1483
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001484 %bw!
1485endfunc
1486
1487" Test for generating a GUI tabline menu event to execute an action
1488func Test_gui_tabmenu_event()
1489 %bw!
1490
1491 " Try to close the last tab page
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001492 call test_gui_event('tabmenu', #{tabnr: 1, item: 1})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001493 call feedkeys("y", "Lx!")
1494
1495 edit Xfile1
1496 tabedit Xfile2
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001497 call test_gui_event('tabmenu', #{tabnr: 1, item: 1})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001498 call feedkeys("y", "Lx!")
1499 call assert_equal(1, tabpagenr('$'))
1500 call assert_equal('Xfile2', bufname())
1501
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001502 eval 'tabmenu'->test_gui_event(#{tabnr: 1, item: 2})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001503 call feedkeys("y", "Lx!")
1504 call assert_equal(2, tabpagenr('$'))
1505
1506 " If tabnr is 0, then the current tabpage should be used.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001507 call test_gui_event('tabmenu', #{tabnr: 0, item: 2})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001508 call feedkeys("y", "Lx!")
1509 call assert_equal(3, tabpagenr('$'))
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +00001510 call test_gui_event('tabmenu', #{tabnr: 0, item: 1})
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001511 call feedkeys("y", "Lx!")
1512 call assert_equal(2, tabpagenr('$'))
1513
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001514 " Invalid arguments
1515 call assert_false(test_gui_event('tabmenu', {}))
1516 call assert_false(test_gui_event('tabmenu', #{tabnr: 1}))
1517 call assert_false(test_gui_event('tabmenu', #{item: 1}))
1518 call assert_false(test_gui_event('tabmenu', #{abc: 1}))
1519
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001520 %bw!
1521endfunc
1522
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001523" Test for find/replace text dialog event
1524func Test_gui_findrepl()
Yegappan Lakshmanan08238042022-03-07 16:57:22 +00001525 " Find/Replace dialog is supported only on GTK, Motif and MS-Windows.
1526 if !has('gui_gtk') && !has('gui_motif') && !has('gui_win32')
1527 return
1528 endif
1529
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001530 new
1531 call setline(1, ['one two one', 'Twoo One two oneo'])
1532
1533 " Replace all instances of a string with another
1534 let args = #{find_text: 'one', repl_text: 'ONE', flags: 0x4, forward: 1}
1535 call test_gui_event('findrepl', args)
1536 call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
1537
1538 " Replace all instances of a whole string with another
1539 call cursor(1, 1)
1540 let args = #{find_text: 'two', repl_text: 'TWO', flags: 0xC, forward: 1}
1541 call test_gui_event('findrepl', args)
1542 call assert_equal(['ONE TWO ONE', 'Twoo ONE TWO ONEo'], getline(1, '$'))
1543
Dominique Pelle81b573d2022-03-22 21:14:55 +00001544 " Find next occurrence of a string (in a find dialog)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001545 call cursor(1, 11)
1546 let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 1}
1547 call test_gui_event('findrepl', args)
1548 call assert_equal([2, 10], [line('.'), col('.')])
1549
Dominique Pelle81b573d2022-03-22 21:14:55 +00001550 " Find previous occurrences of a string (in a find dialog)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001551 call cursor(1, 11)
1552 let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 0}
1553 call test_gui_event('findrepl', args)
1554 call assert_equal([1, 5], [line('.'), col('.')])
1555
Dominique Pelle81b573d2022-03-22 21:14:55 +00001556 " Find next occurrence of a string (in a replace dialog)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001557 call cursor(1, 1)
1558 let args = #{find_text: 'Twoo', repl_text: '', flags: 0x2, forward: 1}
1559 call test_gui_event('findrepl', args)
1560 call assert_equal([2, 1], [line('.'), col('.')])
1561
Dominique Pelle81b573d2022-03-22 21:14:55 +00001562 " Replace only the next occurrence of a string (once)
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001563 call cursor(1, 5)
1564 let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x3, forward: 1}
1565 call test_gui_event('findrepl', args)
1566 call assert_equal(['ONE two ONE', 'Twoo ONE TWO ONEo'], getline(1, '$'))
1567
1568 " Replace all instances of a whole string with another matching case
1569 call cursor(1, 1)
1570 let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x1C, forward: 1}
1571 call test_gui_event('findrepl', args)
1572 call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +00001573
matveyt2834ebd2022-09-06 17:00:15 +01001574 " Replace all instances with sub-replace specials
1575 call cursor(1, 1)
1576 let args = #{find_text: 'ONE', repl_text: '&~&', flags: 0x4, forward: 1}
1577 call test_gui_event('findrepl', args)
1578 call assert_equal(['&~& two &~&', 'Twoo &~& two &~&o'], getline(1, '$'))
1579
Yegappan Lakshmanan9e0208f2022-01-31 17:40:55 +00001580 " Invalid arguments
1581 call assert_false(test_gui_event('findrepl', {}))
1582 let args = #{repl_text: 'a', flags: 1, forward: 1}
1583 call assert_false(test_gui_event('findrepl', args))
1584 let args = #{find_text: 'a', flags: 1, forward: 1}
1585 call assert_false(test_gui_event('findrepl', args))
1586 let args = #{find_text: 'a', repl_text: 'b', forward: 1}
1587 call assert_false(test_gui_event('findrepl', args))
1588 let args = #{find_text: 'a', repl_text: 'b', flags: 1}
1589 call assert_false(test_gui_event('findrepl', args))
1590
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +00001591 bw!
1592endfunc
1593
zeertzjqbad8a012022-04-29 16:44:00 +01001594func Test_gui_CTRL_SHIFT_V()
1595 call feedkeys(":let g:str = '\<*C-S-V>\<*C-S-I>\<*C-S-V>\<*C-S-@>'\<CR>", 'tx')
zeertzjq758a8d12022-04-29 11:06:34 +01001596 call assert_equal('<C-S-I><C-S-@>', g:str)
1597 unlet g:str
1598endfunc
1599
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001600func Test_gui_dialog_file()
K.Takatae68f1342022-09-07 13:01:11 +01001601 " make sure the file does not exist, otherwise a dialog makes Vim hang
1602 call delete('Xdialfile')
1603
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001604 let lines =<< trim END
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001605 file Xdialfile
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001606 normal axxx
1607 confirm qa
1608 END
K.Takatae68f1342022-09-07 13:01:11 +01001609 call writefile(lines, 'Xlines', 'D')
Bram Moolenaara2726242022-06-16 16:36:43 +01001610 let prefix = '!'
1611 if has('win32')
1612 let prefix = '!start '
1613 endif
1614 execute prefix .. GetVimCommand() .. ' -g -f --clean --gui-dialog-file Xdialog -S Xlines'
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001615
1616 call WaitForAssert({-> assert_true(filereadable('Xdialog'))})
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001617 call assert_match('Question: Save changes to "Xdialfile"?', readfile('Xdialog')->join('<NL>'))
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001618
1619 call delete('Xdialog')
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001620 call delete('Xdialfile')
Bram Moolenaarde8be2b2022-06-16 14:45:41 +01001621endfunc
1622
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001623" Test for sending low level key presses
1624func SendKeys(keylist)
1625 for k in a:keylist
1626 call test_gui_event("sendevent", #{event: "keydown", keycode: k})
1627 endfor
1628 for k in reverse(a:keylist)
1629 call test_gui_event("sendevent", #{event: "keyup", keycode: k})
1630 endfor
1631endfunc
1632
1633func Test_gui_lowlevel_keyevent()
1634 CheckMSWindows
1635 new
1636
1637 " Test for <Ctrl-A> to <Ctrl-Z> keys
1638 for kc in range(65, 90)
1639 call SendKeys([0x11, kc])
1640 let ch = getcharstr()
1641 call assert_equal(nr2char(kc - 64), ch)
1642 endfor
1643
1644 " Test for the various Ctrl and Shift key combinations.
Yegappan Lakshmanan0adae2d2022-09-09 17:39:02 +01001645 " Refer to the following page for the virtual key codes:
1646 " https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001647 let keytests = [
Yegappan Lakshmanan0adae2d2022-09-09 17:39:02 +01001648 \ [[0x10, 0x21], "S-Pageup", 2],
1649 \ [[0xA0, 0x21], "S-Pageup", 2],
1650 \ [[0xA1, 0x21], "S-Pageup", 2],
1651 \ [[0x11, 0x21], "C-Pageup", 4],
1652 \ [[0xA2, 0x21], "C-Pageup", 4],
1653 \ [[0xA3, 0x21], "C-Pageup", 4],
1654 \ [[0x11, 0x10, 0x21], "C-S-Pageup", 6],
1655 \ [[0x10, 0x22], "S-PageDown", 2],
1656 \ [[0xA0, 0x22], "S-PageDown", 2],
1657 \ [[0xA1, 0x22], "S-PageDown", 2],
1658 \ [[0x11, 0x22], "C-PageDown", 4],
1659 \ [[0xA2, 0x22], "C-PageDown", 4],
1660 \ [[0xA3, 0x22], "C-PageDown", 4],
1661 \ [[0x11, 0x10, 0x22], "C-S-PageDown", 6],
1662 \ [[0x10, 0x23], "S-End", 0],
1663 \ [[0x11, 0x23], "C-End", 0],
1664 \ [[0x11, 0x10, 0x23], "C-S-End", 4],
1665 \ [[0x10, 0x24], "S-Home", 0],
1666 \ [[0x11, 0x24], "C-Home", 0],
1667 \ [[0x11, 0x10, 0x24], "C-S-Home", 4],
1668 \ [[0x10, 0x25], "S-Left", 0],
1669 \ [[0x11, 0x25], "C-Left", 0],
1670 \ [[0x11, 0x10, 0x25], "C-S-Left", 4],
1671 \ [[0x10, 0x26], "S-Up", 0],
1672 \ [[0x11, 0x26], "C-Up", 4],
1673 \ [[0x11, 0x10, 0x26], "C-S-Up", 4],
1674 \ [[0x10, 0x27], "S-Right", 0],
1675 \ [[0x11, 0x27], "C-Right", 0],
1676 \ [[0x11, 0x10, 0x27], "C-S-Right", 4],
1677 \ [[0x10, 0x28], "S-Down", 0],
1678 \ [[0x11, 0x28], "C-Down", 4],
1679 \ [[0x11, 0x10, 0x28], "C-S-Down", 4],
1680 \ [[0x11, 0x30], "C-0", 4],
1681 \ [[0x11, 0x31], "C-1", 4],
1682 \ [[0x11, 0x32], "C-2", 4],
1683 \ [[0x11, 0x33], "C-3", 4],
1684 \ [[0x11, 0x34], "C-4", 4],
1685 \ [[0x11, 0x35], "C-5", 4],
1686 \ [[0x11, 0x36], "C-^", 0],
1687 \ [[0x11, 0x37], "C-7", 4],
1688 \ [[0x11, 0x38], "C-8", 4],
1689 \ [[0x11, 0x39], "C-9", 4],
1690 \ [[0x11, 0x60], "C-0", 4],
1691 \ [[0x11, 0x61], "C-1", 4],
1692 \ [[0x11, 0x62], "C-2", 4],
1693 \ [[0x11, 0x63], "C-3", 4],
1694 \ [[0x11, 0x64], "C-4", 4],
1695 \ [[0x11, 0x65], "C-5", 4],
1696 \ [[0x11, 0x66], "C-6", 4],
1697 \ [[0x11, 0x67], "C-7", 4],
1698 \ [[0x11, 0x68], "C-8", 4],
1699 \ [[0x11, 0x69], "C-9", 4],
1700 \ [[0x11, 0x6A], "C-*", 4],
1701 \ [[0x11, 0x6B], "C-+", 4],
1702 \ [[0x11, 0x6D], "C--", 4],
1703 \ [[0x11, 0x70], "C-F1", 4],
1704 \ [[0x11, 0x10, 0x70], "C-S-F1", 4],
1705 \ [[0x11, 0x71], "C-F2", 4],
1706 \ [[0x11, 0x10, 0x71], "C-S-F2", 4],
1707 \ [[0x11, 0x72], "C-F3", 4],
1708 \ [[0x11, 0x10, 0x72], "C-S-F3", 4],
1709 \ [[0x11, 0x73], "C-F4", 4],
1710 \ [[0x11, 0x10, 0x73], "C-S-F4", 4],
1711 \ [[0x11, 0x74], "C-F5", 4],
1712 \ [[0x11, 0x10, 0x74], "C-S-F5", 4],
1713 \ [[0x11, 0x75], "C-F6", 4],
1714 \ [[0x11, 0x10, 0x75], "C-S-F6", 4],
1715 \ [[0x11, 0x76], "C-F7", 4],
1716 \ [[0x11, 0x10, 0x76], "C-S-F7", 4],
1717 \ [[0x11, 0x77], "C-F8", 4],
1718 \ [[0x11, 0x10, 0x77], "C-S-F8", 4],
1719 \ [[0x11, 0x78], "C-F9", 4],
1720 \ [[0x11, 0x10, 0x78], "C-S-F9", 4],
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001721 \ ]
1722
1723 for [kcodes, kstr, kmod] in keytests
1724 call SendKeys(kcodes)
1725 let ch = getcharstr()
1726 let mod = getcharmod()
Yegappan Lakshmanan0adae2d2022-09-09 17:39:02 +01001727 let keycode = eval('"\<' .. kstr .. '>"')
1728 call assert_equal(keycode, ch, $"key = {kstr}")
1729 call assert_equal(kmod, mod, $"key = {kstr}")
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +01001730 endfor
1731
1732 bw!
1733endfunc
1734
Bram Moolenaar0e05de42020-03-25 22:23:46 +01001735" vim: shiftwidth=2 sts=2 expandtab