xref: /vim-8.2.3635/src/testdir/test_gui.vim (revision 95bafa29)
1" Tests specifically for the GUI
2
3source shared.vim
4if !CanRunGui()
5  finish
6endif
7
8source setup_gui.vim
9
10func Setup()
11  call GUISetUpCommon()
12endfunc
13
14func TearDown()
15  call GUITearDownCommon()
16endfunc
17
18" Test for resetting "secure" flag after GUI has started.
19" Must be run first, since it starts the GUI on Unix.
20func Test_1_set_secure()
21  set exrc secure
22  gui -f
23  call assert_equal(1, has('gui_running'))
24endfunc
25
26" As for non-GUI, a balloon_show() test was already added with patch 8.0.0401
27func Test_balloon_show()
28  if has('balloon_eval')
29    " This won't do anything but must not crash either.
30    call balloon_show('hi!')
31  endif
32endfunc
33
34func Test_colorscheme()
35  let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
36  let g:color_count = 0
37  augroup TestColors
38    au!
39    au ColorScheme * let g:color_count += 1| let g:after_colors = g:color_count
40    au ColorSchemePre * let g:color_count += 1 |let g:before_colors = g:color_count
41  augroup END
42
43  colorscheme torte
44  redraw!
45  sleep 200m
46  call assert_equal('dark', &background)
47  call assert_equal(1, g:before_colors)
48  call assert_equal(2, g:after_colors)
49
50  exec 'colorscheme' colorscheme_saved
51  augroup TestColors
52    au!
53  augroup END
54  unlet g:color_count g:after_colors g:before_colors
55  redraw!
56endfunc
57
58func Test_getfontname_with_arg()
59  let skipped = ''
60
61  if !g:x11_based_gui
62    let skipped = g:not_implemented
63  elseif has('gui_athena') || has('gui_motif')
64    " Invalid font name. The result should be an empty string.
65    call assert_equal('', getfontname('notexist'))
66
67    " Valid font name. This is usually the real name of 7x13 by default.
68    let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
69    call assert_match(fname, getfontname(fname))
70
71  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
72    " Invalid font name. The result should be the name plus the default size.
73    call assert_equal('notexist 10', getfontname('notexist'))
74
75    " Valid font name. This is usually the real name of Monospace by default.
76    let fname = 'Bitstream Vera Sans Mono 12'
77    call assert_equal(fname, getfontname(fname))
78  endif
79
80  if !empty(skipped)
81    throw skipped
82  endif
83endfunc
84
85func Test_getfontname_without_arg()
86  let skipped = ''
87
88  let fname = getfontname()
89
90  if !g:x11_based_gui
91    let skipped = g:not_implemented
92  elseif has('gui_kde')
93    " 'expected' is the value specified by SetUp() above.
94    call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
95  elseif has('gui_athena') || has('gui_motif')
96    " 'expected' is DFLT_FONT of gui_x11.c or its real name.
97    let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
98    call assert_match(pat, fname)
99  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
100    " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
101    call assert_equal('Monospace 10', fname)
102  endif
103
104  if !empty(skipped)
105    throw skipped
106  endif
107endfunc
108
109func Test_getwinpos()
110  call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
111  call assert_true(getwinposx() >= 0)
112  call assert_true(getwinposy() >= 0)
113  call assert_equal([getwinposx(), getwinposy()], getwinpos())
114endfunc
115
116func Test_quoteplus()
117  let skipped = ''
118
119  if !g:x11_based_gui
120    let skipped = g:not_supported . 'quoteplus'
121  else
122    let quoteplus_saved = @+
123
124    let test_call     = 'Can you hear me?'
125    let test_response = 'Yes, I can.'
126    let vim_exe = exepath(v:progpath)
127    let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
128          \ . vim_exe
129	  \ . ' -u NONE -U NONE --noplugin --not-a-term -c ''%s'''
130    " Ignore the "failed to create input context" error.
131    let cmd = 'call test_ignore_error("E285") | '
132	  \ . 'gui -f | '
133	  \ . 'call feedkeys("'
134          \ . '\"+p'
135          \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
136          \ . '\"+yis'
137          \ . ':q!\<CR>", "tx")'
138    let run_vimtest = printf(testee, cmd)
139
140    " Set the quoteplus register to test_call, and another gvim will launched.
141    " Then, it first tries to paste the content of its own quotedplus register
142    " onto it.  Second, it tries to substitute test_response for the pasted
143    " sentence.  If the sentence is identical to test_call, the substitution
144    " should succeed.  Third, it tries to yank the result of the substitution
145    " to its own quoteplus register, and last it quits.  When system()
146    " returns, the content of the quoteplus register should be identical to
147    " test_response if those quoteplus registers are synchronized properly
148    " with/through the X11 clipboard.
149    let @+ = test_call
150    call system(run_vimtest)
151    call assert_equal(test_response, @+)
152
153    let @+ = quoteplus_saved
154  endif
155
156  if !empty(skipped)
157    throw skipped
158  endif
159endfunc
160
161func Test_set_background()
162  let background_saved = &background
163
164  set background&
165  call assert_equal('light', &background)
166
167  set background=dark
168  call assert_equal('dark', &background)
169
170  let &background = background_saved
171endfunc
172
173func Test_set_balloondelay()
174  if !exists('+balloondelay')
175    return
176  endif
177
178  let balloondelay_saved = &balloondelay
179
180  " Check if the default value is identical to that described in the manual.
181  set balloondelay&
182  call assert_equal(600, &balloondelay)
183
184  " Edge cases
185
186  " XXX This fact should be hidden so that people won't be tempted to write
187  " plugin/TimeMachine.vim.  TODO Add reasonable range checks to the source
188  " code.
189  set balloondelay=-1
190  call assert_equal(-1, &balloondelay)
191
192  " Though it's possible to interpret the zero delay to be 'as soon as
193  " possible' or even 'indefinite', its actual meaning depends on the GUI
194  " toolkit in use after all.
195  set balloondelay=0
196  call assert_equal(0, &balloondelay)
197
198  set balloondelay=1
199  call assert_equal(1, &balloondelay)
200
201  " Since p_bdelay is of type long currently, the upper bound can be
202  " impractically huge and machine-dependent.  Practically, it's sufficient
203  " to check if balloondelay works with 0x7fffffff (32 bits) for now.
204  set balloondelay=2147483647
205  call assert_equal(2147483647, &balloondelay)
206
207  let &balloondelay = balloondelay_saved
208endfunc
209
210func Test_set_ballooneval()
211  if !exists('+ballooneval')
212    return
213  endif
214
215  let ballooneval_saved = &ballooneval
216
217  set ballooneval&
218  call assert_equal(0, &ballooneval)
219
220  set ballooneval
221  call assert_notequal(0, &ballooneval)
222
223  set noballooneval
224  call assert_equal(0, &ballooneval)
225
226  let &ballooneval = ballooneval_saved
227endfunc
228
229func Test_set_balloonexpr()
230  if !exists('+balloonexpr')
231    return
232  endif
233
234  let balloonexpr_saved = &balloonexpr
235
236  " Default value
237  set balloonexpr&
238  call assert_equal('', &balloonexpr)
239
240  " User-defined function
241  new
242  func MyBalloonExpr()
243      return 'Cursor is at line ' . v:beval_lnum .
244	      \', column ' . v:beval_col .
245	      \ ' of file ' .  bufname(v:beval_bufnr) .
246	      \ ' on word "' . v:beval_text . '"' .
247	      \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
248  endfunc
249  setl balloonexpr=MyBalloonExpr()
250  setl ballooneval
251  call assert_equal('MyBalloonExpr()', &balloonexpr)
252  " TODO Read non-empty text, place the pointer at a character of a word,
253  " and check if the content of the balloon is the same as what is expected.
254  " Also, check if textlock works as expected.
255  setl balloonexpr&
256  call assert_equal('', &balloonexpr)
257  delfunc MyBalloonExpr
258  bwipe!
259
260  " Multiline support
261  if has('balloon_multiline')
262    " Multiline balloon using NL
263    new
264    func MyBalloonFuncForMultilineUsingNL()
265      return "Multiline\nSuppported\nBalloon\nusing NL"
266    endfunc
267    setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
268    setl ballooneval
269    call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
270    " TODO Read non-empty text, place the pointer at a character of a word,
271    " and check if the content of the balloon is the same as what is
272    " expected.  Also, check if textlock works as expected.
273    setl balloonexpr&
274    delfunc MyBalloonFuncForMultilineUsingNL
275    bwipe!
276
277    " Multiline balloon using List
278    new
279    func MyBalloonFuncForMultilineUsingList()
280      return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
281    endfunc
282    setl balloonexpr=MyBalloonFuncForMultilineUsingList()
283    setl ballooneval
284    call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
285    " TODO Read non-empty text, place the pointer at a character of a word,
286    " and check if the content of the balloon is the same as what is
287    " expected.  Also, check if textlock works as expected.
288    setl balloonexpr&
289    delfunc MyBalloonFuncForMultilineUsingList
290    bwipe!
291  endif
292
293  let &balloonexpr = balloonexpr_saved
294endfunc
295
296" Invalid arguments are tested with test_options in conjunction with segfaults
297" caused by them (Patch 8.0.0357, 24922ec233).
298func Test_set_guicursor()
299  let guicursor_saved = &guicursor
300
301  let default = [
302        \ "n-v-c:block-Cursor/lCursor",
303        \ "ve:ver35-Cursor",
304        \ "o:hor50-Cursor",
305        \ "i-ci:ver25-Cursor/lCursor",
306        \ "r-cr:hor20-Cursor/lCursor",
307        \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
308        \ ]
309
310  " Default Value
311  set guicursor&
312  call assert_equal(join(default, ','), &guicursor)
313
314  " Argument List Example 1
315  let opt_list = copy(default)
316  let opt_list[0] = "n-c-v:block-nCursor"
317  exec "set guicursor=" . join(opt_list, ',')
318  call assert_equal(join(opt_list, ','), &guicursor)
319  unlet opt_list
320
321  " Argument List Example 2
322  let opt_list = copy(default)
323  let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
324  exec "set guicursor=" . join(opt_list, ',')
325  call assert_equal(join(opt_list, ','), &guicursor)
326  unlet opt_list
327
328  " 'a' Mode
329  set guicursor&
330  let &guicursor .= ',a:blinkon0'
331  call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
332
333  let &guicursor = guicursor_saved
334endfunc
335
336func Test_set_guifont()
337  let skipped = ''
338
339  let guifont_saved = &guifont
340  if has('xfontset')
341    " Prevent 'guifontset' from canceling 'guifont'.
342    let guifontset_saved = &guifontset
343    set guifontset=
344  endif
345
346  if !g:x11_based_gui
347    let skipped = g:not_implemented
348  elseif has('gui_athena') || has('gui_motif')
349    " Non-empty font list with invalid font names.
350    "
351    " This test is twofold: (1) It checks if the command fails as expected
352    " when there are no loadable fonts found in the list. (2) It checks if
353    " 'guifont' remains the same after the command loads none of the fonts
354    " listed.
355    let flist = &guifont
356    call assert_fails('set guifont=-notexist1-*,-notexist2-*')
357    call assert_equal(flist, &guifont)
358
359    " Non-empty font list with a valid font name.  Should pick up the first
360    " valid font.
361    set guifont=-notexist1-*,fixed,-notexist2-*
362    let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
363    call assert_match(pat, getfontname())
364
365    " Empty list. Should fallback to the built-in default.
366    set guifont=
367    let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
368    call assert_match(pat, getfontname())
369
370  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
371    " For GTK, what we refer to as 'font names' in our manual are actually
372    " 'initial font patterns'.  A valid font which matches the 'canonical font
373    " pattern' constructed from a given 'initial pattern' is to be looked up
374    " and loaded.  That explains why the GTK GUIs appear to accept 'invalid
375    " font names'.
376    "
377    " Non-empty list.  Should always pick up the first element, no matter how
378    " strange it is, as explained above.
379    set guifont=(´・ω・`)\ 12,Courier\ 12
380    call assert_equal('(´・ω・`) 12', getfontname())
381
382    " Empty list. Should fallback to the built-in default.
383    set guifont=
384    call assert_equal('Monospace 10', getfontname())
385  endif
386
387  if has('xfontset')
388    let &guifontset = guifontset_saved
389  endif
390  let &guifont = guifont_saved
391
392  if !empty(skipped)
393    throw skipped
394  endif
395endfunc
396
397func Test_set_guifontset()
398  let skipped = ''
399
400  if !has('xfontset')
401    let skipped = g:not_supported . 'xfontset'
402  else
403    let ctype_saved = v:ctype
404
405    " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
406    " be chosen meticulously.
407    let font_head = '-misc-fixed-medium-r-normal--14'
408
409    let font_aw70 = font_head . '-130-75-75-c-70'
410    let font_aw140 = font_head . '-130-75-75-c-140'
411
412    let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
413    let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
414
415    let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
416    let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
417    let singleton = font_head . '-*'
418    let aliases = 'k14,r14'
419
420    " Second, among 'locales', look up such a locale that gets 'set
421    " guifontset=' to work successfully with every fontset specified with
422    " 'fontsets'.
423    let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
424    let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
425
426    let feasible = 0
427    for locale in locales
428      try
429        exec 'language ctype' locale
430      catch /^Vim\%((\a\+)\)\=:E197/
431        continue
432      endtry
433      let done = 0
434      for fontset in fontsets
435        try
436          exec 'set guifontset=' . fontset
437        catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
438          break
439        endtry
440        let done += 1
441      endfor
442      if done == len(fontsets)
443        let feasible = 1
444        break
445      endif
446    endfor
447
448    " Third, give a set of tests if it is found feasible.
449    if !feasible
450      let skipped = g:not_hosted
451    else
452      " N.B. 'v:ctype' has already been set to an appropriate value in the
453      " previous loop.
454      for fontset in fontsets
455        exec 'set guifontset=' . fontset
456        call assert_equal(fontset, &guifontset)
457      endfor
458    endif
459
460    " Finally, restore ctype.
461    exec 'language ctype' ctype_saved
462  endif
463
464  if !empty(skipped)
465    throw skipped
466  endif
467endfunc
468
469func Test_set_guifontwide()
470  let skipped = ''
471
472  if !g:x11_based_gui
473    let skipped = g:not_implemented
474  elseif has('gui_gtk')
475    let guifont_saved = &guifont
476    let guifontwide_saved = &guifontwide
477
478    let fc_match = exepath('fc-match')
479    if empty(fc_match)
480      let skipped = g:not_hosted
481    else
482      let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
483      let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
484      exec 'set guifontwide=' . fnameescape(wide)
485      call assert_equal(wide, &guifontwide)
486    endif
487
488    let &guifontwide = guifontwide_saved
489    let &guifont = guifont_saved
490
491  elseif has('gui_athena') || has('gui_motif')
492    " guifontwide is premised upon the xfontset feature.
493    if !has('xfontset')
494      let skipped = g:not_supported . 'xfontset'
495    else
496      let encoding_saved    = &encoding
497      let guifont_saved     = &guifont
498      let guifontset_saved  = &guifontset
499      let guifontwide_saved = &guifontwide
500
501      let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
502      let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
503
504      set encoding=utf-8
505
506      " Case 1: guifontset is empty
507      set guifontset=
508
509      " Case 1-1: Automatic selection
510      set guifontwide=
511      exec 'set guifont=' . nfont
512      call assert_equal(wfont, &guifontwide)
513
514      " Case 1-2: Manual selection
515      exec 'set guifontwide=' . wfont
516      exec 'set guifont=' . nfont
517      call assert_equal(wfont, &guifontwide)
518
519      " Case 2: guifontset is invalid
520      try
521        set guifontset=-*-notexist-*
522        call assert_report("'set guifontset=-*-notexist-*' should have failed")
523      catch
524        call assert_exception('E598')
525      endtry
526      " Set it to an invalid value brutally for preparation.
527      let &guifontset = '-*-notexist-*'
528
529      " Case 2-1: Automatic selection
530      set guifontwide=
531      exec 'set guifont=' . nfont
532      call assert_equal(wfont, &guifontwide)
533
534      " Case 2-2: Manual selection
535      exec 'set guifontwide=' . wfont
536      exec 'set guifont=' . nfont
537      call assert_equal(wfont, &guifontwide)
538
539      let &guifontwide = guifontwide_saved
540      let &guifontset  = guifontset_saved
541      let &guifont     = guifont_saved
542      let &encoding    = encoding_saved
543    endif
544  endif
545
546  if !empty(skipped)
547    throw skipped
548  endif
549endfunc
550
551func Test_set_guiheadroom()
552  let skipped = ''
553
554  if !g:x11_based_gui
555    let skipped = g:not_supported . 'guiheadroom'
556  else
557    " Since this script is to be read together with '-U NONE', the default
558    " value must be preserved.
559    call assert_equal(50, &guiheadroom)
560  endif
561
562  if !empty(skipped)
563    throw skipped
564  endif
565endfunc
566
567func Test_set_guioptions()
568  let guioptions_saved = &guioptions
569  let duration = '200m'
570
571  if has('win32')
572    " Default Value
573    set guioptions&
574    call assert_equal('egmrLtT', &guioptions)
575
576  else
577    " Default Value
578    set guioptions&
579    call assert_equal('aegimrLtT', &guioptions)
580
581    " To activate scrollbars of type 'L' or 'R'.
582    wincmd v
583    redraw!
584
585    " Remove all default GUI ornaments
586    set guioptions-=T
587    exec 'sleep' . duration
588    call assert_equal('aegimrLt', &guioptions)
589    set guioptions-=t
590    exec 'sleep' . duration
591    call assert_equal('aegimrL', &guioptions)
592    set guioptions-=L
593    exec 'sleep' . duration
594    call assert_equal('aegimr', &guioptions)
595    set guioptions-=r
596    exec 'sleep' . duration
597    call assert_equal('aegim', &guioptions)
598    set guioptions-=m
599    exec 'sleep' . duration
600    call assert_equal('aegi', &guioptions)
601
602    " Try non-default GUI ornaments
603    set guioptions+=l
604    exec 'sleep' . duration
605    call assert_equal('aegil', &guioptions)
606    set guioptions-=l
607    exec 'sleep' . duration
608    call assert_equal('aegi', &guioptions)
609
610    set guioptions+=R
611    exec 'sleep' . duration
612    call assert_equal('aegiR', &guioptions)
613    set guioptions-=R
614    exec 'sleep' . duration
615    call assert_equal('aegi', &guioptions)
616
617    set guioptions+=b
618    exec 'sleep' . duration
619    call assert_equal('aegib', &guioptions)
620    set guioptions+=h
621    exec 'sleep' . duration
622    call assert_equal('aegibh', &guioptions)
623    set guioptions-=h
624    exec 'sleep' . duration
625    call assert_equal('aegib', &guioptions)
626    set guioptions-=b
627    exec 'sleep' . duration
628    call assert_equal('aegi', &guioptions)
629
630    set guioptions+=v
631    exec 'sleep' . duration
632    call assert_equal('aegiv', &guioptions)
633    set guioptions-=v
634    exec 'sleep' . duration
635    call assert_equal('aegi', &guioptions)
636
637    if has('gui_motif')
638      set guioptions+=F
639      exec 'sleep' . duration
640      call assert_equal('aegiF', &guioptions)
641      set guioptions-=F
642      exec 'sleep' . duration
643      call assert_equal('aegi', &guioptions)
644    endif
645
646    " Restore GUI ornaments to the default state.
647    set guioptions+=m
648    exec 'sleep' . duration
649    call assert_equal('aegim', &guioptions)
650    set guioptions+=r
651    exec 'sleep' . duration
652    call assert_equal('aegimr', &guioptions)
653    set guioptions+=L
654    exec 'sleep' . duration
655    call assert_equal('aegimrL', &guioptions)
656    set guioptions+=t
657    exec 'sleep' . duration
658    call assert_equal('aegimrLt', &guioptions)
659    set guioptions+=T
660    exec 'sleep' . duration
661    call assert_equal("aegimrLtT", &guioptions)
662
663    wincmd o
664    redraw!
665  endif
666
667  let &guioptions = guioptions_saved
668endfunc
669
670func Test_scrollbars()
671  new
672  " buffer with 200 lines
673  call setline(1, repeat(['one', 'two'], 100))
674  set guioptions+=rlb
675
676  " scroll to move line 11 at top, moves the cursor there
677  call test_scrollbar('left', 10, 0)
678  redraw
679  call assert_equal(1, winline())
680  call assert_equal(11, line('.'))
681
682  " scroll to move line 1 at top, cursor stays in line 11
683  call test_scrollbar('right', 0, 0)
684  redraw
685  call assert_equal(11, winline())
686  call assert_equal(11, line('.'))
687
688  set nowrap
689  call setline(11, repeat('x', 150))
690  redraw
691  call assert_equal(1, wincol())
692  call assert_equal(1, col('.'))
693
694  " scroll to character 11, cursor is moved
695  call test_scrollbar('hor', 10, 0)
696  redraw
697  call assert_equal(1, wincol())
698  call assert_equal(11, col('.'))
699
700  set guioptions&
701  set wrap&
702  bwipe!
703endfunc
704
705func Test_set_guipty()
706  let guipty_saved = &guipty
707
708  " Default Value
709  set guipty&
710  call assert_equal(1, &guipty)
711
712  set noguipty
713  call assert_equal(0, &guipty)
714
715  let &guipty = guipty_saved
716endfunc
717
718func Test_shell_command()
719  new
720  r !echo hello
721  call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
722  bwipe!
723endfunc
724
725func Test_syntax_colortest()
726  runtime syntax/colortest.vim
727  redraw!
728  sleep 200m
729  bwipe!
730endfunc
731
732func Test_set_term()
733  " It's enough to check the current value since setting 'term' to anything
734  " other than builtin_gui makes no sense at all.
735  call assert_equal('builtin_gui', &term)
736endfunc
737
738func Test_windowid_variable()
739  if g:x11_based_gui || has('win32')
740    call assert_true(v:windowid > 0)
741  else
742    call assert_equal(0, v:windowid)
743  endif
744endfunc
745
746" Test "vim -g" and also the GUIEnter autocommand.
747func Test_gui_dash_g()
748  let cmd = GetVimCommand('Xscriptgui')
749  call writefile([""], "Xtestgui")
750  call writefile([
751	\ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
752	\ 'au GUIEnter * qall',
753	\ ], 'Xscriptgui')
754  call system(cmd . ' -g')
755  call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
756
757  call delete('Xscriptgui')
758  call delete('Xtestgui')
759endfunc
760
761" Test "vim -7" and also the GUIEnter autocommand.
762func Test_gui_dash_y()
763  let cmd = GetVimCommand('Xscriptgui')
764  call writefile([""], "Xtestgui")
765  call writefile([
766	\ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
767	\ 'au GUIEnter * qall',
768	\ ], 'Xscriptgui')
769  call system(cmd . ' -y')
770  call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
771
772  call delete('Xscriptgui')
773  call delete('Xtestgui')
774endfunc
775