blob: e3ec4aadfdf689b0943d911b8669796ec8b7795c [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 Moolenaarce90e362019-09-08 18:58:44 +0200401 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100402 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100403
Bram Moolenaarce90e362019-09-08 18:58:44 +0200404 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100405
Bram Moolenaarce90e362019-09-08 18:58:44 +0200406 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
407 " be chosen meticulously.
408 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100409
Bram Moolenaarce90e362019-09-08 18:58:44 +0200410 let font_aw70 = font_head . '-130-75-75-c-70'
411 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100412
Bram Moolenaarce90e362019-09-08 18:58:44 +0200413 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
414 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100415
Bram Moolenaarce90e362019-09-08 18:58:44 +0200416 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
417 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
418 let singleton = font_head . '-*'
419 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100420
Bram Moolenaarce90e362019-09-08 18:58:44 +0200421 " Second, among 'locales', look up such a locale that gets 'set
422 " guifontset=' to work successfully with every fontset specified with
423 " 'fontsets'.
424 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
425 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100426
Bram Moolenaarce90e362019-09-08 18:58:44 +0200427 let feasible = 0
428 for locale in locales
429 try
430 exec 'language ctype' locale
431 catch /^Vim\%((\a\+)\)\=:E197/
432 continue
433 endtry
434 let done = 0
435 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100436 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200437 exec 'set guifontset=' . fontset
438 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
439 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100440 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200441 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100442 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200443 if done == len(fontsets)
444 let feasible = 1
445 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100446 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200447 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100448
Bram Moolenaarce90e362019-09-08 18:58:44 +0200449 " Third, give a set of tests if it is found feasible.
450 if !feasible
451 let skipped = g:not_hosted
452 else
453 " N.B. 'v:ctype' has already been set to an appropriate value in the
454 " previous loop.
455 for fontset in fontsets
456 exec 'set guifontset=' . fontset
457 call assert_equal(fontset, &guifontset)
458 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100459 endif
460
Bram Moolenaarce90e362019-09-08 18:58:44 +0200461 " Finally, restore ctype.
462 exec 'language ctype' ctype_saved
463
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100464 if !empty(skipped)
465 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100466 endif
467endfunc
468
469func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100470 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100471
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100472 if !g:x11_based_gui
473 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100474 elseif has('gui_gtk')
475 let guifont_saved = &guifont
476 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100477
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100478 let fc_match = exepath('fc-match')
479 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100480 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100481 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100482 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
483 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
484 exec 'set guifontwide=' . fnameescape(wide)
485 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100486 endif
487
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100488 let &guifontwide = guifontwide_saved
489 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100490
491 elseif has('gui_athena') || has('gui_motif')
492 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100493 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100494 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100495 else
496 let encoding_saved = &encoding
497 let guifont_saved = &guifont
498 let guifontset_saved = &guifontset
499 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100500
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100501 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
502 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100503
504 set encoding=utf-8
505
506 " Case 1: guifontset is empty
507 set guifontset=
508
509 " Case 1-1: Automatic selection
510 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100511 exec 'set guifont=' . nfont
512 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100513
514 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100515 exec 'set guifontwide=' . wfont
516 exec 'set guifont=' . nfont
517 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100518
519 " Case 2: guifontset is invalid
520 try
521 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100522 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100523 catch
524 call assert_exception('E598')
525 endtry
526 " Set it to an invalid value brutally for preparation.
527 let &guifontset = '-*-notexist-*'
528
529 " Case 2-1: Automatic selection
530 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100531 exec 'set guifont=' . nfont
532 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100533
534 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100535 exec 'set guifontwide=' . wfont
536 exec 'set guifont=' . nfont
537 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100538
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100539 let &guifontwide = guifontwide_saved
540 let &guifontset = guifontset_saved
541 let &guifont = guifont_saved
542 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100543 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100544 endif
545
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100546 if !empty(skipped)
547 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100548 endif
549endfunc
550
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100551func Test_set_guiheadroom()
552 let skipped = ''
553
554 if !g:x11_based_gui
555 let skipped = g:not_supported . 'guiheadroom'
556 else
557 " Since this script is to be read together with '-U NONE', the default
558 " value must be preserved.
559 call assert_equal(50, &guiheadroom)
560 endif
561
562 if !empty(skipped)
563 throw skipped
564 endif
565endfunc
566
Bram Moolenaar87748452017-03-12 17:10:33 +0100567func Test_set_guioptions()
568 let guioptions_saved = &guioptions
569 let duration = '200m'
570
571 if has('win32')
572 " Default Value
573 set guioptions&
574 call assert_equal('egmrLtT', &guioptions)
575
576 else
577 " Default Value
578 set guioptions&
579 call assert_equal('aegimrLtT', &guioptions)
580
581 " To activate scrollbars of type 'L' or 'R'.
582 wincmd v
583 redraw!
584
585 " Remove all default GUI ornaments
586 set guioptions-=T
587 exec 'sleep' . duration
588 call assert_equal('aegimrLt', &guioptions)
589 set guioptions-=t
590 exec 'sleep' . duration
591 call assert_equal('aegimrL', &guioptions)
592 set guioptions-=L
593 exec 'sleep' . duration
594 call assert_equal('aegimr', &guioptions)
595 set guioptions-=r
596 exec 'sleep' . duration
597 call assert_equal('aegim', &guioptions)
598 set guioptions-=m
599 exec 'sleep' . duration
600 call assert_equal('aegi', &guioptions)
601
602 " Try non-default GUI ornaments
603 set guioptions+=l
604 exec 'sleep' . duration
605 call assert_equal('aegil', &guioptions)
606 set guioptions-=l
607 exec 'sleep' . duration
608 call assert_equal('aegi', &guioptions)
609
610 set guioptions+=R
611 exec 'sleep' . duration
612 call assert_equal('aegiR', &guioptions)
613 set guioptions-=R
614 exec 'sleep' . duration
615 call assert_equal('aegi', &guioptions)
616
617 set guioptions+=b
618 exec 'sleep' . duration
619 call assert_equal('aegib', &guioptions)
620 set guioptions+=h
621 exec 'sleep' . duration
622 call assert_equal('aegibh', &guioptions)
623 set guioptions-=h
624 exec 'sleep' . duration
625 call assert_equal('aegib', &guioptions)
626 set guioptions-=b
627 exec 'sleep' . duration
628 call assert_equal('aegi', &guioptions)
629
630 set guioptions+=v
631 exec 'sleep' . duration
632 call assert_equal('aegiv', &guioptions)
633 set guioptions-=v
634 exec 'sleep' . duration
635 call assert_equal('aegi', &guioptions)
636
637 if has('gui_motif')
638 set guioptions+=F
639 exec 'sleep' . duration
640 call assert_equal('aegiF', &guioptions)
641 set guioptions-=F
642 exec 'sleep' . duration
643 call assert_equal('aegi', &guioptions)
644 endif
645
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200646 if has('gui_gtk3')
647 set guioptions+=d
648 exec 'sleep' . duration
649 call assert_equal('aegid', &guioptions)
650 set guioptions-=d
651 exec 'sleep' . duration
652 call assert_equal('aegi', &guioptions)
653 endif
654
Bram Moolenaar87748452017-03-12 17:10:33 +0100655 " Restore GUI ornaments to the default state.
656 set guioptions+=m
657 exec 'sleep' . duration
658 call assert_equal('aegim', &guioptions)
659 set guioptions+=r
660 exec 'sleep' . duration
661 call assert_equal('aegimr', &guioptions)
662 set guioptions+=L
663 exec 'sleep' . duration
664 call assert_equal('aegimrL', &guioptions)
665 set guioptions+=t
666 exec 'sleep' . duration
667 call assert_equal('aegimrLt', &guioptions)
668 set guioptions+=T
669 exec 'sleep' . duration
670 call assert_equal("aegimrLtT", &guioptions)
671
672 wincmd o
673 redraw!
674 endif
675
676 let &guioptions = guioptions_saved
677endfunc
678
Bram Moolenaarab186732018-09-14 21:27:06 +0200679func Test_scrollbars()
680 new
681 " buffer with 200 lines
682 call setline(1, repeat(['one', 'two'], 100))
683 set guioptions+=rlb
684
685 " scroll to move line 11 at top, moves the cursor there
Bram Moolenaarce90e362019-09-08 18:58:44 +0200686 eval 10->test_scrollbar('left', 0)
Bram Moolenaarab186732018-09-14 21:27:06 +0200687 redraw
688 call assert_equal(1, winline())
689 call assert_equal(11, line('.'))
690
691 " scroll to move line 1 at top, cursor stays in line 11
692 call test_scrollbar('right', 0, 0)
693 redraw
694 call assert_equal(11, winline())
695 call assert_equal(11, line('.'))
696
697 set nowrap
698 call setline(11, repeat('x', 150))
699 redraw
700 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200701 set number
702 redraw
703 call assert_equal(5, wincol())
704 set nonumber
705 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200706 call assert_equal(1, col('.'))
707
708 " scroll to character 11, cursor is moved
709 call test_scrollbar('hor', 10, 0)
710 redraw
711 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200712 set number
713 redraw
714 call assert_equal(5, wincol())
715 set nonumber
716 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200717 call assert_equal(11, col('.'))
718
719 set guioptions&
720 set wrap&
721 bwipe!
722endfunc
723
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100724func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100725 CheckFeature quickfix
726
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100727 " Check Help menu exists
728 let help_menu = execute('menu Help')
729 call assert_match('Overview', help_menu)
730
731 " Check Help menu works
732 emenu Help.Overview
733 call assert_equal('help', &buftype)
734 close
735
736 " Check deleting menu doesn't cause trouble.
737 aunmenu Help
738 call assert_fails('menu Help', 'E329:')
739endfunc
740
Bram Moolenaar87748452017-03-12 17:10:33 +0100741func Test_set_guipty()
742 let guipty_saved = &guipty
743
744 " Default Value
745 set guipty&
746 call assert_equal(1, &guipty)
747
748 set noguipty
749 call assert_equal(0, &guipty)
750
751 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100752endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100753
Bram Moolenaarc701f322019-03-28 21:49:21 +0100754func Test_encoding_conversion()
755 " GTK supports conversion between 'encoding' and "utf-8"
756 if has('gui_gtk')
757 let encoding_saved = &encoding
758 set encoding=latin1
759
760 " would be nice if we could take a screenshot
761 intro
762 " sets the window title
763 edit SomeFile
764
765 let &encoding = encoding_saved
766 endif
767endfunc
768
Bram Moolenaar877e9572016-08-04 20:05:50 +0200769func Test_shell_command()
770 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200771 r !echo hello
772 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200773 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200774endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100775
Bram Moolenaar87748452017-03-12 17:10:33 +0100776func Test_syntax_colortest()
777 runtime syntax/colortest.vim
778 redraw!
779 sleep 200m
780 bwipe!
781endfunc
782
783func Test_set_term()
784 " It's enough to check the current value since setting 'term' to anything
785 " other than builtin_gui makes no sense at all.
786 call assert_equal('builtin_gui', &term)
787endfunc
788
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100789func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100790 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100791 call assert_true(v:windowid > 0)
792 else
793 call assert_equal(0, v:windowid)
794 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100795endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200796
797" Test "vim -g" and also the GUIEnter autocommand.
798func Test_gui_dash_g()
799 let cmd = GetVimCommand('Xscriptgui')
800 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200801 let lines =<< trim END
802 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
803 au GUIEnter * qall
804 END
805 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200806 call system(cmd . ' -g')
807 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
808
809 call delete('Xscriptgui')
810 call delete('Xtestgui')
811endfunc
812
813" Test "vim -7" and also the GUIEnter autocommand.
814func Test_gui_dash_y()
815 let cmd = GetVimCommand('Xscriptgui')
816 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200817 let lines =<< trim END
818 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
819 au GUIEnter * qall
820 END
821 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200822 call system(cmd . ' -y')
823 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
824
825 call delete('Xscriptgui')
826 call delete('Xtestgui')
827endfunc