blob: e80e85f277eba233ed01ebb5dc2a6c994df77a07 [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
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
5CheckCanRunGui
Bram Moolenaar877e9572016-08-04 20:05:50 +02006
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01007source setup_gui.vim
Bram Moolenaar13c724f2017-02-05 20:54:26 +01008
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01009func Setup()
10 call GUISetUpCommon()
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020011endfunc
12
13func TearDown()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010014 call GUITearDownCommon()
Bram Moolenaar877e9572016-08-04 20:05:50 +020015endfunc
16
17" Test for resetting "secure" flag after GUI has started.
Bram Moolenaar5d7ead32018-02-27 17:17:42 +010018" Must be run first, since it starts the GUI on Unix.
Bram Moolenaar877e9572016-08-04 20:05:50 +020019func Test_1_set_secure()
20 set exrc secure
21 gui -f
22 call assert_equal(1, has('gui_running'))
23endfunc
24
Bram Moolenaard5841f22017-03-05 13:27:25 +010025" 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
Bram Moolenaar87748452017-03-12 17:10:33 +010033func Test_colorscheme()
34 let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
Bram Moolenaar60a68362018-04-30 15:40:48 +020035 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
Bram Moolenaar87748452017-03-12 17:10:33 +010041
42 colorscheme torte
43 redraw!
Bram Moolenaar87748452017-03-12 17:10:33 +010044 call assert_equal('dark', &background)
Bram Moolenaar60a68362018-04-30 15:40:48 +020045 call assert_equal(1, g:before_colors)
46 call assert_equal(2, g:after_colors)
Bram Moolenaar6d4470b2019-01-08 21:05:51 +010047 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:')
Bram Moolenaar87748452017-03-12 17:10:33 +010053
54 exec 'colorscheme' colorscheme_saved
Bram Moolenaar60a68362018-04-30 15:40:48 +020055 augroup TestColors
56 au!
57 augroup END
58 unlet g:color_count g:after_colors g:before_colors
Bram Moolenaar87748452017-03-12 17:10:33 +010059 redraw!
60endfunc
61
Bram Moolenaar6f785742017-02-06 22:11:55 +010062func Test_getfontname_with_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010063 let skipped = ''
64
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010065 if !g:x11_based_gui
66 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010067 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010068 " 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.
Bram Moolenaar87748452017-03-12 17:10:33 +010072 let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
73 call assert_match(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010074
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.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010080 let fname = 'Bitstream Vera Sans Mono 12'
81 call assert_equal(fname, getfontname(fname))
82 endif
83
84 if !empty(skipped)
85 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010086 endif
87endfunc
88
89func Test_getfontname_without_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010090 let skipped = ''
91
92 let fname = getfontname()
93
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010094 if !g:x11_based_gui
95 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010096 elseif has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +010097 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010098 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +010099 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar87748452017-03-12 17:10:33 +0100100 " '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)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100103 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
104 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100105 call assert_equal('Monospace 10', fname)
106 endif
107
108 if !empty(skipped)
109 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +0100110 endif
111endfunc
112
Bram Moolenaar87748452017-03-12 17:10:33 +0100113func 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)
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200117 call assert_equal([getwinposx(), getwinposy()], getwinpos())
Bram Moolenaar87748452017-03-12 17:10:33 +0100118endfunc
119
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100120func 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.'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200130 let vim_exe = GetVimCommand()
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100131 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200132 \ . vim_exe . ' --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100133 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100134 let cmd = 'call test_ignore_error("E285") | '
135 \ . 'gui -f | '
136 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100137 \ . '\"+p'
138 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
139 \ . '\"+yis'
140 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100141 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100142
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
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200145 " onto it. Second, it tries to substitute test_response for the pasted
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100146 " 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
Bram Moolenaar87748452017-03-12 17:10:33 +0100164func 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
Bram Moolenaard5841f22017-03-05 13:27:25 +0100176func 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
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100206 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
207 set balloondelay=2147483647
208 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100209
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,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200256 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100257 " 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,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200274 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100275 " 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,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200289 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100290 " 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
Bram Moolenaar87748452017-03-12 17:10:33 +0100299" 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
Bram Moolenaar43dded82017-02-09 16:06:17 +0100339func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100340 let skipped = ''
341
342 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100343 if has('xfontset')
344 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100345 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100346 set guifontset=
347 endif
348
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100349 if !g:x11_based_gui
350 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100351 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100352 " 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.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100358 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100359 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100360 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100361
362 " Non-empty font list with a valid font name. Should pick up the first
363 " valid font.
364 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100365 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
366 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100367
368 " Empty list. Should fallback to the built-in default.
369 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100370 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
371 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100372
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())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100388 endif
389
390 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100391 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100392 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100393 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100394
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100395 if !empty(skipped)
396 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100397 endif
398endfunc
399
Bram Moolenaar10434672017-02-12 19:59:08 +0100400func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100401 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100402
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100403 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100404 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100405 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100406 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
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100453 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100454 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
Bram Moolenaar10434672017-02-12 19:59:08 +0100465 endif
466
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100467 if !empty(skipped)
468 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100469 endif
470endfunc
471
472func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100473 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100474
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100475 if !g:x11_based_gui
476 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100477 elseif has('gui_gtk')
478 let guifont_saved = &guifont
479 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100480
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100481 let fc_match = exepath('fc-match')
482 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100483 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100484 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100485 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)
Bram Moolenaar10434672017-02-12 19:59:08 +0100489 endif
490
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100491 let &guifontwide = guifontwide_saved
492 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100493
494 elseif has('gui_athena') || has('gui_motif')
495 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100496 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100497 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100498 else
499 let encoding_saved = &encoding
500 let guifont_saved = &guifont
501 let guifontset_saved = &guifontset
502 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100503
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100504 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'
Bram Moolenaar10434672017-02-12 19:59:08 +0100506
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=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100514 exec 'set guifont=' . nfont
515 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100516
517 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100518 exec 'set guifontwide=' . wfont
519 exec 'set guifont=' . nfont
520 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100521
522 " Case 2: guifontset is invalid
523 try
524 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100525 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100526 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=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100534 exec 'set guifont=' . nfont
535 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100536
537 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100538 exec 'set guifontwide=' . wfont
539 exec 'set guifont=' . nfont
540 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100541
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100542 let &guifontwide = guifontwide_saved
543 let &guifontset = guifontset_saved
544 let &guifont = guifont_saved
545 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100546 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100547 endif
548
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100549 if !empty(skipped)
550 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100551 endif
552endfunc
553
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100554func 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
Bram Moolenaar87748452017-03-12 17:10:33 +0100570func 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
Bram Moolenaarab186732018-09-14 21:27:06 +0200673func 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())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200695 set number
696 redraw
697 call assert_equal(5, wincol())
698 set nonumber
699 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200700 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())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200706 set number
707 redraw
708 call assert_equal(5, wincol())
709 set nonumber
710 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200711 call assert_equal(11, col('.'))
712
713 set guioptions&
714 set wrap&
715 bwipe!
716endfunc
717
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100718func 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
Bram Moolenaar87748452017-03-12 17:10:33 +0100733func 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
Bram Moolenaar6f785742017-02-06 22:11:55 +0100744endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100745
Bram Moolenaarc701f322019-03-28 21:49:21 +0100746func 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
Bram Moolenaar877e9572016-08-04 20:05:50 +0200761func Test_shell_command()
762 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200763 r !echo hello
764 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200765 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200766endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100767
Bram Moolenaar87748452017-03-12 17:10:33 +0100768func 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
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100781func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100782 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100783 call assert_true(v:windowid > 0)
784 else
785 call assert_equal(0, v:windowid)
786 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100787endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200788
789" Test "vim -g" and also the GUIEnter autocommand.
790func Test_gui_dash_g()
791 let cmd = GetVimCommand('Xscriptgui')
792 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200793 let lines =<< trim END
794 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
795 au GUIEnter * qall
796 END
797 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200798 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")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200809 let lines =<< trim END
810 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
811 au GUIEnter * qall
812 END
813 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200814 call system(cmd . ' -y')
815 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
816
817 call delete('Xscriptgui')
818 call delete('Xtestgui')
819endfunc