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