xref: /vim-8.2.3635/src/testdir/test_gui.vim (revision 30e8e735)
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
79    " Valid font name. This is usually the real name of Monospace by default.
80    let fname = 'Bitstream Vera Sans Mono 12'
81    call assert_equal(fname, getfontname(fname))
82  endif
83
84  if !empty(skipped)
85    throw skipped
86  endif
87endfunc
88
89func Test_getfontname_without_arg()
90  let skipped = ''
91
92  let fname = getfontname()
93
94  if !g:x11_based_gui
95    let skipped = g:not_implemented
96  elseif has('gui_kde')
97    " 'expected' is the value specified by SetUp() above.
98    call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
99  elseif has('gui_athena') || has('gui_motif')
100    " 'expected' is DFLT_FONT of gui_x11.c or its real name.
101    let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
102    call assert_match(pat, fname)
103  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
104    " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
105    call assert_equal('Monospace 10', fname)
106  endif
107
108  if !empty(skipped)
109    throw skipped
110  endif
111endfunc
112
113func 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)
117  call assert_equal([getwinposx(), getwinposy()], getwinpos())
118endfunc
119
120func Test_quoteplus()
121  let skipped = ''
122
123  if !g:x11_based_gui
124    let skipped = g:not_supported . 'quoteplus'
125  else
126    let quoteplus_saved = @+
127
128    let test_call     = 'Can you hear me?'
129    let test_response = 'Yes, I can.'
130    let vim_exe = GetVimCommand()
131    let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
132          \ . vim_exe . ' --noplugin --not-a-term -c ''%s'''
133    " Ignore the "failed to create input context" error.
134    let cmd = 'call test_ignore_error("E285") | '
135	  \ . 'gui -f | '
136	  \ . 'call feedkeys("'
137          \ . '\"+p'
138          \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
139          \ . '\"+yis'
140          \ . ':q!\<CR>", "tx")'
141    let run_vimtest = printf(testee, cmd)
142
143    " Set the quoteplus register to test_call, and another gvim will launched.
144    " Then, it first tries to paste the content of its own quotedplus register
145    " onto it.  Second, it tries to substitute test_response for the pasted
146    " sentence.  If the sentence is identical to test_call, the substitution
147    " should succeed.  Third, it tries to yank the result of the substitution
148    " to its own quoteplus register, and last it quits.  When system()
149    " returns, the content of the quoteplus register should be identical to
150    " test_response if those quoteplus registers are synchronized properly
151    " with/through the X11 clipboard.
152    let @+ = test_call
153    call system(run_vimtest)
154    call assert_equal(test_response, @+)
155
156    let @+ = quoteplus_saved
157  endif
158
159  if !empty(skipped)
160    throw skipped
161  endif
162endfunc
163
164func Test_set_background()
165  let background_saved = &background
166
167  set background&
168  call assert_equal('light', &background)
169
170  set background=dark
171  call assert_equal('dark', &background)
172
173  let &background = background_saved
174endfunc
175
176func Test_set_balloondelay()
177  if !exists('+balloondelay')
178    return
179  endif
180
181  let balloondelay_saved = &balloondelay
182
183  " Check if the default value is identical to that described in the manual.
184  set balloondelay&
185  call assert_equal(600, &balloondelay)
186
187  " Edge cases
188
189  " XXX This fact should be hidden so that people won't be tempted to write
190  " plugin/TimeMachine.vim.  TODO Add reasonable range checks to the source
191  " code.
192  set balloondelay=-1
193  call assert_equal(-1, &balloondelay)
194
195  " Though it's possible to interpret the zero delay to be 'as soon as
196  " possible' or even 'indefinite', its actual meaning depends on the GUI
197  " toolkit in use after all.
198  set balloondelay=0
199  call assert_equal(0, &balloondelay)
200
201  set balloondelay=1
202  call assert_equal(1, &balloondelay)
203
204  " Since p_bdelay is of type long currently, the upper bound can be
205  " impractically huge and machine-dependent.  Practically, it's sufficient
206  " to check if balloondelay works with 0x7fffffff (32 bits) for now.
207  set balloondelay=2147483647
208  call assert_equal(2147483647, &balloondelay)
209
210  let &balloondelay = balloondelay_saved
211endfunc
212
213func Test_set_ballooneval()
214  if !exists('+ballooneval')
215    return
216  endif
217
218  let ballooneval_saved = &ballooneval
219
220  set ballooneval&
221  call assert_equal(0, &ballooneval)
222
223  set ballooneval
224  call assert_notequal(0, &ballooneval)
225
226  set noballooneval
227  call assert_equal(0, &ballooneval)
228
229  let &ballooneval = ballooneval_saved
230endfunc
231
232func Test_set_balloonexpr()
233  if !exists('+balloonexpr')
234    return
235  endif
236
237  let balloonexpr_saved = &balloonexpr
238
239  " Default value
240  set balloonexpr&
241  call assert_equal('', &balloonexpr)
242
243  " User-defined function
244  new
245  func MyBalloonExpr()
246      return 'Cursor is at line ' . v:beval_lnum .
247	      \', column ' . v:beval_col .
248	      \ ' of file ' .  bufname(v:beval_bufnr) .
249	      \ ' on word "' . v:beval_text . '"' .
250	      \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
251  endfunc
252  setl balloonexpr=MyBalloonExpr()
253  setl ballooneval
254  call assert_equal('MyBalloonExpr()', &balloonexpr)
255  " TODO Read non-empty text, place the pointer at a character of a word,
256  " and check if the content of the balloon is the same as what is expected.
257  " Also, check if textlock works as expected.
258  setl balloonexpr&
259  call assert_equal('', &balloonexpr)
260  delfunc MyBalloonExpr
261  bwipe!
262
263  " Multiline support
264  if has('balloon_multiline')
265    " Multiline balloon using NL
266    new
267    func MyBalloonFuncForMultilineUsingNL()
268      return "Multiline\nSuppported\nBalloon\nusing NL"
269    endfunc
270    setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
271    setl ballooneval
272    call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
273    " TODO Read non-empty text, place the pointer at a character of a word,
274    " and check if the content of the balloon is the same as what is
275    " expected.  Also, check if textlock works as expected.
276    setl balloonexpr&
277    delfunc MyBalloonFuncForMultilineUsingNL
278    bwipe!
279
280    " Multiline balloon using List
281    new
282    func MyBalloonFuncForMultilineUsingList()
283      return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
284    endfunc
285    setl balloonexpr=MyBalloonFuncForMultilineUsingList()
286    setl ballooneval
287    call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
288    " TODO Read non-empty text, place the pointer at a character of a word,
289    " and check if the content of the balloon is the same as what is
290    " expected.  Also, check if textlock works as expected.
291    setl balloonexpr&
292    delfunc MyBalloonFuncForMultilineUsingList
293    bwipe!
294  endif
295
296  let &balloonexpr = balloonexpr_saved
297endfunc
298
299" Invalid arguments are tested with test_options in conjunction with segfaults
300" caused by them (Patch 8.0.0357, 24922ec233).
301func Test_set_guicursor()
302  let guicursor_saved = &guicursor
303
304  let default = [
305        \ "n-v-c:block-Cursor/lCursor",
306        \ "ve:ver35-Cursor",
307        \ "o:hor50-Cursor",
308        \ "i-ci:ver25-Cursor/lCursor",
309        \ "r-cr:hor20-Cursor/lCursor",
310        \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
311        \ ]
312
313  " Default Value
314  set guicursor&
315  call assert_equal(join(default, ','), &guicursor)
316
317  " Argument List Example 1
318  let opt_list = copy(default)
319  let opt_list[0] = "n-c-v:block-nCursor"
320  exec "set guicursor=" . join(opt_list, ',')
321  call assert_equal(join(opt_list, ','), &guicursor)
322  unlet opt_list
323
324  " Argument List Example 2
325  let opt_list = copy(default)
326  let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
327  exec "set guicursor=" . join(opt_list, ',')
328  call assert_equal(join(opt_list, ','), &guicursor)
329  unlet opt_list
330
331  " 'a' Mode
332  set guicursor&
333  let &guicursor .= ',a:blinkon0'
334  call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
335
336  let &guicursor = guicursor_saved
337endfunc
338
339func Test_set_guifont()
340  let skipped = ''
341
342  let guifont_saved = &guifont
343  if has('xfontset')
344    " Prevent 'guifontset' from canceling 'guifont'.
345    let guifontset_saved = &guifontset
346    set guifontset=
347  endif
348
349  if !g:x11_based_gui
350    let skipped = g:not_implemented
351  elseif has('gui_athena') || has('gui_motif')
352    " Non-empty font list with invalid font names.
353    "
354    " This test is twofold: (1) It checks if the command fails as expected
355    " when there are no loadable fonts found in the list. (2) It checks if
356    " 'guifont' remains the same after the command loads none of the fonts
357    " listed.
358    let flist = &guifont
359    call assert_fails('set guifont=-notexist1-*,-notexist2-*')
360    call assert_equal(flist, &guifont)
361
362    " Non-empty font list with a valid font name.  Should pick up the first
363    " valid font.
364    set guifont=-notexist1-*,fixed,-notexist2-*
365    let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
366    call assert_match(pat, getfontname())
367
368    " Empty list. Should fallback to the built-in default.
369    set guifont=
370    let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
371    call assert_match(pat, getfontname())
372
373  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
374    " For GTK, what we refer to as 'font names' in our manual are actually
375    " 'initial font patterns'.  A valid font which matches the 'canonical font
376    " pattern' constructed from a given 'initial pattern' is to be looked up
377    " and loaded.  That explains why the GTK GUIs appear to accept 'invalid
378    " font names'.
379    "
380    " Non-empty list.  Should always pick up the first element, no matter how
381    " strange it is, as explained above.
382    set guifont=(´・ω・`)\ 12,Courier\ 12
383    call assert_equal('(´・ω・`) 12', getfontname())
384
385    " Empty list. Should fallback to the built-in default.
386    set guifont=
387    call assert_equal('Monospace 10', getfontname())
388  endif
389
390  if has('xfontset')
391    let &guifontset = guifontset_saved
392  endif
393  let &guifont = guifont_saved
394
395  if !empty(skipped)
396    throw skipped
397  endif
398endfunc
399
400func Test_set_guifontset()
401  CheckFeature xfontset
402  let skipped = ''
403
404  let ctype_saved = v:ctype
405
406  " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
407  " be chosen meticulously.
408  let font_head = '-misc-fixed-medium-r-normal--14'
409
410  let font_aw70 = font_head . '-130-75-75-c-70'
411  let font_aw140 = font_head . '-130-75-75-c-140'
412
413  let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
414  let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
415
416  let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
417  let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
418  let singleton = font_head . '-*'
419  let aliases = 'k14,r14'
420
421  " Second, among 'locales', look up such a locale that gets 'set
422  " guifontset=' to work successfully with every fontset specified with
423  " 'fontsets'.
424  let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
425  let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
426
427  let feasible = 0
428  for locale in locales
429    try
430      exec 'language ctype' locale
431    catch /^Vim\%((\a\+)\)\=:E197/
432      continue
433    endtry
434    let done = 0
435    for fontset in fontsets
436      try
437	exec 'set guifontset=' . fontset
438      catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
439	break
440      endtry
441      let done += 1
442    endfor
443    if done == len(fontsets)
444      let feasible = 1
445      break
446    endif
447  endfor
448
449  " Third, give a set of tests if it is found feasible.
450  if !feasible
451    let skipped = g:not_hosted
452  else
453    " N.B. 'v:ctype' has already been set to an appropriate value in the
454    " previous loop.
455    for fontset in fontsets
456      exec 'set guifontset=' . fontset
457      call assert_equal(fontset, &guifontset)
458    endfor
459  endif
460
461  " Finally, restore ctype.
462  exec 'language ctype' ctype_saved
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    if has('gui_gtk3')
647      set guioptions+=d
648      exec 'sleep' . duration
649      call assert_equal('aegid', &guioptions)
650      set guioptions-=d
651      exec 'sleep' . duration
652      call assert_equal('aegi', &guioptions)
653    endif
654
655    " Restore GUI ornaments to the default state.
656    set guioptions+=m
657    exec 'sleep' . duration
658    call assert_equal('aegim', &guioptions)
659    set guioptions+=r
660    exec 'sleep' . duration
661    call assert_equal('aegimr', &guioptions)
662    set guioptions+=L
663    exec 'sleep' . duration
664    call assert_equal('aegimrL', &guioptions)
665    set guioptions+=t
666    exec 'sleep' . duration
667    call assert_equal('aegimrLt', &guioptions)
668    set guioptions+=T
669    exec 'sleep' . duration
670    call assert_equal("aegimrLtT", &guioptions)
671
672    wincmd o
673    redraw!
674  endif
675
676  let &guioptions = guioptions_saved
677endfunc
678
679func Test_scrollbars()
680  new
681  " buffer with 200 lines
682  call setline(1, repeat(['one', 'two'], 100))
683  set guioptions+=rlb
684
685  " scroll to move line 11 at top, moves the cursor there
686  eval 10->test_scrollbar('left', 0)
687  redraw
688  call assert_equal(1, winline())
689  call assert_equal(11, line('.'))
690
691  " scroll to move line 1 at top, cursor stays in line 11
692  call test_scrollbar('right', 0, 0)
693  redraw
694  call assert_equal(11, winline())
695  call assert_equal(11, line('.'))
696
697  set nowrap
698  call setline(11, repeat('x', 150))
699  redraw
700  call assert_equal(1, wincol())
701  set number
702  redraw
703  call assert_equal(5, wincol())
704  set nonumber
705  redraw
706  call assert_equal(1, col('.'))
707
708  " scroll to character 11, cursor is moved
709  call test_scrollbar('hor', 10, 0)
710  redraw
711  call assert_equal(1, wincol())
712  set number
713  redraw
714  call assert_equal(5, wincol())
715  set nonumber
716  redraw
717  call assert_equal(11, col('.'))
718
719  set guioptions&
720  set wrap&
721  bwipe!
722endfunc
723
724func Test_menu()
725  " Check Help menu exists
726  let help_menu = execute('menu Help')
727  call assert_match('Overview', help_menu)
728
729  " Check Help menu works
730  emenu Help.Overview
731  call assert_equal('help', &buftype)
732  close
733
734  " Check deleting menu doesn't cause trouble.
735  aunmenu Help
736  call assert_fails('menu Help', 'E329:')
737endfunc
738
739func Test_set_guipty()
740  let guipty_saved = &guipty
741
742  " Default Value
743  set guipty&
744  call assert_equal(1, &guipty)
745
746  set noguipty
747  call assert_equal(0, &guipty)
748
749  let &guipty = guipty_saved
750endfunc
751
752func Test_encoding_conversion()
753  " GTK supports conversion between 'encoding' and "utf-8"
754  if has('gui_gtk')
755    let encoding_saved = &encoding
756    set encoding=latin1
757
758    " would be nice if we could take a screenshot
759    intro
760    " sets the window title
761    edit SomeFile
762
763    let &encoding = encoding_saved
764  endif
765endfunc
766
767func Test_shell_command()
768  new
769  r !echo hello
770  call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
771  bwipe!
772endfunc
773
774func Test_syntax_colortest()
775  runtime syntax/colortest.vim
776  redraw!
777  sleep 200m
778  bwipe!
779endfunc
780
781func Test_set_term()
782  " It's enough to check the current value since setting 'term' to anything
783  " other than builtin_gui makes no sense at all.
784  call assert_equal('builtin_gui', &term)
785endfunc
786
787func Test_windowid_variable()
788  if g:x11_based_gui || has('win32')
789    call assert_true(v:windowid > 0)
790  else
791    call assert_equal(0, v:windowid)
792  endif
793endfunc
794
795" Test "vim -g" and also the GUIEnter autocommand.
796func Test_gui_dash_g()
797  let cmd = GetVimCommand('Xscriptgui')
798  call writefile([""], "Xtestgui")
799  let lines =<< trim END
800	au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
801	au GUIEnter * qall
802  END
803  call writefile(lines, 'Xscriptgui')
804  call system(cmd . ' -g')
805  call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
806
807  call delete('Xscriptgui')
808  call delete('Xtestgui')
809endfunc
810
811" Test "vim -7" and also the GUIEnter autocommand.
812func Test_gui_dash_y()
813  let cmd = GetVimCommand('Xscriptgui')
814  call writefile([""], "Xtestgui")
815  let lines =<< trim END
816	au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
817	au GUIEnter * qall
818  END
819  call writefile(lines, 'Xscriptgui')
820  call system(cmd . ' -y')
821  call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
822
823  call delete('Xscriptgui')
824  call delete('Xtestgui')
825endfunc
826