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