blob: 985bbf4b7157f76cf17791ccc625ef0a9b5d3bdc [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.'
130 let vim_exe = exepath(v:progpath)
131 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100132 \ . vim_exe
Bram Moolenaar24d76362017-03-04 13:32:10 +0100133 \ . ' -u NONE -U NONE --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100134 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100135 let cmd = 'call test_ignore_error("E285") | '
136 \ . 'gui -f | '
137 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100138 \ . '\"+p'
139 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
140 \ . '\"+yis'
141 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100142 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100143
144 " Set the quoteplus register to test_call, and another gvim will launched.
145 " Then, it first tries to paste the content of its own quotedplus register
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200146 " onto it. Second, it tries to substitute test_response for the pasted
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100147 " sentence. If the sentence is identical to test_call, the substitution
148 " should succeed. Third, it tries to yank the result of the substitution
149 " to its own quoteplus register, and last it quits. When system()
150 " returns, the content of the quoteplus register should be identical to
151 " test_response if those quoteplus registers are synchronized properly
152 " with/through the X11 clipboard.
153 let @+ = test_call
154 call system(run_vimtest)
155 call assert_equal(test_response, @+)
156
157 let @+ = quoteplus_saved
158 endif
159
160 if !empty(skipped)
161 throw skipped
162 endif
163endfunc
164
Bram Moolenaar87748452017-03-12 17:10:33 +0100165func Test_set_background()
166 let background_saved = &background
167
168 set background&
169 call assert_equal('light', &background)
170
171 set background=dark
172 call assert_equal('dark', &background)
173
174 let &background = background_saved
175endfunc
176
Bram Moolenaard5841f22017-03-05 13:27:25 +0100177func Test_set_balloondelay()
178 if !exists('+balloondelay')
179 return
180 endif
181
182 let balloondelay_saved = &balloondelay
183
184 " Check if the default value is identical to that described in the manual.
185 set balloondelay&
186 call assert_equal(600, &balloondelay)
187
188 " Edge cases
189
190 " XXX This fact should be hidden so that people won't be tempted to write
191 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
192 " code.
193 set balloondelay=-1
194 call assert_equal(-1, &balloondelay)
195
196 " Though it's possible to interpret the zero delay to be 'as soon as
197 " possible' or even 'indefinite', its actual meaning depends on the GUI
198 " toolkit in use after all.
199 set balloondelay=0
200 call assert_equal(0, &balloondelay)
201
202 set balloondelay=1
203 call assert_equal(1, &balloondelay)
204
205 " Since p_bdelay is of type long currently, the upper bound can be
206 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100207 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
208 set balloondelay=2147483647
209 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100210
211 let &balloondelay = balloondelay_saved
212endfunc
213
214func Test_set_ballooneval()
215 if !exists('+ballooneval')
216 return
217 endif
218
219 let ballooneval_saved = &ballooneval
220
221 set ballooneval&
222 call assert_equal(0, &ballooneval)
223
224 set ballooneval
225 call assert_notequal(0, &ballooneval)
226
227 set noballooneval
228 call assert_equal(0, &ballooneval)
229
230 let &ballooneval = ballooneval_saved
231endfunc
232
233func Test_set_balloonexpr()
234 if !exists('+balloonexpr')
235 return
236 endif
237
238 let balloonexpr_saved = &balloonexpr
239
240 " Default value
241 set balloonexpr&
242 call assert_equal('', &balloonexpr)
243
244 " User-defined function
245 new
246 func MyBalloonExpr()
247 return 'Cursor is at line ' . v:beval_lnum .
248 \', column ' . v:beval_col .
249 \ ' of file ' . bufname(v:beval_bufnr) .
250 \ ' on word "' . v:beval_text . '"' .
251 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
252 endfunc
253 setl balloonexpr=MyBalloonExpr()
254 setl ballooneval
255 call assert_equal('MyBalloonExpr()', &balloonexpr)
256 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200257 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100258 " Also, check if textlock works as expected.
259 setl balloonexpr&
260 call assert_equal('', &balloonexpr)
261 delfunc MyBalloonExpr
262 bwipe!
263
264 " Multiline support
265 if has('balloon_multiline')
266 " Multiline balloon using NL
267 new
268 func MyBalloonFuncForMultilineUsingNL()
269 return "Multiline\nSuppported\nBalloon\nusing NL"
270 endfunc
271 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
272 setl ballooneval
273 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
274 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200275 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100276 " expected. Also, check if textlock works as expected.
277 setl balloonexpr&
278 delfunc MyBalloonFuncForMultilineUsingNL
279 bwipe!
280
281 " Multiline balloon using List
282 new
283 func MyBalloonFuncForMultilineUsingList()
284 return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
285 endfunc
286 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
287 setl ballooneval
288 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
289 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200290 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100291 " expected. Also, check if textlock works as expected.
292 setl balloonexpr&
293 delfunc MyBalloonFuncForMultilineUsingList
294 bwipe!
295 endif
296
297 let &balloonexpr = balloonexpr_saved
298endfunc
299
Bram Moolenaar87748452017-03-12 17:10:33 +0100300" Invalid arguments are tested with test_options in conjunction with segfaults
301" caused by them (Patch 8.0.0357, 24922ec233).
302func Test_set_guicursor()
303 let guicursor_saved = &guicursor
304
305 let default = [
306 \ "n-v-c:block-Cursor/lCursor",
307 \ "ve:ver35-Cursor",
308 \ "o:hor50-Cursor",
309 \ "i-ci:ver25-Cursor/lCursor",
310 \ "r-cr:hor20-Cursor/lCursor",
311 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
312 \ ]
313
314 " Default Value
315 set guicursor&
316 call assert_equal(join(default, ','), &guicursor)
317
318 " Argument List Example 1
319 let opt_list = copy(default)
320 let opt_list[0] = "n-c-v:block-nCursor"
321 exec "set guicursor=" . join(opt_list, ',')
322 call assert_equal(join(opt_list, ','), &guicursor)
323 unlet opt_list
324
325 " Argument List Example 2
326 let opt_list = copy(default)
327 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
328 exec "set guicursor=" . join(opt_list, ',')
329 call assert_equal(join(opt_list, ','), &guicursor)
330 unlet opt_list
331
332 " 'a' Mode
333 set guicursor&
334 let &guicursor .= ',a:blinkon0'
335 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
336
337 let &guicursor = guicursor_saved
338endfunc
339
Bram Moolenaar43dded82017-02-09 16:06:17 +0100340func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100341 let skipped = ''
342
343 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100344 if has('xfontset')
345 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100346 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100347 set guifontset=
348 endif
349
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100350 if !g:x11_based_gui
351 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100352 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100353 " Non-empty font list with invalid font names.
354 "
355 " This test is twofold: (1) It checks if the command fails as expected
356 " when there are no loadable fonts found in the list. (2) It checks if
357 " 'guifont' remains the same after the command loads none of the fonts
358 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100359 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100360 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100361 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100362
363 " Non-empty font list with a valid font name. Should pick up the first
364 " valid font.
365 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100366 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
367 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100368
369 " Empty list. Should fallback to the built-in default.
370 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100371 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
372 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100373
374 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
375 " For GTK, what we refer to as 'font names' in our manual are actually
376 " 'initial font patterns'. A valid font which matches the 'canonical font
377 " pattern' constructed from a given 'initial pattern' is to be looked up
378 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
379 " font names'.
380 "
381 " Non-empty list. Should always pick up the first element, no matter how
382 " strange it is, as explained above.
383 set guifont=(´・ω・`)\ 12,Courier\ 12
384 call assert_equal('(´・ω・`) 12', getfontname())
385
386 " Empty list. Should fallback to the built-in default.
387 set guifont=
388 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100389 endif
390
391 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100392 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100393 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100394 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100395
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100396 if !empty(skipped)
397 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100398 endif
399endfunc
400
Bram Moolenaar10434672017-02-12 19:59:08 +0100401func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100402 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100403
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100404 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100405 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100406 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100407 let ctype_saved = v:ctype
408
409 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
410 " be chosen meticulously.
411 let font_head = '-misc-fixed-medium-r-normal--14'
412
413 let font_aw70 = font_head . '-130-75-75-c-70'
414 let font_aw140 = font_head . '-130-75-75-c-140'
415
416 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
417 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
418
419 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
420 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
421 let singleton = font_head . '-*'
422 let aliases = 'k14,r14'
423
424 " Second, among 'locales', look up such a locale that gets 'set
425 " guifontset=' to work successfully with every fontset specified with
426 " 'fontsets'.
427 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
428 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
429
430 let feasible = 0
431 for locale in locales
432 try
433 exec 'language ctype' locale
434 catch /^Vim\%((\a\+)\)\=:E197/
435 continue
436 endtry
437 let done = 0
438 for fontset in fontsets
439 try
440 exec 'set guifontset=' . fontset
441 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
442 break
443 endtry
444 let done += 1
445 endfor
446 if done == len(fontsets)
447 let feasible = 1
448 break
449 endif
450 endfor
451
452 " Third, give a set of tests if it is found feasible.
453 if !feasible
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100454 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100455 else
456 " N.B. 'v:ctype' has already been set to an appropriate value in the
457 " previous loop.
458 for fontset in fontsets
459 exec 'set guifontset=' . fontset
460 call assert_equal(fontset, &guifontset)
461 endfor
462 endif
463
464 " Finally, restore ctype.
465 exec 'language ctype' ctype_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100466 endif
467
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100468 if !empty(skipped)
469 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100470 endif
471endfunc
472
473func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100474 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100475
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100476 if !g:x11_based_gui
477 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100478 elseif has('gui_gtk')
479 let guifont_saved = &guifont
480 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100481
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100482 let fc_match = exepath('fc-match')
483 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100484 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100485 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100486 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
487 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
488 exec 'set guifontwide=' . fnameescape(wide)
489 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100490 endif
491
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100492 let &guifontwide = guifontwide_saved
493 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100494
495 elseif has('gui_athena') || has('gui_motif')
496 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100497 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100498 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100499 else
500 let encoding_saved = &encoding
501 let guifont_saved = &guifont
502 let guifontset_saved = &guifontset
503 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100504
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100505 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
506 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100507
508 set encoding=utf-8
509
510 " Case 1: guifontset is empty
511 set guifontset=
512
513 " Case 1-1: Automatic selection
514 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100515 exec 'set guifont=' . nfont
516 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100517
518 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100519 exec 'set guifontwide=' . wfont
520 exec 'set guifont=' . nfont
521 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100522
523 " Case 2: guifontset is invalid
524 try
525 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100526 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100527 catch
528 call assert_exception('E598')
529 endtry
530 " Set it to an invalid value brutally for preparation.
531 let &guifontset = '-*-notexist-*'
532
533 " Case 2-1: Automatic selection
534 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100535 exec 'set guifont=' . nfont
536 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100537
538 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100539 exec 'set guifontwide=' . wfont
540 exec 'set guifont=' . nfont
541 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100542
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100543 let &guifontwide = guifontwide_saved
544 let &guifontset = guifontset_saved
545 let &guifont = guifont_saved
546 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100547 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100548 endif
549
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100550 if !empty(skipped)
551 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100552 endif
553endfunc
554
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100555func Test_set_guiheadroom()
556 let skipped = ''
557
558 if !g:x11_based_gui
559 let skipped = g:not_supported . 'guiheadroom'
560 else
561 " Since this script is to be read together with '-U NONE', the default
562 " value must be preserved.
563 call assert_equal(50, &guiheadroom)
564 endif
565
566 if !empty(skipped)
567 throw skipped
568 endif
569endfunc
570
Bram Moolenaar87748452017-03-12 17:10:33 +0100571func Test_set_guioptions()
572 let guioptions_saved = &guioptions
573 let duration = '200m'
574
575 if has('win32')
576 " Default Value
577 set guioptions&
578 call assert_equal('egmrLtT', &guioptions)
579
580 else
581 " Default Value
582 set guioptions&
583 call assert_equal('aegimrLtT', &guioptions)
584
585 " To activate scrollbars of type 'L' or 'R'.
586 wincmd v
587 redraw!
588
589 " Remove all default GUI ornaments
590 set guioptions-=T
591 exec 'sleep' . duration
592 call assert_equal('aegimrLt', &guioptions)
593 set guioptions-=t
594 exec 'sleep' . duration
595 call assert_equal('aegimrL', &guioptions)
596 set guioptions-=L
597 exec 'sleep' . duration
598 call assert_equal('aegimr', &guioptions)
599 set guioptions-=r
600 exec 'sleep' . duration
601 call assert_equal('aegim', &guioptions)
602 set guioptions-=m
603 exec 'sleep' . duration
604 call assert_equal('aegi', &guioptions)
605
606 " Try non-default GUI ornaments
607 set guioptions+=l
608 exec 'sleep' . duration
609 call assert_equal('aegil', &guioptions)
610 set guioptions-=l
611 exec 'sleep' . duration
612 call assert_equal('aegi', &guioptions)
613
614 set guioptions+=R
615 exec 'sleep' . duration
616 call assert_equal('aegiR', &guioptions)
617 set guioptions-=R
618 exec 'sleep' . duration
619 call assert_equal('aegi', &guioptions)
620
621 set guioptions+=b
622 exec 'sleep' . duration
623 call assert_equal('aegib', &guioptions)
624 set guioptions+=h
625 exec 'sleep' . duration
626 call assert_equal('aegibh', &guioptions)
627 set guioptions-=h
628 exec 'sleep' . duration
629 call assert_equal('aegib', &guioptions)
630 set guioptions-=b
631 exec 'sleep' . duration
632 call assert_equal('aegi', &guioptions)
633
634 set guioptions+=v
635 exec 'sleep' . duration
636 call assert_equal('aegiv', &guioptions)
637 set guioptions-=v
638 exec 'sleep' . duration
639 call assert_equal('aegi', &guioptions)
640
641 if has('gui_motif')
642 set guioptions+=F
643 exec 'sleep' . duration
644 call assert_equal('aegiF', &guioptions)
645 set guioptions-=F
646 exec 'sleep' . duration
647 call assert_equal('aegi', &guioptions)
648 endif
649
650 " Restore GUI ornaments to the default state.
651 set guioptions+=m
652 exec 'sleep' . duration
653 call assert_equal('aegim', &guioptions)
654 set guioptions+=r
655 exec 'sleep' . duration
656 call assert_equal('aegimr', &guioptions)
657 set guioptions+=L
658 exec 'sleep' . duration
659 call assert_equal('aegimrL', &guioptions)
660 set guioptions+=t
661 exec 'sleep' . duration
662 call assert_equal('aegimrLt', &guioptions)
663 set guioptions+=T
664 exec 'sleep' . duration
665 call assert_equal("aegimrLtT", &guioptions)
666
667 wincmd o
668 redraw!
669 endif
670
671 let &guioptions = guioptions_saved
672endfunc
673
Bram Moolenaarab186732018-09-14 21:27:06 +0200674func Test_scrollbars()
675 new
676 " buffer with 200 lines
677 call setline(1, repeat(['one', 'two'], 100))
678 set guioptions+=rlb
679
680 " scroll to move line 11 at top, moves the cursor there
681 call test_scrollbar('left', 10, 0)
682 redraw
683 call assert_equal(1, winline())
684 call assert_equal(11, line('.'))
685
686 " scroll to move line 1 at top, cursor stays in line 11
687 call test_scrollbar('right', 0, 0)
688 redraw
689 call assert_equal(11, winline())
690 call assert_equal(11, line('.'))
691
692 set nowrap
693 call setline(11, repeat('x', 150))
694 redraw
695 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200696 set number
697 redraw
698 call assert_equal(5, wincol())
699 set nonumber
700 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200701 call assert_equal(1, col('.'))
702
703 " scroll to character 11, cursor is moved
704 call test_scrollbar('hor', 10, 0)
705 redraw
706 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200707 set number
708 redraw
709 call assert_equal(5, wincol())
710 set nonumber
711 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200712 call assert_equal(11, col('.'))
713
714 set guioptions&
715 set wrap&
716 bwipe!
717endfunc
718
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100719func Test_menu()
720 " Check Help menu exists
721 let help_menu = execute('menu Help')
722 call assert_match('Overview', help_menu)
723
724 " Check Help menu works
725 emenu Help.Overview
726 call assert_equal('help', &buftype)
727 close
728
729 " Check deleting menu doesn't cause trouble.
730 aunmenu Help
731 call assert_fails('menu Help', 'E329:')
732endfunc
733
Bram Moolenaar87748452017-03-12 17:10:33 +0100734func Test_set_guipty()
735 let guipty_saved = &guipty
736
737 " Default Value
738 set guipty&
739 call assert_equal(1, &guipty)
740
741 set noguipty
742 call assert_equal(0, &guipty)
743
744 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100745endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100746
Bram Moolenaarc701f322019-03-28 21:49:21 +0100747func Test_encoding_conversion()
748 " GTK supports conversion between 'encoding' and "utf-8"
749 if has('gui_gtk')
750 let encoding_saved = &encoding
751 set encoding=latin1
752
753 " would be nice if we could take a screenshot
754 intro
755 " sets the window title
756 edit SomeFile
757
758 let &encoding = encoding_saved
759 endif
760endfunc
761
Bram Moolenaar877e9572016-08-04 20:05:50 +0200762func Test_shell_command()
763 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200764 r !echo hello
765 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200766 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200767endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100768
Bram Moolenaar87748452017-03-12 17:10:33 +0100769func Test_syntax_colortest()
770 runtime syntax/colortest.vim
771 redraw!
772 sleep 200m
773 bwipe!
774endfunc
775
776func Test_set_term()
777 " It's enough to check the current value since setting 'term' to anything
778 " other than builtin_gui makes no sense at all.
779 call assert_equal('builtin_gui', &term)
780endfunc
781
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100782func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100783 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100784 call assert_true(v:windowid > 0)
785 else
786 call assert_equal(0, v:windowid)
787 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100788endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200789
790" Test "vim -g" and also the GUIEnter autocommand.
791func Test_gui_dash_g()
792 let cmd = GetVimCommand('Xscriptgui')
793 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200794 let lines =<< trim END
795 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
796 au GUIEnter * qall
797 END
798 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200799 call system(cmd . ' -g')
800 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
801
802 call delete('Xscriptgui')
803 call delete('Xtestgui')
804endfunc
805
806" Test "vim -7" and also the GUIEnter autocommand.
807func Test_gui_dash_y()
808 let cmd = GetVimCommand('Xscriptgui')
809 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200810 let lines =<< trim END
811 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
812 au GUIEnter * qall
813 END
814 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200815 call system(cmd . ' -y')
816 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
817
818 call delete('Xscriptgui')
819 call delete('Xtestgui')
820endfunc