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