blob: 7874fffa064c613d0fc3475b6cd701e2780c255d [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!
Bram Moolenaar87748452017-03-12 17:10:33 +010045 call assert_equal('dark', &background)
Bram Moolenaar60a68362018-04-30 15:40:48 +020046 call assert_equal(1, g:before_colors)
47 call assert_equal(2, g:after_colors)
Bram Moolenaar6d4470b2019-01-08 21:05:51 +010048 call assert_equal("\ntorte", execute('colorscheme'))
49
50 let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g')
51 call assert_match("\nSearch xxx term=reverse ctermfg=0 ctermbg=12 gui=bold guifg=Black guibg=Red", a)
52
53 call assert_fails('colorscheme does_not_exist', 'E185:')
Bram Moolenaar87748452017-03-12 17:10:33 +010054
55 exec 'colorscheme' colorscheme_saved
Bram Moolenaar60a68362018-04-30 15:40:48 +020056 augroup TestColors
57 au!
58 augroup END
59 unlet g:color_count g:after_colors g:before_colors
Bram Moolenaar87748452017-03-12 17:10:33 +010060 redraw!
61endfunc
62
Bram Moolenaar6f785742017-02-06 22:11:55 +010063func Test_getfontname_with_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010064 let skipped = ''
65
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010066 if !g:x11_based_gui
67 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010068 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010069 " Invalid font name. The result should be an empty string.
70 call assert_equal('', getfontname('notexist'))
71
72 " Valid font name. This is usually the real name of 7x13 by default.
Bram Moolenaar87748452017-03-12 17:10:33 +010073 let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
74 call assert_match(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010075
76 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
77 " Invalid font name. The result should be the name plus the default size.
78 call assert_equal('notexist 10', getfontname('notexist'))
79
80 " Valid font name. This is usually the real name of Monospace by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010081 let fname = 'Bitstream Vera Sans Mono 12'
82 call assert_equal(fname, getfontname(fname))
83 endif
84
85 if !empty(skipped)
86 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010087 endif
88endfunc
89
90func Test_getfontname_without_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010091 let skipped = ''
92
93 let fname = getfontname()
94
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010095 if !g:x11_based_gui
96 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010097 elseif has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +010098 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010099 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100100 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar87748452017-03-12 17:10:33 +0100101 " 'expected' is DFLT_FONT of gui_x11.c or its real name.
102 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
103 call assert_match(pat, fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100104 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
105 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100106 call assert_equal('Monospace 10', fname)
107 endif
108
109 if !empty(skipped)
110 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +0100111 endif
112endfunc
113
Bram Moolenaar87748452017-03-12 17:10:33 +0100114func Test_getwinpos()
115 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
116 call assert_true(getwinposx() >= 0)
117 call assert_true(getwinposy() >= 0)
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200118 call assert_equal([getwinposx(), getwinposy()], getwinpos())
Bram Moolenaar87748452017-03-12 17:10:33 +0100119endfunc
120
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100121func Test_quoteplus()
122 let skipped = ''
123
124 if !g:x11_based_gui
125 let skipped = g:not_supported . 'quoteplus'
126 else
127 let quoteplus_saved = @+
128
129 let test_call = 'Can you hear me?'
130 let test_response = 'Yes, I can.'
131 let vim_exe = exepath(v:progpath)
132 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100133 \ . vim_exe
Bram Moolenaar24d76362017-03-04 13:32:10 +0100134 \ . ' -u NONE -U NONE --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100135 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100136 let cmd = 'call test_ignore_error("E285") | '
137 \ . 'gui -f | '
138 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100139 \ . '\"+p'
140 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
141 \ . '\"+yis'
142 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100143 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100144
145 " Set the quoteplus register to test_call, and another gvim will launched.
146 " Then, it first tries to paste the content of its own quotedplus register
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200147 " onto it. Second, it tries to substitute test_response for the pasted
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100148 " sentence. If the sentence is identical to test_call, the substitution
149 " should succeed. Third, it tries to yank the result of the substitution
150 " to its own quoteplus register, and last it quits. When system()
151 " returns, the content of the quoteplus register should be identical to
152 " test_response if those quoteplus registers are synchronized properly
153 " with/through the X11 clipboard.
154 let @+ = test_call
155 call system(run_vimtest)
156 call assert_equal(test_response, @+)
157
158 let @+ = quoteplus_saved
159 endif
160
161 if !empty(skipped)
162 throw skipped
163 endif
164endfunc
165
Bram Moolenaar87748452017-03-12 17:10:33 +0100166func Test_set_background()
167 let background_saved = &background
168
169 set background&
170 call assert_equal('light', &background)
171
172 set background=dark
173 call assert_equal('dark', &background)
174
175 let &background = background_saved
176endfunc
177
Bram Moolenaard5841f22017-03-05 13:27:25 +0100178func Test_set_balloondelay()
179 if !exists('+balloondelay')
180 return
181 endif
182
183 let balloondelay_saved = &balloondelay
184
185 " Check if the default value is identical to that described in the manual.
186 set balloondelay&
187 call assert_equal(600, &balloondelay)
188
189 " Edge cases
190
191 " XXX This fact should be hidden so that people won't be tempted to write
192 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
193 " code.
194 set balloondelay=-1
195 call assert_equal(-1, &balloondelay)
196
197 " Though it's possible to interpret the zero delay to be 'as soon as
198 " possible' or even 'indefinite', its actual meaning depends on the GUI
199 " toolkit in use after all.
200 set balloondelay=0
201 call assert_equal(0, &balloondelay)
202
203 set balloondelay=1
204 call assert_equal(1, &balloondelay)
205
206 " Since p_bdelay is of type long currently, the upper bound can be
207 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100208 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
209 set balloondelay=2147483647
210 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100211
212 let &balloondelay = balloondelay_saved
213endfunc
214
215func Test_set_ballooneval()
216 if !exists('+ballooneval')
217 return
218 endif
219
220 let ballooneval_saved = &ballooneval
221
222 set ballooneval&
223 call assert_equal(0, &ballooneval)
224
225 set ballooneval
226 call assert_notequal(0, &ballooneval)
227
228 set noballooneval
229 call assert_equal(0, &ballooneval)
230
231 let &ballooneval = ballooneval_saved
232endfunc
233
234func Test_set_balloonexpr()
235 if !exists('+balloonexpr')
236 return
237 endif
238
239 let balloonexpr_saved = &balloonexpr
240
241 " Default value
242 set balloonexpr&
243 call assert_equal('', &balloonexpr)
244
245 " User-defined function
246 new
247 func MyBalloonExpr()
248 return 'Cursor is at line ' . v:beval_lnum .
249 \', column ' . v:beval_col .
250 \ ' of file ' . bufname(v:beval_bufnr) .
251 \ ' on word "' . v:beval_text . '"' .
252 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
253 endfunc
254 setl balloonexpr=MyBalloonExpr()
255 setl ballooneval
256 call assert_equal('MyBalloonExpr()', &balloonexpr)
257 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200258 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100259 " Also, check if textlock works as expected.
260 setl balloonexpr&
261 call assert_equal('', &balloonexpr)
262 delfunc MyBalloonExpr
263 bwipe!
264
265 " Multiline support
266 if has('balloon_multiline')
267 " Multiline balloon using NL
268 new
269 func MyBalloonFuncForMultilineUsingNL()
270 return "Multiline\nSuppported\nBalloon\nusing NL"
271 endfunc
272 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
273 setl ballooneval
274 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
275 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200276 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100277 " expected. Also, check if textlock works as expected.
278 setl balloonexpr&
279 delfunc MyBalloonFuncForMultilineUsingNL
280 bwipe!
281
282 " Multiline balloon using List
283 new
284 func MyBalloonFuncForMultilineUsingList()
285 return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
286 endfunc
287 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
288 setl ballooneval
289 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
290 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200291 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100292 " expected. Also, check if textlock works as expected.
293 setl balloonexpr&
294 delfunc MyBalloonFuncForMultilineUsingList
295 bwipe!
296 endif
297
298 let &balloonexpr = balloonexpr_saved
299endfunc
300
Bram Moolenaar87748452017-03-12 17:10:33 +0100301" Invalid arguments are tested with test_options in conjunction with segfaults
302" caused by them (Patch 8.0.0357, 24922ec233).
303func Test_set_guicursor()
304 let guicursor_saved = &guicursor
305
306 let default = [
307 \ "n-v-c:block-Cursor/lCursor",
308 \ "ve:ver35-Cursor",
309 \ "o:hor50-Cursor",
310 \ "i-ci:ver25-Cursor/lCursor",
311 \ "r-cr:hor20-Cursor/lCursor",
312 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
313 \ ]
314
315 " Default Value
316 set guicursor&
317 call assert_equal(join(default, ','), &guicursor)
318
319 " Argument List Example 1
320 let opt_list = copy(default)
321 let opt_list[0] = "n-c-v:block-nCursor"
322 exec "set guicursor=" . join(opt_list, ',')
323 call assert_equal(join(opt_list, ','), &guicursor)
324 unlet opt_list
325
326 " Argument List Example 2
327 let opt_list = copy(default)
328 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
329 exec "set guicursor=" . join(opt_list, ',')
330 call assert_equal(join(opt_list, ','), &guicursor)
331 unlet opt_list
332
333 " 'a' Mode
334 set guicursor&
335 let &guicursor .= ',a:blinkon0'
336 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
337
338 let &guicursor = guicursor_saved
339endfunc
340
Bram Moolenaar43dded82017-02-09 16:06:17 +0100341func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100342 let skipped = ''
343
344 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100345 if has('xfontset')
346 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100347 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100348 set guifontset=
349 endif
350
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100351 if !g:x11_based_gui
352 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100353 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100354 " Non-empty font list with invalid font names.
355 "
356 " This test is twofold: (1) It checks if the command fails as expected
357 " when there are no loadable fonts found in the list. (2) It checks if
358 " 'guifont' remains the same after the command loads none of the fonts
359 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100360 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100361 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100362 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100363
364 " Non-empty font list with a valid font name. Should pick up the first
365 " valid font.
366 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100367 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
368 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100369
370 " Empty list. Should fallback to the built-in default.
371 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100372 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
373 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100374
375 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
376 " For GTK, what we refer to as 'font names' in our manual are actually
377 " 'initial font patterns'. A valid font which matches the 'canonical font
378 " pattern' constructed from a given 'initial pattern' is to be looked up
379 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
380 " font names'.
381 "
382 " Non-empty list. Should always pick up the first element, no matter how
383 " strange it is, as explained above.
384 set guifont=(´・ω・`)\ 12,Courier\ 12
385 call assert_equal('(´・ω・`) 12', getfontname())
386
387 " Empty list. Should fallback to the built-in default.
388 set guifont=
389 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100390 endif
391
392 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100393 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100394 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100395 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100396
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100397 if !empty(skipped)
398 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100399 endif
400endfunc
401
Bram Moolenaar10434672017-02-12 19:59:08 +0100402func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100403 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100404
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100405 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100406 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100407 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100408 let ctype_saved = v:ctype
409
410 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
411 " be chosen meticulously.
412 let font_head = '-misc-fixed-medium-r-normal--14'
413
414 let font_aw70 = font_head . '-130-75-75-c-70'
415 let font_aw140 = font_head . '-130-75-75-c-140'
416
417 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
418 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
419
420 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
421 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
422 let singleton = font_head . '-*'
423 let aliases = 'k14,r14'
424
425 " Second, among 'locales', look up such a locale that gets 'set
426 " guifontset=' to work successfully with every fontset specified with
427 " 'fontsets'.
428 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
429 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
430
431 let feasible = 0
432 for locale in locales
433 try
434 exec 'language ctype' locale
435 catch /^Vim\%((\a\+)\)\=:E197/
436 continue
437 endtry
438 let done = 0
439 for fontset in fontsets
440 try
441 exec 'set guifontset=' . fontset
442 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
443 break
444 endtry
445 let done += 1
446 endfor
447 if done == len(fontsets)
448 let feasible = 1
449 break
450 endif
451 endfor
452
453 " Third, give a set of tests if it is found feasible.
454 if !feasible
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100455 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100456 else
457 " N.B. 'v:ctype' has already been set to an appropriate value in the
458 " previous loop.
459 for fontset in fontsets
460 exec 'set guifontset=' . fontset
461 call assert_equal(fontset, &guifontset)
462 endfor
463 endif
464
465 " Finally, restore ctype.
466 exec 'language ctype' ctype_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100467 endif
468
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100469 if !empty(skipped)
470 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100471 endif
472endfunc
473
474func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100475 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100476
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100477 if !g:x11_based_gui
478 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100479 elseif has('gui_gtk')
480 let guifont_saved = &guifont
481 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100482
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100483 let fc_match = exepath('fc-match')
484 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100485 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100486 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100487 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
488 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
489 exec 'set guifontwide=' . fnameescape(wide)
490 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100491 endif
492
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100493 let &guifontwide = guifontwide_saved
494 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100495
496 elseif has('gui_athena') || has('gui_motif')
497 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100498 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100499 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100500 else
501 let encoding_saved = &encoding
502 let guifont_saved = &guifont
503 let guifontset_saved = &guifontset
504 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100505
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100506 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
507 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100508
509 set encoding=utf-8
510
511 " Case 1: guifontset is empty
512 set guifontset=
513
514 " Case 1-1: Automatic selection
515 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100516 exec 'set guifont=' . nfont
517 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100518
519 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100520 exec 'set guifontwide=' . wfont
521 exec 'set guifont=' . nfont
522 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100523
524 " Case 2: guifontset is invalid
525 try
526 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100527 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100528 catch
529 call assert_exception('E598')
530 endtry
531 " Set it to an invalid value brutally for preparation.
532 let &guifontset = '-*-notexist-*'
533
534 " Case 2-1: Automatic selection
535 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100536 exec 'set guifont=' . nfont
537 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100538
539 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100540 exec 'set guifontwide=' . wfont
541 exec 'set guifont=' . nfont
542 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100543
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100544 let &guifontwide = guifontwide_saved
545 let &guifontset = guifontset_saved
546 let &guifont = guifont_saved
547 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100548 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100549 endif
550
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100551 if !empty(skipped)
552 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100553 endif
554endfunc
555
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100556func Test_set_guiheadroom()
557 let skipped = ''
558
559 if !g:x11_based_gui
560 let skipped = g:not_supported . 'guiheadroom'
561 else
562 " Since this script is to be read together with '-U NONE', the default
563 " value must be preserved.
564 call assert_equal(50, &guiheadroom)
565 endif
566
567 if !empty(skipped)
568 throw skipped
569 endif
570endfunc
571
Bram Moolenaar87748452017-03-12 17:10:33 +0100572func Test_set_guioptions()
573 let guioptions_saved = &guioptions
574 let duration = '200m'
575
576 if has('win32')
577 " Default Value
578 set guioptions&
579 call assert_equal('egmrLtT', &guioptions)
580
581 else
582 " Default Value
583 set guioptions&
584 call assert_equal('aegimrLtT', &guioptions)
585
586 " To activate scrollbars of type 'L' or 'R'.
587 wincmd v
588 redraw!
589
590 " Remove all default GUI ornaments
591 set guioptions-=T
592 exec 'sleep' . duration
593 call assert_equal('aegimrLt', &guioptions)
594 set guioptions-=t
595 exec 'sleep' . duration
596 call assert_equal('aegimrL', &guioptions)
597 set guioptions-=L
598 exec 'sleep' . duration
599 call assert_equal('aegimr', &guioptions)
600 set guioptions-=r
601 exec 'sleep' . duration
602 call assert_equal('aegim', &guioptions)
603 set guioptions-=m
604 exec 'sleep' . duration
605 call assert_equal('aegi', &guioptions)
606
607 " Try non-default GUI ornaments
608 set guioptions+=l
609 exec 'sleep' . duration
610 call assert_equal('aegil', &guioptions)
611 set guioptions-=l
612 exec 'sleep' . duration
613 call assert_equal('aegi', &guioptions)
614
615 set guioptions+=R
616 exec 'sleep' . duration
617 call assert_equal('aegiR', &guioptions)
618 set guioptions-=R
619 exec 'sleep' . duration
620 call assert_equal('aegi', &guioptions)
621
622 set guioptions+=b
623 exec 'sleep' . duration
624 call assert_equal('aegib', &guioptions)
625 set guioptions+=h
626 exec 'sleep' . duration
627 call assert_equal('aegibh', &guioptions)
628 set guioptions-=h
629 exec 'sleep' . duration
630 call assert_equal('aegib', &guioptions)
631 set guioptions-=b
632 exec 'sleep' . duration
633 call assert_equal('aegi', &guioptions)
634
635 set guioptions+=v
636 exec 'sleep' . duration
637 call assert_equal('aegiv', &guioptions)
638 set guioptions-=v
639 exec 'sleep' . duration
640 call assert_equal('aegi', &guioptions)
641
642 if has('gui_motif')
643 set guioptions+=F
644 exec 'sleep' . duration
645 call assert_equal('aegiF', &guioptions)
646 set guioptions-=F
647 exec 'sleep' . duration
648 call assert_equal('aegi', &guioptions)
649 endif
650
651 " Restore GUI ornaments to the default state.
652 set guioptions+=m
653 exec 'sleep' . duration
654 call assert_equal('aegim', &guioptions)
655 set guioptions+=r
656 exec 'sleep' . duration
657 call assert_equal('aegimr', &guioptions)
658 set guioptions+=L
659 exec 'sleep' . duration
660 call assert_equal('aegimrL', &guioptions)
661 set guioptions+=t
662 exec 'sleep' . duration
663 call assert_equal('aegimrLt', &guioptions)
664 set guioptions+=T
665 exec 'sleep' . duration
666 call assert_equal("aegimrLtT", &guioptions)
667
668 wincmd o
669 redraw!
670 endif
671
672 let &guioptions = guioptions_saved
673endfunc
674
Bram Moolenaarab186732018-09-14 21:27:06 +0200675func Test_scrollbars()
676 new
677 " buffer with 200 lines
678 call setline(1, repeat(['one', 'two'], 100))
679 set guioptions+=rlb
680
681 " scroll to move line 11 at top, moves the cursor there
682 call test_scrollbar('left', 10, 0)
683 redraw
684 call assert_equal(1, winline())
685 call assert_equal(11, line('.'))
686
687 " scroll to move line 1 at top, cursor stays in line 11
688 call test_scrollbar('right', 0, 0)
689 redraw
690 call assert_equal(11, winline())
691 call assert_equal(11, line('.'))
692
693 set nowrap
694 call setline(11, repeat('x', 150))
695 redraw
696 call assert_equal(1, wincol())
697 call assert_equal(1, col('.'))
698
699 " scroll to character 11, cursor is moved
700 call test_scrollbar('hor', 10, 0)
701 redraw
702 call assert_equal(1, wincol())
703 call assert_equal(11, col('.'))
704
705 set guioptions&
706 set wrap&
707 bwipe!
708endfunc
709
Bram Moolenaar87748452017-03-12 17:10:33 +0100710func Test_set_guipty()
711 let guipty_saved = &guipty
712
713 " Default Value
714 set guipty&
715 call assert_equal(1, &guipty)
716
717 set noguipty
718 call assert_equal(0, &guipty)
719
720 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100721endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100722
Bram Moolenaar877e9572016-08-04 20:05:50 +0200723func Test_shell_command()
724 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200725 r !echo hello
726 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200727 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200728endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100729
Bram Moolenaar87748452017-03-12 17:10:33 +0100730func Test_syntax_colortest()
731 runtime syntax/colortest.vim
732 redraw!
733 sleep 200m
734 bwipe!
735endfunc
736
737func Test_set_term()
738 " It's enough to check the current value since setting 'term' to anything
739 " other than builtin_gui makes no sense at all.
740 call assert_equal('builtin_gui', &term)
741endfunc
742
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100743func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100744 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100745 call assert_true(v:windowid > 0)
746 else
747 call assert_equal(0, v:windowid)
748 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100749endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200750
751" Test "vim -g" and also the GUIEnter autocommand.
752func Test_gui_dash_g()
753 let cmd = GetVimCommand('Xscriptgui')
754 call writefile([""], "Xtestgui")
755 call writefile([
756 \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
757 \ 'au GUIEnter * qall',
758 \ ], 'Xscriptgui')
759 call system(cmd . ' -g')
760 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
761
762 call delete('Xscriptgui')
763 call delete('Xtestgui')
764endfunc
765
766" Test "vim -7" and also the GUIEnter autocommand.
767func Test_gui_dash_y()
768 let cmd = GetVimCommand('Xscriptgui')
769 call writefile([""], "Xtestgui")
770 call writefile([
771 \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
772 \ 'au GUIEnter * qall',
773 \ ], 'Xscriptgui')
774 call system(cmd . ' -y')
775 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
776
777 call delete('Xscriptgui')
778 call delete('Xtestgui')
779endfunc