blob: 60e2bf412e33bb75cca1078fa1c4eb36074243c3 [file] [log] [blame]
Bram Moolenaar877e9572016-08-04 20:05:50 +02001" Tests specifically for the GUI
2
Bram Moolenaar9f0139a2017-08-13 20:26:20 +02003source shared.vim
4if !CanRunGui()
Bram Moolenaar877e9572016-08-04 20:05:50 +02005 finish
6endif
7
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01008source setup_gui.vim
Bram Moolenaar13c724f2017-02-05 20:54:26 +01009
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010010func Setup()
11 call GUISetUpCommon()
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020012endfunc
13
14func TearDown()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010015 call GUITearDownCommon()
Bram Moolenaar877e9572016-08-04 20:05:50 +020016endfunc
17
18" Test for resetting "secure" flag after GUI has started.
Bram Moolenaar5d7ead32018-02-27 17:17:42 +010019" Must be run first, since it starts the GUI on Unix.
Bram Moolenaar877e9572016-08-04 20:05:50 +020020func Test_1_set_secure()
21 set exrc secure
22 gui -f
23 call assert_equal(1, has('gui_running'))
24endfunc
25
Bram Moolenaard5841f22017-03-05 13:27:25 +010026" 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
Bram Moolenaar87748452017-03-12 17:10:33 +010034func Test_colorscheme()
35 let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
Bram Moolenaar60a68362018-04-30 15:40:48 +020036 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
Bram Moolenaar87748452017-03-12 17:10:33 +010042
43 colorscheme torte
44 redraw!
45 sleep 200m
46 call assert_equal('dark', &background)
Bram Moolenaar60a68362018-04-30 15:40:48 +020047 call assert_equal(1, g:before_colors)
48 call assert_equal(2, g:after_colors)
Bram Moolenaar87748452017-03-12 17:10:33 +010049
50 exec 'colorscheme' colorscheme_saved
Bram Moolenaar60a68362018-04-30 15:40:48 +020051 augroup TestColors
52 au!
53 augroup END
54 unlet g:color_count g:after_colors g:before_colors
Bram Moolenaar87748452017-03-12 17:10:33 +010055 redraw!
56endfunc
57
Bram Moolenaar6f785742017-02-06 22:11:55 +010058func Test_getfontname_with_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010059 let skipped = ''
60
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010061 if !g:x11_based_gui
62 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010063 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010064 " Invalid font name. The result should be an empty string.
65 call assert_equal('', getfontname('notexist'))
66
67 " Valid font name. This is usually the real name of 7x13 by default.
Bram Moolenaar87748452017-03-12 17:10:33 +010068 let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
69 call assert_match(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010070
71 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
72 " Invalid font name. The result should be the name plus the default size.
73 call assert_equal('notexist 10', getfontname('notexist'))
74
75 " Valid font name. This is usually the real name of Monospace by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010076 let fname = 'Bitstream Vera Sans Mono 12'
77 call assert_equal(fname, getfontname(fname))
78 endif
79
80 if !empty(skipped)
81 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010082 endif
83endfunc
84
85func Test_getfontname_without_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010086 let skipped = ''
87
88 let fname = getfontname()
89
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010090 if !g:x11_based_gui
91 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010092 elseif has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +010093 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010094 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +010095 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar87748452017-03-12 17:10:33 +010096 " 'expected' is DFLT_FONT of gui_x11.c or its real name.
97 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
98 call assert_match(pat, fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +010099 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
100 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100101 call assert_equal('Monospace 10', fname)
102 endif
103
104 if !empty(skipped)
105 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +0100106 endif
107endfunc
108
Bram Moolenaar87748452017-03-12 17:10:33 +0100109func Test_getwinpos()
110 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
111 call assert_true(getwinposx() >= 0)
112 call assert_true(getwinposy() >= 0)
113endfunc
114
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100115func Test_quoteplus()
116 let skipped = ''
117
118 if !g:x11_based_gui
119 let skipped = g:not_supported . 'quoteplus'
120 else
121 let quoteplus_saved = @+
122
123 let test_call = 'Can you hear me?'
124 let test_response = 'Yes, I can.'
125 let vim_exe = exepath(v:progpath)
126 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100127 \ . vim_exe
Bram Moolenaar24d76362017-03-04 13:32:10 +0100128 \ . ' -u NONE -U NONE --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100129 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100130 let cmd = 'call test_ignore_error("E285") | '
131 \ . 'gui -f | '
132 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100133 \ . '\"+p'
134 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
135 \ . '\"+yis'
136 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100137 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100138
139 " Set the quoteplus register to test_call, and another gvim will launched.
140 " Then, it first tries to paste the content of its own quotedplus register
141 " onto it. Second, it tries to substitute test_responce for the pasted
142 " sentence. If the sentence is identical to test_call, the substitution
143 " should succeed. Third, it tries to yank the result of the substitution
144 " to its own quoteplus register, and last it quits. When system()
145 " returns, the content of the quoteplus register should be identical to
146 " test_response if those quoteplus registers are synchronized properly
147 " with/through the X11 clipboard.
148 let @+ = test_call
149 call system(run_vimtest)
150 call assert_equal(test_response, @+)
151
152 let @+ = quoteplus_saved
153 endif
154
155 if !empty(skipped)
156 throw skipped
157 endif
158endfunc
159
Bram Moolenaar87748452017-03-12 17:10:33 +0100160func Test_set_background()
161 let background_saved = &background
162
163 set background&
164 call assert_equal('light', &background)
165
166 set background=dark
167 call assert_equal('dark', &background)
168
169 let &background = background_saved
170endfunc
171
Bram Moolenaard5841f22017-03-05 13:27:25 +0100172func Test_set_balloondelay()
173 if !exists('+balloondelay')
174 return
175 endif
176
177 let balloondelay_saved = &balloondelay
178
179 " Check if the default value is identical to that described in the manual.
180 set balloondelay&
181 call assert_equal(600, &balloondelay)
182
183 " Edge cases
184
185 " XXX This fact should be hidden so that people won't be tempted to write
186 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
187 " code.
188 set balloondelay=-1
189 call assert_equal(-1, &balloondelay)
190
191 " Though it's possible to interpret the zero delay to be 'as soon as
192 " possible' or even 'indefinite', its actual meaning depends on the GUI
193 " toolkit in use after all.
194 set balloondelay=0
195 call assert_equal(0, &balloondelay)
196
197 set balloondelay=1
198 call assert_equal(1, &balloondelay)
199
200 " Since p_bdelay is of type long currently, the upper bound can be
201 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100202 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
203 set balloondelay=2147483647
204 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100205
206 let &balloondelay = balloondelay_saved
207endfunc
208
209func Test_set_ballooneval()
210 if !exists('+ballooneval')
211 return
212 endif
213
214 let ballooneval_saved = &ballooneval
215
216 set ballooneval&
217 call assert_equal(0, &ballooneval)
218
219 set ballooneval
220 call assert_notequal(0, &ballooneval)
221
222 set noballooneval
223 call assert_equal(0, &ballooneval)
224
225 let &ballooneval = ballooneval_saved
226endfunc
227
228func Test_set_balloonexpr()
229 if !exists('+balloonexpr')
230 return
231 endif
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 smae 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 smae 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 smae 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
Bram Moolenaar87748452017-03-12 17:10:33 +0100295" 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
Bram Moolenaar43dded82017-02-09 16:06:17 +0100335func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100336 let skipped = ''
337
338 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100339 if has('xfontset')
340 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100341 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100342 set guifontset=
343 endif
344
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100345 if !g:x11_based_gui
346 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100347 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100348 " 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.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100354 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100355 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100356 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100357
358 " Non-empty font list with a valid font name. Should pick up the first
359 " valid font.
360 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100361 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
362 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100363
364 " Empty list. Should fallback to the built-in default.
365 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100366 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
367 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100368
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())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100384 endif
385
386 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100387 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100388 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100389 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100390
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100391 if !empty(skipped)
392 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100393 endif
394endfunc
395
Bram Moolenaar10434672017-02-12 19:59:08 +0100396func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100397 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100398
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100399 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100400 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100401 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100402 let ctype_saved = v:ctype
403
404 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
405 " be chosen meticulously.
406 let font_head = '-misc-fixed-medium-r-normal--14'
407
408 let font_aw70 = font_head . '-130-75-75-c-70'
409 let font_aw140 = font_head . '-130-75-75-c-140'
410
411 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
412 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
413
414 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
415 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
416 let singleton = font_head . '-*'
417 let aliases = 'k14,r14'
418
419 " Second, among 'locales', look up such a locale that gets 'set
420 " guifontset=' to work successfully with every fontset specified with
421 " 'fontsets'.
422 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
423 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
424
425 let feasible = 0
426 for locale in locales
427 try
428 exec 'language ctype' locale
429 catch /^Vim\%((\a\+)\)\=:E197/
430 continue
431 endtry
432 let done = 0
433 for fontset in fontsets
434 try
435 exec 'set guifontset=' . fontset
436 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
437 break
438 endtry
439 let done += 1
440 endfor
441 if done == len(fontsets)
442 let feasible = 1
443 break
444 endif
445 endfor
446
447 " Third, give a set of tests if it is found feasible.
448 if !feasible
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100449 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100450 else
451 " N.B. 'v:ctype' has already been set to an appropriate value in the
452 " previous loop.
453 for fontset in fontsets
454 exec 'set guifontset=' . fontset
455 call assert_equal(fontset, &guifontset)
456 endfor
457 endif
458
459 " Finally, restore ctype.
460 exec 'language ctype' ctype_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100461 endif
462
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100463 if !empty(skipped)
464 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100465 endif
466endfunc
467
468func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100469 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100470
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100471 if !g:x11_based_gui
472 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100473 elseif has('gui_gtk')
474 let guifont_saved = &guifont
475 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100476
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100477 let fc_match = exepath('fc-match')
478 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100479 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100480 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100481 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
482 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
483 exec 'set guifontwide=' . fnameescape(wide)
484 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100485 endif
486
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100487 let &guifontwide = guifontwide_saved
488 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100489
490 elseif has('gui_athena') || has('gui_motif')
491 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100492 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100493 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100494 else
495 let encoding_saved = &encoding
496 let guifont_saved = &guifont
497 let guifontset_saved = &guifontset
498 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100499
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100500 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
501 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100502
503 set encoding=utf-8
504
505 " Case 1: guifontset is empty
506 set guifontset=
507
508 " Case 1-1: Automatic selection
509 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100510 exec 'set guifont=' . nfont
511 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100512
513 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100514 exec 'set guifontwide=' . wfont
515 exec 'set guifont=' . nfont
516 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100517
518 " Case 2: guifontset is invalid
519 try
520 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100521 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100522 catch
523 call assert_exception('E598')
524 endtry
525 " Set it to an invalid value brutally for preparation.
526 let &guifontset = '-*-notexist-*'
527
528 " Case 2-1: Automatic selection
529 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100530 exec 'set guifont=' . nfont
531 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100532
533 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100534 exec 'set guifontwide=' . wfont
535 exec 'set guifont=' . nfont
536 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100537
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100538 let &guifontwide = guifontwide_saved
539 let &guifontset = guifontset_saved
540 let &guifont = guifont_saved
541 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100542 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100543 endif
544
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100545 if !empty(skipped)
546 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100547 endif
548endfunc
549
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100550func Test_set_guiheadroom()
551 let skipped = ''
552
553 if !g:x11_based_gui
554 let skipped = g:not_supported . 'guiheadroom'
555 else
556 " Since this script is to be read together with '-U NONE', the default
557 " value must be preserved.
558 call assert_equal(50, &guiheadroom)
559 endif
560
561 if !empty(skipped)
562 throw skipped
563 endif
564endfunc
565
Bram Moolenaar87748452017-03-12 17:10:33 +0100566func Test_set_guioptions()
567 let guioptions_saved = &guioptions
568 let duration = '200m'
569
570 if has('win32')
571 " Default Value
572 set guioptions&
573 call assert_equal('egmrLtT', &guioptions)
574
575 else
576 " Default Value
577 set guioptions&
578 call assert_equal('aegimrLtT', &guioptions)
579
580 " To activate scrollbars of type 'L' or 'R'.
581 wincmd v
582 redraw!
583
584 " Remove all default GUI ornaments
585 set guioptions-=T
586 exec 'sleep' . duration
587 call assert_equal('aegimrLt', &guioptions)
588 set guioptions-=t
589 exec 'sleep' . duration
590 call assert_equal('aegimrL', &guioptions)
591 set guioptions-=L
592 exec 'sleep' . duration
593 call assert_equal('aegimr', &guioptions)
594 set guioptions-=r
595 exec 'sleep' . duration
596 call assert_equal('aegim', &guioptions)
597 set guioptions-=m
598 exec 'sleep' . duration
599 call assert_equal('aegi', &guioptions)
600
601 " Try non-default GUI ornaments
602 set guioptions+=l
603 exec 'sleep' . duration
604 call assert_equal('aegil', &guioptions)
605 set guioptions-=l
606 exec 'sleep' . duration
607 call assert_equal('aegi', &guioptions)
608
609 set guioptions+=R
610 exec 'sleep' . duration
611 call assert_equal('aegiR', &guioptions)
612 set guioptions-=R
613 exec 'sleep' . duration
614 call assert_equal('aegi', &guioptions)
615
616 set guioptions+=b
617 exec 'sleep' . duration
618 call assert_equal('aegib', &guioptions)
619 set guioptions+=h
620 exec 'sleep' . duration
621 call assert_equal('aegibh', &guioptions)
622 set guioptions-=h
623 exec 'sleep' . duration
624 call assert_equal('aegib', &guioptions)
625 set guioptions-=b
626 exec 'sleep' . duration
627 call assert_equal('aegi', &guioptions)
628
629 set guioptions+=v
630 exec 'sleep' . duration
631 call assert_equal('aegiv', &guioptions)
632 set guioptions-=v
633 exec 'sleep' . duration
634 call assert_equal('aegi', &guioptions)
635
636 if has('gui_motif')
637 set guioptions+=F
638 exec 'sleep' . duration
639 call assert_equal('aegiF', &guioptions)
640 set guioptions-=F
641 exec 'sleep' . duration
642 call assert_equal('aegi', &guioptions)
643 endif
644
645 " Restore GUI ornaments to the default state.
646 set guioptions+=m
647 exec 'sleep' . duration
648 call assert_equal('aegim', &guioptions)
649 set guioptions+=r
650 exec 'sleep' . duration
651 call assert_equal('aegimr', &guioptions)
652 set guioptions+=L
653 exec 'sleep' . duration
654 call assert_equal('aegimrL', &guioptions)
655 set guioptions+=t
656 exec 'sleep' . duration
657 call assert_equal('aegimrLt', &guioptions)
658 set guioptions+=T
659 exec 'sleep' . duration
660 call assert_equal("aegimrLtT", &guioptions)
661
662 wincmd o
663 redraw!
664 endif
665
666 let &guioptions = guioptions_saved
667endfunc
668
669func Test_set_guipty()
670 let guipty_saved = &guipty
671
672 " Default Value
673 set guipty&
674 call assert_equal(1, &guipty)
675
676 set noguipty
677 call assert_equal(0, &guipty)
678
679 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100680endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100681
Bram Moolenaar877e9572016-08-04 20:05:50 +0200682func Test_shell_command()
683 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200684 r !echo hello
685 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200686 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200687endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100688
Bram Moolenaar87748452017-03-12 17:10:33 +0100689func Test_syntax_colortest()
690 runtime syntax/colortest.vim
691 redraw!
692 sleep 200m
693 bwipe!
694endfunc
695
696func Test_set_term()
697 " It's enough to check the current value since setting 'term' to anything
698 " other than builtin_gui makes no sense at all.
699 call assert_equal('builtin_gui', &term)
700endfunc
701
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100702func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100703 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100704 call assert_true(v:windowid > 0)
705 else
706 call assert_equal(0, v:windowid)
707 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100708endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200709
710" Test "vim -g" and also the GUIEnter autocommand.
711func Test_gui_dash_g()
712 let cmd = GetVimCommand('Xscriptgui')
713 call writefile([""], "Xtestgui")
714 call writefile([
715 \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
716 \ 'au GUIEnter * qall',
717 \ ], 'Xscriptgui')
718 call system(cmd . ' -g')
719 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
720
721 call delete('Xscriptgui')
722 call delete('Xtestgui')
723endfunc
724
725" Test "vim -7" and also the GUIEnter autocommand.
726func Test_gui_dash_y()
727 let cmd = GetVimCommand('Xscriptgui')
728 call writefile([""], "Xtestgui")
729 call writefile([
730 \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
731 \ 'au GUIEnter * qall',
732 \ ], 'Xscriptgui')
733 call system(cmd . ' -y')
734 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
735
736 call delete('Xscriptgui')
737 call delete('Xtestgui')
738endfunc