blob: 0775b178fb79ee8a2044d614e4d796e8ea75f5fc [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)
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200113 call assert_equal([getwinposx(), getwinposy()], getwinpos())
Bram Moolenaar87748452017-03-12 17:10:33 +0100114endfunc
115
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100116func Test_quoteplus()
117 let skipped = ''
118
119 if !g:x11_based_gui
120 let skipped = g:not_supported . 'quoteplus'
121 else
122 let quoteplus_saved = @+
123
124 let test_call = 'Can you hear me?'
125 let test_response = 'Yes, I can.'
126 let vim_exe = exepath(v:progpath)
127 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100128 \ . vim_exe
Bram Moolenaar24d76362017-03-04 13:32:10 +0100129 \ . ' -u NONE -U NONE --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100130 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100131 let cmd = 'call test_ignore_error("E285") | '
132 \ . 'gui -f | '
133 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100134 \ . '\"+p'
135 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
136 \ . '\"+yis'
137 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100138 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100139
140 " Set the quoteplus register to test_call, and another gvim will launched.
141 " Then, it first tries to paste the content of its own quotedplus register
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200142 " onto it. Second, it tries to substitute test_response for the pasted
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100143 " sentence. If the sentence is identical to test_call, the substitution
144 " should succeed. Third, it tries to yank the result of the substitution
145 " to its own quoteplus register, and last it quits. When system()
146 " returns, the content of the quoteplus register should be identical to
147 " test_response if those quoteplus registers are synchronized properly
148 " with/through the X11 clipboard.
149 let @+ = test_call
150 call system(run_vimtest)
151 call assert_equal(test_response, @+)
152
153 let @+ = quoteplus_saved
154 endif
155
156 if !empty(skipped)
157 throw skipped
158 endif
159endfunc
160
Bram Moolenaar87748452017-03-12 17:10:33 +0100161func Test_set_background()
162 let background_saved = &background
163
164 set background&
165 call assert_equal('light', &background)
166
167 set background=dark
168 call assert_equal('dark', &background)
169
170 let &background = background_saved
171endfunc
172
Bram Moolenaard5841f22017-03-05 13:27:25 +0100173func Test_set_balloondelay()
174 if !exists('+balloondelay')
175 return
176 endif
177
178 let balloondelay_saved = &balloondelay
179
180 " Check if the default value is identical to that described in the manual.
181 set balloondelay&
182 call assert_equal(600, &balloondelay)
183
184 " Edge cases
185
186 " XXX This fact should be hidden so that people won't be tempted to write
187 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
188 " code.
189 set balloondelay=-1
190 call assert_equal(-1, &balloondelay)
191
192 " Though it's possible to interpret the zero delay to be 'as soon as
193 " possible' or even 'indefinite', its actual meaning depends on the GUI
194 " toolkit in use after all.
195 set balloondelay=0
196 call assert_equal(0, &balloondelay)
197
198 set balloondelay=1
199 call assert_equal(1, &balloondelay)
200
201 " Since p_bdelay is of type long currently, the upper bound can be
202 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100203 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
204 set balloondelay=2147483647
205 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100206
207 let &balloondelay = balloondelay_saved
208endfunc
209
210func Test_set_ballooneval()
211 if !exists('+ballooneval')
212 return
213 endif
214
215 let ballooneval_saved = &ballooneval
216
217 set ballooneval&
218 call assert_equal(0, &ballooneval)
219
220 set ballooneval
221 call assert_notequal(0, &ballooneval)
222
223 set noballooneval
224 call assert_equal(0, &ballooneval)
225
226 let &ballooneval = ballooneval_saved
227endfunc
228
229func Test_set_balloonexpr()
230 if !exists('+balloonexpr')
231 return
232 endif
233
234 let balloonexpr_saved = &balloonexpr
235
236 " Default value
237 set balloonexpr&
238 call assert_equal('', &balloonexpr)
239
240 " User-defined function
241 new
242 func MyBalloonExpr()
243 return 'Cursor is at line ' . v:beval_lnum .
244 \', column ' . v:beval_col .
245 \ ' of file ' . bufname(v:beval_bufnr) .
246 \ ' on word "' . v:beval_text . '"' .
247 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
248 endfunc
249 setl balloonexpr=MyBalloonExpr()
250 setl ballooneval
251 call assert_equal('MyBalloonExpr()', &balloonexpr)
252 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200253 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100254 " Also, check if textlock works as expected.
255 setl balloonexpr&
256 call assert_equal('', &balloonexpr)
257 delfunc MyBalloonExpr
258 bwipe!
259
260 " Multiline support
261 if has('balloon_multiline')
262 " Multiline balloon using NL
263 new
264 func MyBalloonFuncForMultilineUsingNL()
265 return "Multiline\nSuppported\nBalloon\nusing NL"
266 endfunc
267 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
268 setl ballooneval
269 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
270 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200271 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100272 " expected. Also, check if textlock works as expected.
273 setl balloonexpr&
274 delfunc MyBalloonFuncForMultilineUsingNL
275 bwipe!
276
277 " Multiline balloon using List
278 new
279 func MyBalloonFuncForMultilineUsingList()
280 return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
281 endfunc
282 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
283 setl ballooneval
284 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
285 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200286 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100287 " expected. Also, check if textlock works as expected.
288 setl balloonexpr&
289 delfunc MyBalloonFuncForMultilineUsingList
290 bwipe!
291 endif
292
293 let &balloonexpr = balloonexpr_saved
294endfunc
295
Bram Moolenaar87748452017-03-12 17:10:33 +0100296" Invalid arguments are tested with test_options in conjunction with segfaults
297" caused by them (Patch 8.0.0357, 24922ec233).
298func Test_set_guicursor()
299 let guicursor_saved = &guicursor
300
301 let default = [
302 \ "n-v-c:block-Cursor/lCursor",
303 \ "ve:ver35-Cursor",
304 \ "o:hor50-Cursor",
305 \ "i-ci:ver25-Cursor/lCursor",
306 \ "r-cr:hor20-Cursor/lCursor",
307 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
308 \ ]
309
310 " Default Value
311 set guicursor&
312 call assert_equal(join(default, ','), &guicursor)
313
314 " Argument List Example 1
315 let opt_list = copy(default)
316 let opt_list[0] = "n-c-v:block-nCursor"
317 exec "set guicursor=" . join(opt_list, ',')
318 call assert_equal(join(opt_list, ','), &guicursor)
319 unlet opt_list
320
321 " Argument List Example 2
322 let opt_list = copy(default)
323 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
324 exec "set guicursor=" . join(opt_list, ',')
325 call assert_equal(join(opt_list, ','), &guicursor)
326 unlet opt_list
327
328 " 'a' Mode
329 set guicursor&
330 let &guicursor .= ',a:blinkon0'
331 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
332
333 let &guicursor = guicursor_saved
334endfunc
335
Bram Moolenaar43dded82017-02-09 16:06:17 +0100336func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100337 let skipped = ''
338
339 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100340 if has('xfontset')
341 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100342 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100343 set guifontset=
344 endif
345
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100346 if !g:x11_based_gui
347 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100348 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100349 " Non-empty font list with invalid font names.
350 "
351 " This test is twofold: (1) It checks if the command fails as expected
352 " when there are no loadable fonts found in the list. (2) It checks if
353 " 'guifont' remains the same after the command loads none of the fonts
354 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100355 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100356 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100357 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100358
359 " Non-empty font list with a valid font name. Should pick up the first
360 " valid font.
361 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100362 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
363 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100364
365 " Empty list. Should fallback to the built-in default.
366 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100367 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
368 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100369
370 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
371 " For GTK, what we refer to as 'font names' in our manual are actually
372 " 'initial font patterns'. A valid font which matches the 'canonical font
373 " pattern' constructed from a given 'initial pattern' is to be looked up
374 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
375 " font names'.
376 "
377 " Non-empty list. Should always pick up the first element, no matter how
378 " strange it is, as explained above.
379 set guifont=(´・ω・`)\ 12,Courier\ 12
380 call assert_equal('(´・ω・`) 12', getfontname())
381
382 " Empty list. Should fallback to the built-in default.
383 set guifont=
384 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100385 endif
386
387 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100388 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100389 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100390 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100391
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100392 if !empty(skipped)
393 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100394 endif
395endfunc
396
Bram Moolenaar10434672017-02-12 19:59:08 +0100397func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100398 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100399
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100400 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100401 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100402 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100403 let ctype_saved = v:ctype
404
405 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
406 " be chosen meticulously.
407 let font_head = '-misc-fixed-medium-r-normal--14'
408
409 let font_aw70 = font_head . '-130-75-75-c-70'
410 let font_aw140 = font_head . '-130-75-75-c-140'
411
412 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
413 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
414
415 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
416 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
417 let singleton = font_head . '-*'
418 let aliases = 'k14,r14'
419
420 " Second, among 'locales', look up such a locale that gets 'set
421 " guifontset=' to work successfully with every fontset specified with
422 " 'fontsets'.
423 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
424 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
425
426 let feasible = 0
427 for locale in locales
428 try
429 exec 'language ctype' locale
430 catch /^Vim\%((\a\+)\)\=:E197/
431 continue
432 endtry
433 let done = 0
434 for fontset in fontsets
435 try
436 exec 'set guifontset=' . fontset
437 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
438 break
439 endtry
440 let done += 1
441 endfor
442 if done == len(fontsets)
443 let feasible = 1
444 break
445 endif
446 endfor
447
448 " Third, give a set of tests if it is found feasible.
449 if !feasible
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100450 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100451 else
452 " N.B. 'v:ctype' has already been set to an appropriate value in the
453 " previous loop.
454 for fontset in fontsets
455 exec 'set guifontset=' . fontset
456 call assert_equal(fontset, &guifontset)
457 endfor
458 endif
459
460 " Finally, restore ctype.
461 exec 'language ctype' ctype_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100462 endif
463
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100464 if !empty(skipped)
465 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100466 endif
467endfunc
468
469func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100470 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100471
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100472 if !g:x11_based_gui
473 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100474 elseif has('gui_gtk')
475 let guifont_saved = &guifont
476 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100477
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100478 let fc_match = exepath('fc-match')
479 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100480 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100481 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100482 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
483 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
484 exec 'set guifontwide=' . fnameescape(wide)
485 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100486 endif
487
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100488 let &guifontwide = guifontwide_saved
489 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100490
491 elseif has('gui_athena') || has('gui_motif')
492 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100493 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100494 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100495 else
496 let encoding_saved = &encoding
497 let guifont_saved = &guifont
498 let guifontset_saved = &guifontset
499 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100500
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100501 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
502 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100503
504 set encoding=utf-8
505
506 " Case 1: guifontset is empty
507 set guifontset=
508
509 " Case 1-1: Automatic selection
510 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100511 exec 'set guifont=' . nfont
512 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100513
514 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100515 exec 'set guifontwide=' . wfont
516 exec 'set guifont=' . nfont
517 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100518
519 " Case 2: guifontset is invalid
520 try
521 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100522 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100523 catch
524 call assert_exception('E598')
525 endtry
526 " Set it to an invalid value brutally for preparation.
527 let &guifontset = '-*-notexist-*'
528
529 " Case 2-1: Automatic selection
530 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100531 exec 'set guifont=' . nfont
532 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100533
534 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100535 exec 'set guifontwide=' . wfont
536 exec 'set guifont=' . nfont
537 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100538
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100539 let &guifontwide = guifontwide_saved
540 let &guifontset = guifontset_saved
541 let &guifont = guifont_saved
542 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100543 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100544 endif
545
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100546 if !empty(skipped)
547 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100548 endif
549endfunc
550
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100551func Test_set_guiheadroom()
552 let skipped = ''
553
554 if !g:x11_based_gui
555 let skipped = g:not_supported . 'guiheadroom'
556 else
557 " Since this script is to be read together with '-U NONE', the default
558 " value must be preserved.
559 call assert_equal(50, &guiheadroom)
560 endif
561
562 if !empty(skipped)
563 throw skipped
564 endif
565endfunc
566
Bram Moolenaar87748452017-03-12 17:10:33 +0100567func Test_set_guioptions()
568 let guioptions_saved = &guioptions
569 let duration = '200m'
570
571 if has('win32')
572 " Default Value
573 set guioptions&
574 call assert_equal('egmrLtT', &guioptions)
575
576 else
577 " Default Value
578 set guioptions&
579 call assert_equal('aegimrLtT', &guioptions)
580
581 " To activate scrollbars of type 'L' or 'R'.
582 wincmd v
583 redraw!
584
585 " Remove all default GUI ornaments
586 set guioptions-=T
587 exec 'sleep' . duration
588 call assert_equal('aegimrLt', &guioptions)
589 set guioptions-=t
590 exec 'sleep' . duration
591 call assert_equal('aegimrL', &guioptions)
592 set guioptions-=L
593 exec 'sleep' . duration
594 call assert_equal('aegimr', &guioptions)
595 set guioptions-=r
596 exec 'sleep' . duration
597 call assert_equal('aegim', &guioptions)
598 set guioptions-=m
599 exec 'sleep' . duration
600 call assert_equal('aegi', &guioptions)
601
602 " Try non-default GUI ornaments
603 set guioptions+=l
604 exec 'sleep' . duration
605 call assert_equal('aegil', &guioptions)
606 set guioptions-=l
607 exec 'sleep' . duration
608 call assert_equal('aegi', &guioptions)
609
610 set guioptions+=R
611 exec 'sleep' . duration
612 call assert_equal('aegiR', &guioptions)
613 set guioptions-=R
614 exec 'sleep' . duration
615 call assert_equal('aegi', &guioptions)
616
617 set guioptions+=b
618 exec 'sleep' . duration
619 call assert_equal('aegib', &guioptions)
620 set guioptions+=h
621 exec 'sleep' . duration
622 call assert_equal('aegibh', &guioptions)
623 set guioptions-=h
624 exec 'sleep' . duration
625 call assert_equal('aegib', &guioptions)
626 set guioptions-=b
627 exec 'sleep' . duration
628 call assert_equal('aegi', &guioptions)
629
630 set guioptions+=v
631 exec 'sleep' . duration
632 call assert_equal('aegiv', &guioptions)
633 set guioptions-=v
634 exec 'sleep' . duration
635 call assert_equal('aegi', &guioptions)
636
637 if has('gui_motif')
638 set guioptions+=F
639 exec 'sleep' . duration
640 call assert_equal('aegiF', &guioptions)
641 set guioptions-=F
642 exec 'sleep' . duration
643 call assert_equal('aegi', &guioptions)
644 endif
645
646 " Restore GUI ornaments to the default state.
647 set guioptions+=m
648 exec 'sleep' . duration
649 call assert_equal('aegim', &guioptions)
650 set guioptions+=r
651 exec 'sleep' . duration
652 call assert_equal('aegimr', &guioptions)
653 set guioptions+=L
654 exec 'sleep' . duration
655 call assert_equal('aegimrL', &guioptions)
656 set guioptions+=t
657 exec 'sleep' . duration
658 call assert_equal('aegimrLt', &guioptions)
659 set guioptions+=T
660 exec 'sleep' . duration
661 call assert_equal("aegimrLtT", &guioptions)
662
663 wincmd o
664 redraw!
665 endif
666
667 let &guioptions = guioptions_saved
668endfunc
669
Bram Moolenaarab186732018-09-14 21:27:06 +0200670func Test_scrollbars()
671 new
672 " buffer with 200 lines
673 call setline(1, repeat(['one', 'two'], 100))
674 set guioptions+=rlb
675
676 " scroll to move line 11 at top, moves the cursor there
677 call test_scrollbar('left', 10, 0)
678 redraw
679 call assert_equal(1, winline())
680 call assert_equal(11, line('.'))
681
682 " scroll to move line 1 at top, cursor stays in line 11
683 call test_scrollbar('right', 0, 0)
684 redraw
685 call assert_equal(11, winline())
686 call assert_equal(11, line('.'))
687
688 set nowrap
689 call setline(11, repeat('x', 150))
690 redraw
691 call assert_equal(1, wincol())
692 call assert_equal(1, col('.'))
693
694 " scroll to character 11, cursor is moved
695 call test_scrollbar('hor', 10, 0)
696 redraw
697 call assert_equal(1, wincol())
698 call assert_equal(11, col('.'))
699
700 set guioptions&
701 set wrap&
702 bwipe!
703endfunc
704
Bram Moolenaar87748452017-03-12 17:10:33 +0100705func Test_set_guipty()
706 let guipty_saved = &guipty
707
708 " Default Value
709 set guipty&
710 call assert_equal(1, &guipty)
711
712 set noguipty
713 call assert_equal(0, &guipty)
714
715 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100716endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100717
Bram Moolenaar877e9572016-08-04 20:05:50 +0200718func Test_shell_command()
719 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200720 r !echo hello
721 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200722 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200723endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100724
Bram Moolenaar87748452017-03-12 17:10:33 +0100725func Test_syntax_colortest()
726 runtime syntax/colortest.vim
727 redraw!
728 sleep 200m
729 bwipe!
730endfunc
731
732func Test_set_term()
733 " It's enough to check the current value since setting 'term' to anything
734 " other than builtin_gui makes no sense at all.
735 call assert_equal('builtin_gui', &term)
736endfunc
737
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100738func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100739 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100740 call assert_true(v:windowid > 0)
741 else
742 call assert_equal(0, v:windowid)
743 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100744endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200745
746" Test "vim -g" and also the GUIEnter autocommand.
747func Test_gui_dash_g()
748 let cmd = GetVimCommand('Xscriptgui')
749 call writefile([""], "Xtestgui")
750 call writefile([
751 \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
752 \ 'au GUIEnter * qall',
753 \ ], 'Xscriptgui')
754 call system(cmd . ' -g')
755 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
756
757 call delete('Xscriptgui')
758 call delete('Xtestgui')
759endfunc
760
761" Test "vim -7" and also the GUIEnter autocommand.
762func Test_gui_dash_y()
763 let cmd = GetVimCommand('Xscriptgui')
764 call writefile([""], "Xtestgui")
765 call writefile([
766 \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
767 \ 'au GUIEnter * qall',
768 \ ], 'Xscriptgui')
769 call system(cmd . ' -y')
770 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
771
772 call delete('Xscriptgui')
773 call delete('Xtestgui')
774endfunc