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