blob: 28782f00c087a44f528c19d85cc3331bfac5dbc3 [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()
Bram Moolenaaracc770a2020-04-12 15:11:06 +020034 call assert_equal('16777216', &t_Co)
35
Bram Moolenaar87748452017-03-12 17:10:33 +010036 let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
Bram Moolenaar60a68362018-04-30 15:40:48 +020037 let g:color_count = 0
38 augroup TestColors
39 au!
40 au ColorScheme * let g:color_count += 1| let g:after_colors = g:color_count
41 au ColorSchemePre * let g:color_count += 1 |let g:before_colors = g:color_count
42 augroup END
Bram Moolenaar87748452017-03-12 17:10:33 +010043
44 colorscheme torte
45 redraw!
Bram Moolenaar87748452017-03-12 17:10:33 +010046 call assert_equal('dark', &background)
Bram Moolenaar60a68362018-04-30 15:40:48 +020047 call assert_equal(1, g:before_colors)
48 call assert_equal(2, g:after_colors)
Bram Moolenaar6d4470b2019-01-08 21:05:51 +010049 call assert_equal("\ntorte", execute('colorscheme'))
50
51 let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g')
52 call assert_match("\nSearch xxx term=reverse ctermfg=0 ctermbg=12 gui=bold guifg=Black guibg=Red", a)
53
54 call assert_fails('colorscheme does_not_exist', 'E185:')
Bram Moolenaar87748452017-03-12 17:10:33 +010055
56 exec 'colorscheme' colorscheme_saved
Bram Moolenaar60a68362018-04-30 15:40:48 +020057 augroup TestColors
58 au!
59 augroup END
60 unlet g:color_count g:after_colors g:before_colors
Bram Moolenaar87748452017-03-12 17:10:33 +010061 redraw!
62endfunc
63
Bram Moolenaar6f785742017-02-06 22:11:55 +010064func Test_getfontname_with_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010065 let skipped = ''
66
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010067 if !g:x11_based_gui
68 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010069 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010070 " Invalid font name. The result should be an empty string.
71 call assert_equal('', getfontname('notexist'))
72
73 " Valid font name. This is usually the real name of 7x13 by default.
Bram Moolenaar87748452017-03-12 17:10:33 +010074 let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
75 call assert_match(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010076
77 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
78 " Invalid font name. The result should be the name plus the default size.
79 call assert_equal('notexist 10', getfontname('notexist'))
Bram Moolenaar0e05de42020-03-25 22:23:46 +010080 call assert_equal('', getfontname('*'))
Bram Moolenaar6f785742017-02-06 22:11:55 +010081
82 " Valid font name. This is usually the real name of Monospace by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010083 let fname = 'Bitstream Vera Sans Mono 12'
84 call assert_equal(fname, getfontname(fname))
85 endif
86
87 if !empty(skipped)
88 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010089 endif
90endfunc
91
92func Test_getfontname_without_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010093 let skipped = ''
94
95 let fname = getfontname()
96
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010097 if !g:x11_based_gui
98 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010099 elseif has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +0100100 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100101 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100102 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar87748452017-03-12 17:10:33 +0100103 " 'expected' is DFLT_FONT of gui_x11.c or its real name.
104 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
105 call assert_match(pat, fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100106 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
107 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100108 call assert_equal('Monospace 10', fname)
109 endif
110
111 if !empty(skipped)
112 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +0100113 endif
114endfunc
115
Bram Moolenaar87748452017-03-12 17:10:33 +0100116func Test_getwinpos()
117 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
118 call assert_true(getwinposx() >= 0)
119 call assert_true(getwinposy() >= 0)
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200120 call assert_equal([getwinposx(), getwinposy()], getwinpos())
Bram Moolenaar87748452017-03-12 17:10:33 +0100121endfunc
122
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100123func Test_quoteplus()
124 let skipped = ''
125
126 if !g:x11_based_gui
127 let skipped = g:not_supported . 'quoteplus'
128 else
129 let quoteplus_saved = @+
130
131 let test_call = 'Can you hear me?'
132 let test_response = 'Yes, I can.'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200133 let vim_exe = GetVimCommand()
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100134 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200135 \ . vim_exe . ' --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100136 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100137 let cmd = 'call test_ignore_error("E285") | '
138 \ . 'gui -f | '
139 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100140 \ . '\"+p'
141 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
142 \ . '\"+yis'
143 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100144 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100145
146 " Set the quoteplus register to test_call, and another gvim will launched.
147 " Then, it first tries to paste the content of its own quotedplus register
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200148 " onto it. Second, it tries to substitute test_response for the pasted
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100149 " sentence. If the sentence is identical to test_call, the substitution
150 " should succeed. Third, it tries to yank the result of the substitution
151 " to its own quoteplus register, and last it quits. When system()
152 " returns, the content of the quoteplus register should be identical to
153 " test_response if those quoteplus registers are synchronized properly
154 " with/through the X11 clipboard.
155 let @+ = test_call
156 call system(run_vimtest)
157 call assert_equal(test_response, @+)
158
159 let @+ = quoteplus_saved
160 endif
161
162 if !empty(skipped)
163 throw skipped
164 endif
165endfunc
166
Bram Moolenaar87748452017-03-12 17:10:33 +0100167func Test_set_background()
168 let background_saved = &background
169
170 set background&
171 call assert_equal('light', &background)
172
173 set background=dark
174 call assert_equal('dark', &background)
175
176 let &background = background_saved
177endfunc
178
Bram Moolenaard5841f22017-03-05 13:27:25 +0100179func Test_set_balloondelay()
180 if !exists('+balloondelay')
181 return
182 endif
183
184 let balloondelay_saved = &balloondelay
185
186 " Check if the default value is identical to that described in the manual.
187 set balloondelay&
188 call assert_equal(600, &balloondelay)
189
190 " Edge cases
191
192 " XXX This fact should be hidden so that people won't be tempted to write
193 " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source
194 " code.
195 set balloondelay=-1
196 call assert_equal(-1, &balloondelay)
197
198 " Though it's possible to interpret the zero delay to be 'as soon as
199 " possible' or even 'indefinite', its actual meaning depends on the GUI
200 " toolkit in use after all.
201 set balloondelay=0
202 call assert_equal(0, &balloondelay)
203
204 set balloondelay=1
205 call assert_equal(1, &balloondelay)
206
207 " Since p_bdelay is of type long currently, the upper bound can be
208 " impractically huge and machine-dependent. Practically, it's sufficient
Bram Moolenaar0f9ea222017-03-05 13:48:13 +0100209 " to check if balloondelay works with 0x7fffffff (32 bits) for now.
210 set balloondelay=2147483647
211 call assert_equal(2147483647, &balloondelay)
Bram Moolenaard5841f22017-03-05 13:27:25 +0100212
213 let &balloondelay = balloondelay_saved
214endfunc
215
216func Test_set_ballooneval()
217 if !exists('+ballooneval')
218 return
219 endif
220
221 let ballooneval_saved = &ballooneval
222
223 set ballooneval&
224 call assert_equal(0, &ballooneval)
225
226 set ballooneval
227 call assert_notequal(0, &ballooneval)
228
229 set noballooneval
230 call assert_equal(0, &ballooneval)
231
232 let &ballooneval = ballooneval_saved
233endfunc
234
235func Test_set_balloonexpr()
236 if !exists('+balloonexpr')
237 return
238 endif
239
240 let balloonexpr_saved = &balloonexpr
241
242 " Default value
243 set balloonexpr&
244 call assert_equal('', &balloonexpr)
245
246 " User-defined function
247 new
248 func MyBalloonExpr()
249 return 'Cursor is at line ' . v:beval_lnum .
250 \', column ' . v:beval_col .
251 \ ' of file ' . bufname(v:beval_bufnr) .
252 \ ' on word "' . v:beval_text . '"' .
253 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
254 endfunc
255 setl balloonexpr=MyBalloonExpr()
256 setl ballooneval
257 call assert_equal('MyBalloonExpr()', &balloonexpr)
258 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200259 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100260 " Also, check if textlock works as expected.
261 setl balloonexpr&
262 call assert_equal('', &balloonexpr)
263 delfunc MyBalloonExpr
264 bwipe!
265
266 " Multiline support
267 if has('balloon_multiline')
268 " Multiline balloon using NL
269 new
270 func MyBalloonFuncForMultilineUsingNL()
271 return "Multiline\nSuppported\nBalloon\nusing NL"
272 endfunc
273 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
274 setl ballooneval
275 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
276 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200277 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100278 " expected. Also, check if textlock works as expected.
279 setl balloonexpr&
280 delfunc MyBalloonFuncForMultilineUsingNL
281 bwipe!
282
283 " Multiline balloon using List
284 new
285 func MyBalloonFuncForMultilineUsingList()
286 return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
287 endfunc
288 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
289 setl ballooneval
290 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
291 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200292 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100293 " expected. Also, check if textlock works as expected.
294 setl balloonexpr&
295 delfunc MyBalloonFuncForMultilineUsingList
296 bwipe!
297 endif
298
299 let &balloonexpr = balloonexpr_saved
300endfunc
301
Bram Moolenaar87748452017-03-12 17:10:33 +0100302" Invalid arguments are tested with test_options in conjunction with segfaults
303" caused by them (Patch 8.0.0357, 24922ec233).
304func Test_set_guicursor()
305 let guicursor_saved = &guicursor
306
307 let default = [
308 \ "n-v-c:block-Cursor/lCursor",
309 \ "ve:ver35-Cursor",
310 \ "o:hor50-Cursor",
311 \ "i-ci:ver25-Cursor/lCursor",
312 \ "r-cr:hor20-Cursor/lCursor",
313 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
314 \ ]
315
316 " Default Value
317 set guicursor&
318 call assert_equal(join(default, ','), &guicursor)
319
320 " Argument List Example 1
321 let opt_list = copy(default)
322 let opt_list[0] = "n-c-v:block-nCursor"
323 exec "set guicursor=" . join(opt_list, ',')
324 call assert_equal(join(opt_list, ','), &guicursor)
325 unlet opt_list
326
327 " Argument List Example 2
328 let opt_list = copy(default)
329 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
330 exec "set guicursor=" . join(opt_list, ',')
331 call assert_equal(join(opt_list, ','), &guicursor)
332 unlet opt_list
333
334 " 'a' Mode
335 set guicursor&
336 let &guicursor .= ',a:blinkon0'
337 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
338
339 let &guicursor = guicursor_saved
340endfunc
341
Bram Moolenaar43dded82017-02-09 16:06:17 +0100342func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100343 let skipped = ''
344
345 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100346 if has('xfontset')
347 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100348 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100349 set guifontset=
350 endif
351
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100352 if !g:x11_based_gui
353 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100354 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100355 " Non-empty font list with invalid font names.
356 "
357 " This test is twofold: (1) It checks if the command fails as expected
358 " when there are no loadable fonts found in the list. (2) It checks if
359 " 'guifont' remains the same after the command loads none of the fonts
360 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100361 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100362 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100363 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100364
365 " Non-empty font list with a valid font name. Should pick up the first
366 " valid font.
367 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100368 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
369 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100370
371 " Empty list. Should fallback to the built-in default.
372 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100373 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
374 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100375
376 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
377 " For GTK, what we refer to as 'font names' in our manual are actually
378 " 'initial font patterns'. A valid font which matches the 'canonical font
379 " pattern' constructed from a given 'initial pattern' is to be looked up
380 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
381 " font names'.
382 "
383 " Non-empty list. Should always pick up the first element, no matter how
384 " strange it is, as explained above.
385 set guifont=(´・ω・`)\ 12,Courier\ 12
386 call assert_equal('(´・ω・`) 12', getfontname())
387
388 " Empty list. Should fallback to the built-in default.
389 set guifont=
390 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100391 endif
392
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200393 if has('win32')
394 " Invalid font names are accepted in GTK GUI
395 call assert_fails('set guifont=xa1bc23d7f', 'E596:')
396 endif
397
Bram Moolenaar43dded82017-02-09 16:06:17 +0100398 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100399 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100400 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100401 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100402
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100403 if !empty(skipped)
404 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100405 endif
406endfunc
407
Bram Moolenaar10434672017-02-12 19:59:08 +0100408func Test_set_guifontset()
Bram Moolenaarce90e362019-09-08 18:58:44 +0200409 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100410 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100411
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200412 call assert_fails('set guifontset=*', 'E597:')
413
Bram Moolenaarce90e362019-09-08 18:58:44 +0200414 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100415
Bram Moolenaarce90e362019-09-08 18:58:44 +0200416 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
417 " be chosen meticulously.
418 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100419
Bram Moolenaarce90e362019-09-08 18:58:44 +0200420 let font_aw70 = font_head . '-130-75-75-c-70'
421 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100422
Bram Moolenaarce90e362019-09-08 18:58:44 +0200423 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
424 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100425
Bram Moolenaarce90e362019-09-08 18:58:44 +0200426 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
427 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
428 let singleton = font_head . '-*'
429 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100430
Bram Moolenaarce90e362019-09-08 18:58:44 +0200431 " Second, among 'locales', look up such a locale that gets 'set
432 " guifontset=' to work successfully with every fontset specified with
433 " 'fontsets'.
434 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
435 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100436
Bram Moolenaarce90e362019-09-08 18:58:44 +0200437 let feasible = 0
438 for locale in locales
439 try
440 exec 'language ctype' locale
441 catch /^Vim\%((\a\+)\)\=:E197/
442 continue
443 endtry
444 let done = 0
445 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100446 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200447 exec 'set guifontset=' . fontset
448 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
449 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100450 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200451 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100452 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200453 if done == len(fontsets)
454 let feasible = 1
455 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100456 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200457 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100458
Bram Moolenaarce90e362019-09-08 18:58:44 +0200459 " Third, give a set of tests if it is found feasible.
460 if !feasible
461 let skipped = g:not_hosted
462 else
463 " N.B. 'v:ctype' has already been set to an appropriate value in the
464 " previous loop.
465 for fontset in fontsets
466 exec 'set guifontset=' . fontset
467 call assert_equal(fontset, &guifontset)
468 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100469 endif
470
Bram Moolenaarce90e362019-09-08 18:58:44 +0200471 " Finally, restore ctype.
472 exec 'language ctype' ctype_saved
473
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100474 if !empty(skipped)
475 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100476 endif
477endfunc
478
479func Test_set_guifontwide()
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200480 call assert_fails('set guifontwide=*', 'E533:')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100481 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100482
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100483 if !g:x11_based_gui
484 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100485 elseif has('gui_gtk')
486 let guifont_saved = &guifont
487 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100488
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100489 let fc_match = exepath('fc-match')
490 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100491 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100492 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100493 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
494 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
495 exec 'set guifontwide=' . fnameescape(wide)
496 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100497 endif
498
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100499 let &guifontwide = guifontwide_saved
500 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100501
502 elseif has('gui_athena') || has('gui_motif')
503 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100504 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100505 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100506 else
507 let encoding_saved = &encoding
508 let guifont_saved = &guifont
509 let guifontset_saved = &guifontset
510 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100511
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100512 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
513 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100514
515 set encoding=utf-8
516
517 " Case 1: guifontset is empty
518 set guifontset=
519
520 " Case 1-1: Automatic selection
521 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100522 exec 'set guifont=' . nfont
523 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100524
525 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100526 exec 'set guifontwide=' . wfont
527 exec 'set guifont=' . nfont
528 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100529
530 " Case 2: guifontset is invalid
531 try
532 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100533 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100534 catch
535 call assert_exception('E598')
536 endtry
537 " Set it to an invalid value brutally for preparation.
538 let &guifontset = '-*-notexist-*'
539
540 " Case 2-1: Automatic selection
541 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100542 exec 'set guifont=' . nfont
543 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100544
545 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100546 exec 'set guifontwide=' . wfont
547 exec 'set guifont=' . nfont
548 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100549
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100550 let &guifontwide = guifontwide_saved
551 let &guifontset = guifontset_saved
552 let &guifont = guifont_saved
553 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100554 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100555 endif
556
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100557 if !empty(skipped)
558 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100559 endif
560endfunc
561
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100562func Test_set_guiheadroom()
563 let skipped = ''
564
565 if !g:x11_based_gui
566 let skipped = g:not_supported . 'guiheadroom'
567 else
568 " Since this script is to be read together with '-U NONE', the default
569 " value must be preserved.
570 call assert_equal(50, &guiheadroom)
571 endif
572
573 if !empty(skipped)
574 throw skipped
575 endif
576endfunc
577
Bram Moolenaar87748452017-03-12 17:10:33 +0100578func Test_set_guioptions()
579 let guioptions_saved = &guioptions
580 let duration = '200m'
581
582 if has('win32')
583 " Default Value
584 set guioptions&
585 call assert_equal('egmrLtT', &guioptions)
586
587 else
588 " Default Value
589 set guioptions&
590 call assert_equal('aegimrLtT', &guioptions)
591
592 " To activate scrollbars of type 'L' or 'R'.
593 wincmd v
594 redraw!
595
596 " Remove all default GUI ornaments
597 set guioptions-=T
598 exec 'sleep' . duration
599 call assert_equal('aegimrLt', &guioptions)
600 set guioptions-=t
601 exec 'sleep' . duration
602 call assert_equal('aegimrL', &guioptions)
603 set guioptions-=L
604 exec 'sleep' . duration
605 call assert_equal('aegimr', &guioptions)
606 set guioptions-=r
607 exec 'sleep' . duration
608 call assert_equal('aegim', &guioptions)
609 set guioptions-=m
610 exec 'sleep' . duration
611 call assert_equal('aegi', &guioptions)
612
613 " Try non-default GUI ornaments
614 set guioptions+=l
615 exec 'sleep' . duration
616 call assert_equal('aegil', &guioptions)
617 set guioptions-=l
618 exec 'sleep' . duration
619 call assert_equal('aegi', &guioptions)
620
621 set guioptions+=R
622 exec 'sleep' . duration
623 call assert_equal('aegiR', &guioptions)
624 set guioptions-=R
625 exec 'sleep' . duration
626 call assert_equal('aegi', &guioptions)
627
628 set guioptions+=b
629 exec 'sleep' . duration
630 call assert_equal('aegib', &guioptions)
631 set guioptions+=h
632 exec 'sleep' . duration
633 call assert_equal('aegibh', &guioptions)
634 set guioptions-=h
635 exec 'sleep' . duration
636 call assert_equal('aegib', &guioptions)
637 set guioptions-=b
638 exec 'sleep' . duration
639 call assert_equal('aegi', &guioptions)
640
641 set guioptions+=v
642 exec 'sleep' . duration
643 call assert_equal('aegiv', &guioptions)
644 set guioptions-=v
645 exec 'sleep' . duration
646 call assert_equal('aegi', &guioptions)
647
648 if has('gui_motif')
649 set guioptions+=F
650 exec 'sleep' . duration
651 call assert_equal('aegiF', &guioptions)
652 set guioptions-=F
653 exec 'sleep' . duration
654 call assert_equal('aegi', &guioptions)
655 endif
656
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200657 if has('gui_gtk3')
658 set guioptions+=d
659 exec 'sleep' . duration
660 call assert_equal('aegid', &guioptions)
661 set guioptions-=d
662 exec 'sleep' . duration
663 call assert_equal('aegi', &guioptions)
664 endif
665
Bram Moolenaar87748452017-03-12 17:10:33 +0100666 " Restore GUI ornaments to the default state.
667 set guioptions+=m
668 exec 'sleep' . duration
669 call assert_equal('aegim', &guioptions)
670 set guioptions+=r
671 exec 'sleep' . duration
672 call assert_equal('aegimr', &guioptions)
673 set guioptions+=L
674 exec 'sleep' . duration
675 call assert_equal('aegimrL', &guioptions)
676 set guioptions+=t
677 exec 'sleep' . duration
678 call assert_equal('aegimrLt', &guioptions)
679 set guioptions+=T
680 exec 'sleep' . duration
681 call assert_equal("aegimrLtT", &guioptions)
682
683 wincmd o
684 redraw!
685 endif
686
687 let &guioptions = guioptions_saved
688endfunc
689
Bram Moolenaarab186732018-09-14 21:27:06 +0200690func Test_scrollbars()
691 new
692 " buffer with 200 lines
693 call setline(1, repeat(['one', 'two'], 100))
694 set guioptions+=rlb
695
696 " scroll to move line 11 at top, moves the cursor there
Bram Moolenaarce90e362019-09-08 18:58:44 +0200697 eval 10->test_scrollbar('left', 0)
Bram Moolenaarab186732018-09-14 21:27:06 +0200698 redraw
699 call assert_equal(1, winline())
700 call assert_equal(11, line('.'))
701
702 " scroll to move line 1 at top, cursor stays in line 11
703 call test_scrollbar('right', 0, 0)
704 redraw
705 call assert_equal(11, winline())
706 call assert_equal(11, line('.'))
707
708 set nowrap
709 call setline(11, repeat('x', 150))
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(1, col('.'))
718
719 " scroll to character 11, cursor is moved
720 call test_scrollbar('hor', 10, 0)
721 redraw
722 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200723 set number
724 redraw
725 call assert_equal(5, wincol())
726 set nonumber
727 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200728 call assert_equal(11, col('.'))
729
730 set guioptions&
731 set wrap&
732 bwipe!
733endfunc
734
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100735func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100736 CheckFeature quickfix
737
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100738 " Check Help menu exists
739 let help_menu = execute('menu Help')
740 call assert_match('Overview', help_menu)
741
742 " Check Help menu works
743 emenu Help.Overview
744 call assert_equal('help', &buftype)
745 close
746
747 " Check deleting menu doesn't cause trouble.
748 aunmenu Help
749 call assert_fails('menu Help', 'E329:')
750endfunc
751
Bram Moolenaar87748452017-03-12 17:10:33 +0100752func Test_set_guipty()
753 let guipty_saved = &guipty
754
755 " Default Value
756 set guipty&
757 call assert_equal(1, &guipty)
758
759 set noguipty
760 call assert_equal(0, &guipty)
761
762 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100763endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100764
Bram Moolenaarc701f322019-03-28 21:49:21 +0100765func Test_encoding_conversion()
766 " GTK supports conversion between 'encoding' and "utf-8"
767 if has('gui_gtk')
768 let encoding_saved = &encoding
769 set encoding=latin1
770
771 " would be nice if we could take a screenshot
772 intro
773 " sets the window title
774 edit SomeFile
775
776 let &encoding = encoding_saved
777 endif
778endfunc
779
Bram Moolenaar877e9572016-08-04 20:05:50 +0200780func Test_shell_command()
781 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200782 r !echo hello
783 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200784 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200785endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100786
Bram Moolenaar87748452017-03-12 17:10:33 +0100787func Test_syntax_colortest()
788 runtime syntax/colortest.vim
789 redraw!
790 sleep 200m
791 bwipe!
792endfunc
793
794func Test_set_term()
795 " It's enough to check the current value since setting 'term' to anything
796 " other than builtin_gui makes no sense at all.
797 call assert_equal('builtin_gui', &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200798 call assert_fails('set term=xterm', 'E530:')
Bram Moolenaar87748452017-03-12 17:10:33 +0100799endfunc
800
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100801func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100802 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100803 call assert_true(v:windowid > 0)
804 else
805 call assert_equal(0, v:windowid)
806 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100807endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200808
809" Test "vim -g" and also the GUIEnter autocommand.
810func Test_gui_dash_g()
811 let cmd = GetVimCommand('Xscriptgui')
812 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200813 let lines =<< trim END
814 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
815 au GUIEnter * qall
816 END
817 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200818 call system(cmd . ' -g')
819 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
820
821 call delete('Xscriptgui')
822 call delete('Xtestgui')
823endfunc
824
825" Test "vim -7" and also the GUIEnter autocommand.
826func Test_gui_dash_y()
827 let cmd = GetVimCommand('Xscriptgui')
828 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200829 let lines =<< trim END
830 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
831 au GUIEnter * qall
832 END
833 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200834 call system(cmd . ' -y')
835 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
836
837 call delete('Xscriptgui')
838 call delete('Xtestgui')
839endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100840
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200841" Test for "!" option in 'guioptions'. Use a terminal for running external
842" commands
843func Test_gui_run_cmd_in_terminal()
Bram Moolenaar4457e1d2020-05-15 22:46:44 +0200844 CheckFeature terminal
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200845 let save_guioptions = &guioptions
846 set guioptions+=!
847 if has('win32')
848 let cmd = 'type'
849 else
850 " assume all the other systems have a cat command
851 let cmd = 'cat'
852 endif
853 let cmd = ':silent !' . cmd . " test_gui.vim\<CR>\<CR>"
854 call feedkeys(cmd, 'xt')
855 " TODO: how to check that the command ran in a separate terminal?
856 " Maybe check for $TERM (dumb vs xterm) in the spawned shell?
857 let &guioptions = save_guioptions
858endfunc
859
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100860" vim: shiftwidth=2 sts=2 expandtab