xref: /vim-8.2.3635/src/testdir/test_gui.vim (revision 81ea1dfb)
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('win32')
392    " Invalid font names are accepted in GTK GUI
393    call assert_fails('set guifont=xa1bc23d7f', 'E596:')
394  endif
395
396  if has('xfontset')
397    let &guifontset = guifontset_saved
398  endif
399  let &guifont = guifont_saved
400
401  if !empty(skipped)
402    throw skipped
403  endif
404endfunc
405
406func Test_set_guifontset()
407  CheckFeature xfontset
408  let skipped = ''
409
410  call assert_fails('set guifontset=*', 'E597:')
411
412  let ctype_saved = v:ctype
413
414  " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
415  " be chosen meticulously.
416  let font_head = '-misc-fixed-medium-r-normal--14'
417
418  let font_aw70 = font_head . '-130-75-75-c-70'
419  let font_aw140 = font_head . '-130-75-75-c-140'
420
421  let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
422  let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
423
424  let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
425  let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
426  let singleton = font_head . '-*'
427  let aliases = 'k14,r14'
428
429  " Second, among 'locales', look up such a locale that gets 'set
430  " guifontset=' to work successfully with every fontset specified with
431  " 'fontsets'.
432  let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
433  let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
434
435  let feasible = 0
436  for locale in locales
437    try
438      exec 'language ctype' locale
439    catch /^Vim\%((\a\+)\)\=:E197/
440      continue
441    endtry
442    let done = 0
443    for fontset in fontsets
444      try
445	exec 'set guifontset=' . fontset
446      catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
447	break
448      endtry
449      let done += 1
450    endfor
451    if done == len(fontsets)
452      let feasible = 1
453      break
454    endif
455  endfor
456
457  " Third, give a set of tests if it is found feasible.
458  if !feasible
459    let skipped = g:not_hosted
460  else
461    " N.B. 'v:ctype' has already been set to an appropriate value in the
462    " previous loop.
463    for fontset in fontsets
464      exec 'set guifontset=' . fontset
465      call assert_equal(fontset, &guifontset)
466    endfor
467  endif
468
469  " Finally, restore ctype.
470  exec 'language ctype' ctype_saved
471
472  if !empty(skipped)
473    throw skipped
474  endif
475endfunc
476
477func Test_set_guifontwide()
478  call assert_fails('set guifontwide=*', 'E533:')
479  let skipped = ''
480
481  if !g:x11_based_gui
482    let skipped = g:not_implemented
483  elseif has('gui_gtk')
484    let guifont_saved = &guifont
485    let guifontwide_saved = &guifontwide
486
487    let fc_match = exepath('fc-match')
488    if empty(fc_match)
489      let skipped = g:not_hosted
490    else
491      let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
492      let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
493      exec 'set guifontwide=' . fnameescape(wide)
494      call assert_equal(wide, &guifontwide)
495    endif
496
497    let &guifontwide = guifontwide_saved
498    let &guifont = guifont_saved
499
500  elseif has('gui_athena') || has('gui_motif')
501    " guifontwide is premised upon the xfontset feature.
502    if !has('xfontset')
503      let skipped = g:not_supported . 'xfontset'
504    else
505      let encoding_saved    = &encoding
506      let guifont_saved     = &guifont
507      let guifontset_saved  = &guifontset
508      let guifontwide_saved = &guifontwide
509
510      let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
511      let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
512
513      set encoding=utf-8
514
515      " Case 1: guifontset is empty
516      set guifontset=
517
518      " Case 1-1: Automatic selection
519      set guifontwide=
520      exec 'set guifont=' . nfont
521      call assert_equal(wfont, &guifontwide)
522
523      " Case 1-2: Manual selection
524      exec 'set guifontwide=' . wfont
525      exec 'set guifont=' . nfont
526      call assert_equal(wfont, &guifontwide)
527
528      " Case 2: guifontset is invalid
529      try
530        set guifontset=-*-notexist-*
531        call assert_report("'set guifontset=-*-notexist-*' should have failed")
532      catch
533        call assert_exception('E598')
534      endtry
535      " Set it to an invalid value brutally for preparation.
536      let &guifontset = '-*-notexist-*'
537
538      " Case 2-1: Automatic selection
539      set guifontwide=
540      exec 'set guifont=' . nfont
541      call assert_equal(wfont, &guifontwide)
542
543      " Case 2-2: Manual selection
544      exec 'set guifontwide=' . wfont
545      exec 'set guifont=' . nfont
546      call assert_equal(wfont, &guifontwide)
547
548      let &guifontwide = guifontwide_saved
549      let &guifontset  = guifontset_saved
550      let &guifont     = guifont_saved
551      let &encoding    = encoding_saved
552    endif
553  endif
554
555  if !empty(skipped)
556    throw skipped
557  endif
558endfunc
559
560func Test_set_guiheadroom()
561  let skipped = ''
562
563  if !g:x11_based_gui
564    let skipped = g:not_supported . 'guiheadroom'
565  else
566    " Since this script is to be read together with '-U NONE', the default
567    " value must be preserved.
568    call assert_equal(50, &guiheadroom)
569  endif
570
571  if !empty(skipped)
572    throw skipped
573  endif
574endfunc
575
576func Test_set_guioptions()
577  let guioptions_saved = &guioptions
578  let duration = '200m'
579
580  if has('win32')
581    " Default Value
582    set guioptions&
583    call assert_equal('egmrLtT', &guioptions)
584
585  else
586    " Default Value
587    set guioptions&
588    call assert_equal('aegimrLtT', &guioptions)
589
590    " To activate scrollbars of type 'L' or 'R'.
591    wincmd v
592    redraw!
593
594    " Remove all default GUI ornaments
595    set guioptions-=T
596    exec 'sleep' . duration
597    call assert_equal('aegimrLt', &guioptions)
598    set guioptions-=t
599    exec 'sleep' . duration
600    call assert_equal('aegimrL', &guioptions)
601    set guioptions-=L
602    exec 'sleep' . duration
603    call assert_equal('aegimr', &guioptions)
604    set guioptions-=r
605    exec 'sleep' . duration
606    call assert_equal('aegim', &guioptions)
607    set guioptions-=m
608    exec 'sleep' . duration
609    call assert_equal('aegi', &guioptions)
610
611    " Try non-default GUI ornaments
612    set guioptions+=l
613    exec 'sleep' . duration
614    call assert_equal('aegil', &guioptions)
615    set guioptions-=l
616    exec 'sleep' . duration
617    call assert_equal('aegi', &guioptions)
618
619    set guioptions+=R
620    exec 'sleep' . duration
621    call assert_equal('aegiR', &guioptions)
622    set guioptions-=R
623    exec 'sleep' . duration
624    call assert_equal('aegi', &guioptions)
625
626    set guioptions+=b
627    exec 'sleep' . duration
628    call assert_equal('aegib', &guioptions)
629    set guioptions+=h
630    exec 'sleep' . duration
631    call assert_equal('aegibh', &guioptions)
632    set guioptions-=h
633    exec 'sleep' . duration
634    call assert_equal('aegib', &guioptions)
635    set guioptions-=b
636    exec 'sleep' . duration
637    call assert_equal('aegi', &guioptions)
638
639    set guioptions+=v
640    exec 'sleep' . duration
641    call assert_equal('aegiv', &guioptions)
642    set guioptions-=v
643    exec 'sleep' . duration
644    call assert_equal('aegi', &guioptions)
645
646    if has('gui_motif')
647      set guioptions+=F
648      exec 'sleep' . duration
649      call assert_equal('aegiF', &guioptions)
650      set guioptions-=F
651      exec 'sleep' . duration
652      call assert_equal('aegi', &guioptions)
653    endif
654
655    if has('gui_gtk3')
656      set guioptions+=d
657      exec 'sleep' . duration
658      call assert_equal('aegid', &guioptions)
659      set guioptions-=d
660      exec 'sleep' . duration
661      call assert_equal('aegi', &guioptions)
662    endif
663
664    " Restore GUI ornaments to the default state.
665    set guioptions+=m
666    exec 'sleep' . duration
667    call assert_equal('aegim', &guioptions)
668    set guioptions+=r
669    exec 'sleep' . duration
670    call assert_equal('aegimr', &guioptions)
671    set guioptions+=L
672    exec 'sleep' . duration
673    call assert_equal('aegimrL', &guioptions)
674    set guioptions+=t
675    exec 'sleep' . duration
676    call assert_equal('aegimrLt', &guioptions)
677    set guioptions+=T
678    exec 'sleep' . duration
679    call assert_equal("aegimrLtT", &guioptions)
680
681    wincmd o
682    redraw!
683  endif
684
685  let &guioptions = guioptions_saved
686endfunc
687
688func Test_scrollbars()
689  new
690  " buffer with 200 lines
691  call setline(1, repeat(['one', 'two'], 100))
692  set guioptions+=rlb
693
694  " scroll to move line 11 at top, moves the cursor there
695  eval 10->test_scrollbar('left', 0)
696  redraw
697  call assert_equal(1, winline())
698  call assert_equal(11, line('.'))
699
700  " scroll to move line 1 at top, cursor stays in line 11
701  call test_scrollbar('right', 0, 0)
702  redraw
703  call assert_equal(11, winline())
704  call assert_equal(11, line('.'))
705
706  set nowrap
707  call setline(11, repeat('x', 150))
708  redraw
709  call assert_equal(1, wincol())
710  set number
711  redraw
712  call assert_equal(5, wincol())
713  set nonumber
714  redraw
715  call assert_equal(1, col('.'))
716
717  " scroll to character 11, cursor is moved
718  call test_scrollbar('hor', 10, 0)
719  redraw
720  call assert_equal(1, wincol())
721  set number
722  redraw
723  call assert_equal(5, wincol())
724  set nonumber
725  redraw
726  call assert_equal(11, col('.'))
727
728  set guioptions&
729  set wrap&
730  bwipe!
731endfunc
732
733func Test_menu()
734  CheckFeature quickfix
735
736  " Check Help menu exists
737  let help_menu = execute('menu Help')
738  call assert_match('Overview', help_menu)
739
740  " Check Help menu works
741  emenu Help.Overview
742  call assert_equal('help', &buftype)
743  close
744
745  " Check deleting menu doesn't cause trouble.
746  aunmenu Help
747  call assert_fails('menu Help', 'E329:')
748endfunc
749
750func Test_set_guipty()
751  let guipty_saved = &guipty
752
753  " Default Value
754  set guipty&
755  call assert_equal(1, &guipty)
756
757  set noguipty
758  call assert_equal(0, &guipty)
759
760  let &guipty = guipty_saved
761endfunc
762
763func Test_encoding_conversion()
764  " GTK supports conversion between 'encoding' and "utf-8"
765  if has('gui_gtk')
766    let encoding_saved = &encoding
767    set encoding=latin1
768
769    " would be nice if we could take a screenshot
770    intro
771    " sets the window title
772    edit SomeFile
773
774    let &encoding = encoding_saved
775  endif
776endfunc
777
778func Test_shell_command()
779  new
780  r !echo hello
781  call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
782  bwipe!
783endfunc
784
785func Test_syntax_colortest()
786  runtime syntax/colortest.vim
787  redraw!
788  sleep 200m
789  bwipe!
790endfunc
791
792func Test_set_term()
793  " It's enough to check the current value since setting 'term' to anything
794  " other than builtin_gui makes no sense at all.
795  call assert_equal('builtin_gui', &term)
796  call assert_fails('set term=xterm', 'E530:')
797endfunc
798
799func Test_windowid_variable()
800  if g:x11_based_gui || has('win32')
801    call assert_true(v:windowid > 0)
802  else
803    call assert_equal(0, v:windowid)
804  endif
805endfunc
806
807" Test "vim -g" and also the GUIEnter autocommand.
808func Test_gui_dash_g()
809  let cmd = GetVimCommand('Xscriptgui')
810  call writefile([""], "Xtestgui")
811  let lines =<< trim END
812	au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
813	au GUIEnter * qall
814  END
815  call writefile(lines, 'Xscriptgui')
816  call system(cmd . ' -g')
817  call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
818
819  call delete('Xscriptgui')
820  call delete('Xtestgui')
821endfunc
822
823" Test "vim -7" and also the GUIEnter autocommand.
824func Test_gui_dash_y()
825  let cmd = GetVimCommand('Xscriptgui')
826  call writefile([""], "Xtestgui")
827  let lines =<< trim END
828	au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
829	au GUIEnter * qall
830  END
831  call writefile(lines, 'Xscriptgui')
832  call system(cmd . ' -y')
833  call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
834
835  call delete('Xscriptgui')
836  call delete('Xtestgui')
837endfunc
838
839" vim: shiftwidth=2 sts=2 expandtab
840