blob: af4ce246c3fb2224bfb22d83eaeaaad85b8195c0 [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'))
Bram Moolenaar0e05de42020-03-25 22:23:46 +010078 call assert_equal('', getfontname('*'))
Bram Moolenaar6f785742017-02-06 22:11:55 +010079
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.'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200131 let vim_exe = GetVimCommand()
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100132 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200133 \ . vim_exe . ' --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
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200391 if has('win32')
392 " Invalid font names are accepted in GTK GUI
393 call assert_fails('set guifont=xa1bc23d7f', 'E596:')
394 endif
395
Bram Moolenaar43dded82017-02-09 16:06:17 +0100396 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100397 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100398 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100399 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100400
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100401 if !empty(skipped)
402 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100403 endif
404endfunc
405
Bram Moolenaar10434672017-02-12 19:59:08 +0100406func Test_set_guifontset()
Bram Moolenaarce90e362019-09-08 18:58:44 +0200407 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100408 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100409
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200410 call assert_fails('set guifontset=*', 'E597:')
411
Bram Moolenaarce90e362019-09-08 18:58:44 +0200412 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100413
Bram Moolenaarce90e362019-09-08 18:58:44 +0200414 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
415 " be chosen meticulously.
416 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100417
Bram Moolenaarce90e362019-09-08 18:58:44 +0200418 let font_aw70 = font_head . '-130-75-75-c-70'
419 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100420
Bram Moolenaarce90e362019-09-08 18:58:44 +0200421 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
422 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100423
Bram Moolenaarce90e362019-09-08 18:58:44 +0200424 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
425 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
426 let singleton = font_head . '-*'
427 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100428
Bram Moolenaarce90e362019-09-08 18:58:44 +0200429 " Second, among 'locales', look up such a locale that gets 'set
430 " guifontset=' to work successfully with every fontset specified with
431 " 'fontsets'.
432 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
433 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100434
Bram Moolenaarce90e362019-09-08 18:58:44 +0200435 let feasible = 0
436 for locale in locales
437 try
438 exec 'language ctype' locale
439 catch /^Vim\%((\a\+)\)\=:E197/
440 continue
441 endtry
442 let done = 0
443 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100444 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200445 exec 'set guifontset=' . fontset
446 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
447 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100448 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200449 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100450 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200451 if done == len(fontsets)
452 let feasible = 1
453 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100454 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200455 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100456
Bram Moolenaarce90e362019-09-08 18:58:44 +0200457 " Third, give a set of tests if it is found feasible.
458 if !feasible
459 let skipped = g:not_hosted
460 else
461 " N.B. 'v:ctype' has already been set to an appropriate value in the
462 " previous loop.
463 for fontset in fontsets
464 exec 'set guifontset=' . fontset
465 call assert_equal(fontset, &guifontset)
466 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100467 endif
468
Bram Moolenaarce90e362019-09-08 18:58:44 +0200469 " Finally, restore ctype.
470 exec 'language ctype' ctype_saved
471
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100472 if !empty(skipped)
473 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100474 endif
475endfunc
476
477func Test_set_guifontwide()
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200478 call assert_fails('set guifontwide=*', 'E533:')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100479 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100480
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100481 if !g:x11_based_gui
482 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100483 elseif has('gui_gtk')
484 let guifont_saved = &guifont
485 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100486
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100487 let fc_match = exepath('fc-match')
488 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100489 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100490 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100491 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
492 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
493 exec 'set guifontwide=' . fnameescape(wide)
494 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100495 endif
496
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100497 let &guifontwide = guifontwide_saved
498 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100499
500 elseif has('gui_athena') || has('gui_motif')
501 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100502 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100503 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100504 else
505 let encoding_saved = &encoding
506 let guifont_saved = &guifont
507 let guifontset_saved = &guifontset
508 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100509
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100510 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
511 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100512
513 set encoding=utf-8
514
515 " Case 1: guifontset is empty
516 set guifontset=
517
518 " Case 1-1: Automatic selection
519 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100520 exec 'set guifont=' . nfont
521 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100522
523 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100524 exec 'set guifontwide=' . wfont
525 exec 'set guifont=' . nfont
526 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100527
528 " Case 2: guifontset is invalid
529 try
530 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100531 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100532 catch
533 call assert_exception('E598')
534 endtry
535 " Set it to an invalid value brutally for preparation.
536 let &guifontset = '-*-notexist-*'
537
538 " Case 2-1: Automatic selection
539 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100540 exec 'set guifont=' . nfont
541 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100542
543 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100544 exec 'set guifontwide=' . wfont
545 exec 'set guifont=' . nfont
546 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100547
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100548 let &guifontwide = guifontwide_saved
549 let &guifontset = guifontset_saved
550 let &guifont = guifont_saved
551 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100552 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100553 endif
554
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100555 if !empty(skipped)
556 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100557 endif
558endfunc
559
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100560func Test_set_guiheadroom()
561 let skipped = ''
562
563 if !g:x11_based_gui
564 let skipped = g:not_supported . 'guiheadroom'
565 else
566 " Since this script is to be read together with '-U NONE', the default
567 " value must be preserved.
568 call assert_equal(50, &guiheadroom)
569 endif
570
571 if !empty(skipped)
572 throw skipped
573 endif
574endfunc
575
Bram Moolenaar87748452017-03-12 17:10:33 +0100576func Test_set_guioptions()
577 let guioptions_saved = &guioptions
578 let duration = '200m'
579
580 if has('win32')
581 " Default Value
582 set guioptions&
583 call assert_equal('egmrLtT', &guioptions)
584
585 else
586 " Default Value
587 set guioptions&
588 call assert_equal('aegimrLtT', &guioptions)
589
590 " To activate scrollbars of type 'L' or 'R'.
591 wincmd v
592 redraw!
593
594 " Remove all default GUI ornaments
595 set guioptions-=T
596 exec 'sleep' . duration
597 call assert_equal('aegimrLt', &guioptions)
598 set guioptions-=t
599 exec 'sleep' . duration
600 call assert_equal('aegimrL', &guioptions)
601 set guioptions-=L
602 exec 'sleep' . duration
603 call assert_equal('aegimr', &guioptions)
604 set guioptions-=r
605 exec 'sleep' . duration
606 call assert_equal('aegim', &guioptions)
607 set guioptions-=m
608 exec 'sleep' . duration
609 call assert_equal('aegi', &guioptions)
610
611 " Try non-default GUI ornaments
612 set guioptions+=l
613 exec 'sleep' . duration
614 call assert_equal('aegil', &guioptions)
615 set guioptions-=l
616 exec 'sleep' . duration
617 call assert_equal('aegi', &guioptions)
618
619 set guioptions+=R
620 exec 'sleep' . duration
621 call assert_equal('aegiR', &guioptions)
622 set guioptions-=R
623 exec 'sleep' . duration
624 call assert_equal('aegi', &guioptions)
625
626 set guioptions+=b
627 exec 'sleep' . duration
628 call assert_equal('aegib', &guioptions)
629 set guioptions+=h
630 exec 'sleep' . duration
631 call assert_equal('aegibh', &guioptions)
632 set guioptions-=h
633 exec 'sleep' . duration
634 call assert_equal('aegib', &guioptions)
635 set guioptions-=b
636 exec 'sleep' . duration
637 call assert_equal('aegi', &guioptions)
638
639 set guioptions+=v
640 exec 'sleep' . duration
641 call assert_equal('aegiv', &guioptions)
642 set guioptions-=v
643 exec 'sleep' . duration
644 call assert_equal('aegi', &guioptions)
645
646 if has('gui_motif')
647 set guioptions+=F
648 exec 'sleep' . duration
649 call assert_equal('aegiF', &guioptions)
650 set guioptions-=F
651 exec 'sleep' . duration
652 call assert_equal('aegi', &guioptions)
653 endif
654
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200655 if has('gui_gtk3')
656 set guioptions+=d
657 exec 'sleep' . duration
658 call assert_equal('aegid', &guioptions)
659 set guioptions-=d
660 exec 'sleep' . duration
661 call assert_equal('aegi', &guioptions)
662 endif
663
Bram Moolenaar87748452017-03-12 17:10:33 +0100664 " Restore GUI ornaments to the default state.
665 set guioptions+=m
666 exec 'sleep' . duration
667 call assert_equal('aegim', &guioptions)
668 set guioptions+=r
669 exec 'sleep' . duration
670 call assert_equal('aegimr', &guioptions)
671 set guioptions+=L
672 exec 'sleep' . duration
673 call assert_equal('aegimrL', &guioptions)
674 set guioptions+=t
675 exec 'sleep' . duration
676 call assert_equal('aegimrLt', &guioptions)
677 set guioptions+=T
678 exec 'sleep' . duration
679 call assert_equal("aegimrLtT", &guioptions)
680
681 wincmd o
682 redraw!
683 endif
684
685 let &guioptions = guioptions_saved
686endfunc
687
Bram Moolenaarab186732018-09-14 21:27:06 +0200688func Test_scrollbars()
689 new
690 " buffer with 200 lines
691 call setline(1, repeat(['one', 'two'], 100))
692 set guioptions+=rlb
693
694 " scroll to move line 11 at top, moves the cursor there
Bram Moolenaarce90e362019-09-08 18:58:44 +0200695 eval 10->test_scrollbar('left', 0)
Bram Moolenaarab186732018-09-14 21:27:06 +0200696 redraw
697 call assert_equal(1, winline())
698 call assert_equal(11, line('.'))
699
700 " scroll to move line 1 at top, cursor stays in line 11
701 call test_scrollbar('right', 0, 0)
702 redraw
703 call assert_equal(11, winline())
704 call assert_equal(11, line('.'))
705
706 set nowrap
707 call setline(11, repeat('x', 150))
708 redraw
709 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200710 set number
711 redraw
712 call assert_equal(5, wincol())
713 set nonumber
714 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200715 call assert_equal(1, col('.'))
716
717 " scroll to character 11, cursor is moved
718 call test_scrollbar('hor', 10, 0)
719 redraw
720 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200721 set number
722 redraw
723 call assert_equal(5, wincol())
724 set nonumber
725 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200726 call assert_equal(11, col('.'))
727
728 set guioptions&
729 set wrap&
730 bwipe!
731endfunc
732
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100733func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100734 CheckFeature quickfix
735
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100736 " Check Help menu exists
737 let help_menu = execute('menu Help')
738 call assert_match('Overview', help_menu)
739
740 " Check Help menu works
741 emenu Help.Overview
742 call assert_equal('help', &buftype)
743 close
744
745 " Check deleting menu doesn't cause trouble.
746 aunmenu Help
747 call assert_fails('menu Help', 'E329:')
748endfunc
749
Bram Moolenaar87748452017-03-12 17:10:33 +0100750func Test_set_guipty()
751 let guipty_saved = &guipty
752
753 " Default Value
754 set guipty&
755 call assert_equal(1, &guipty)
756
757 set noguipty
758 call assert_equal(0, &guipty)
759
760 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100761endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100762
Bram Moolenaarc701f322019-03-28 21:49:21 +0100763func Test_encoding_conversion()
764 " GTK supports conversion between 'encoding' and "utf-8"
765 if has('gui_gtk')
766 let encoding_saved = &encoding
767 set encoding=latin1
768
769 " would be nice if we could take a screenshot
770 intro
771 " sets the window title
772 edit SomeFile
773
774 let &encoding = encoding_saved
775 endif
776endfunc
777
Bram Moolenaar877e9572016-08-04 20:05:50 +0200778func Test_shell_command()
779 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200780 r !echo hello
781 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200782 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200783endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100784
Bram Moolenaar87748452017-03-12 17:10:33 +0100785func Test_syntax_colortest()
786 runtime syntax/colortest.vim
787 redraw!
788 sleep 200m
789 bwipe!
790endfunc
791
792func Test_set_term()
793 " It's enough to check the current value since setting 'term' to anything
794 " other than builtin_gui makes no sense at all.
795 call assert_equal('builtin_gui', &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200796 call assert_fails('set term=xterm', 'E530:')
Bram Moolenaar87748452017-03-12 17:10:33 +0100797endfunc
798
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100799func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100800 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100801 call assert_true(v:windowid > 0)
802 else
803 call assert_equal(0, v:windowid)
804 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100805endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200806
807" Test "vim -g" and also the GUIEnter autocommand.
808func Test_gui_dash_g()
809 let cmd = GetVimCommand('Xscriptgui')
810 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200811 let lines =<< trim END
812 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
813 au GUIEnter * qall
814 END
815 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200816 call system(cmd . ' -g')
817 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
818
819 call delete('Xscriptgui')
820 call delete('Xtestgui')
821endfunc
822
823" Test "vim -7" and also the GUIEnter autocommand.
824func Test_gui_dash_y()
825 let cmd = GetVimCommand('Xscriptgui')
826 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200827 let lines =<< trim END
828 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
829 au GUIEnter * qall
830 END
831 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200832 call system(cmd . ' -y')
833 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
834
835 call delete('Xscriptgui')
836 call delete('Xtestgui')
837endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100838
839" vim: shiftwidth=2 sts=2 expandtab