blob: 0d504d5491d79efbcd23e2a77a9e1e963a3f7aa6 [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()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020027 CheckFeature balloon_eval
28 " This won't do anything but must not crash either.
29 call balloon_show('hi!')
Bram Moolenaard5841f22017-03-05 13:27:25 +010030endfunc
31
Bram Moolenaar87748452017-03-12 17:10:33 +010032func Test_colorscheme()
Bram Moolenaaracc770a2020-04-12 15:11:06 +020033 call assert_equal('16777216', &t_Co)
34
Bram Moolenaar87748452017-03-12 17:10:33 +010035 let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
Bram Moolenaar60a68362018-04-30 15:40:48 +020036 let g:color_count = 0
37 augroup TestColors
38 au!
39 au ColorScheme * let g:color_count += 1| let g:after_colors = g:color_count
40 au ColorSchemePre * let g:color_count += 1 |let g:before_colors = g:color_count
41 augroup END
Bram Moolenaar87748452017-03-12 17:10:33 +010042
43 colorscheme torte
44 redraw!
Bram Moolenaar87748452017-03-12 17:10:33 +010045 call assert_equal('dark', &background)
Bram Moolenaar60a68362018-04-30 15:40:48 +020046 call assert_equal(1, g:before_colors)
47 call assert_equal(2, g:after_colors)
Bram Moolenaar6d4470b2019-01-08 21:05:51 +010048 call assert_equal("\ntorte", execute('colorscheme'))
49
50 let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g')
51 call assert_match("\nSearch xxx term=reverse ctermfg=0 ctermbg=12 gui=bold guifg=Black guibg=Red", a)
52
53 call assert_fails('colorscheme does_not_exist', 'E185:')
Bram Moolenaar87748452017-03-12 17:10:33 +010054
55 exec 'colorscheme' colorscheme_saved
Bram Moolenaar60a68362018-04-30 15:40:48 +020056 augroup TestColors
57 au!
58 augroup END
59 unlet g:color_count g:after_colors g:before_colors
Bram Moolenaar87748452017-03-12 17:10:33 +010060 redraw!
61endfunc
62
Bram Moolenaar6f785742017-02-06 22:11:55 +010063func Test_getfontname_with_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010064 let skipped = ''
65
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010066 if !g:x11_based_gui
67 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010068 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010069 " Invalid font name. The result should be an empty string.
70 call assert_equal('', getfontname('notexist'))
71
72 " Valid font name. This is usually the real name of 7x13 by default.
Bram Moolenaar87748452017-03-12 17:10:33 +010073 let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
74 call assert_match(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010075
76 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
77 " Invalid font name. The result should be the name plus the default size.
78 call assert_equal('notexist 10', getfontname('notexist'))
Bram Moolenaar0e05de42020-03-25 22:23:46 +010079 call assert_equal('', getfontname('*'))
Bram Moolenaar6f785742017-02-06 22:11:55 +010080
81 " Valid font name. This is usually the real name of Monospace by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010082 let fname = 'Bitstream Vera Sans Mono 12'
83 call assert_equal(fname, getfontname(fname))
84 endif
85
86 if !empty(skipped)
87 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010088 endif
89endfunc
90
91func Test_getfontname_without_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010092 let skipped = ''
93
94 let fname = getfontname()
95
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010096 if !g:x11_based_gui
97 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010098 elseif has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +010099 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100100 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100101 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar87748452017-03-12 17:10:33 +0100102 " 'expected' is DFLT_FONT of gui_x11.c or its real name.
103 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
104 call assert_match(pat, fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100105 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
106 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100107 call assert_equal('Monospace 10', fname)
108 endif
109
110 if !empty(skipped)
111 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +0100112 endif
113endfunc
114
Bram Moolenaar87748452017-03-12 17:10:33 +0100115func Test_getwinpos()
116 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
117 call assert_true(getwinposx() >= 0)
118 call assert_true(getwinposy() >= 0)
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200119 call assert_equal([getwinposx(), getwinposy()], getwinpos())
Bram Moolenaar87748452017-03-12 17:10:33 +0100120endfunc
121
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100122func Test_quoteplus()
123 let skipped = ''
124
125 if !g:x11_based_gui
126 let skipped = g:not_supported . 'quoteplus'
127 else
128 let quoteplus_saved = @+
129
130 let test_call = 'Can you hear me?'
131 let test_response = 'Yes, I can.'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200132 let vim_exe = GetVimCommand()
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100133 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
Bram Moolenaar93344c22019-08-14 21:12:05 +0200134 \ . vim_exe . ' --noplugin --not-a-term -c ''%s'''
Bram Moolenaarf8ab1b12017-03-01 18:30:34 +0100135 " Ignore the "failed to create input context" error.
Bram Moolenaar24d76362017-03-04 13:32:10 +0100136 let cmd = 'call test_ignore_error("E285") | '
137 \ . 'gui -f | '
138 \ . 'call feedkeys("'
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100139 \ . '\"+p'
140 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
141 \ . '\"+yis'
142 \ . ':q!\<CR>", "tx")'
Bram Moolenaar24d76362017-03-04 13:32:10 +0100143 let run_vimtest = printf(testee, cmd)
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100144
145 " Set the quoteplus register to test_call, and another gvim will launched.
146 " Then, it first tries to paste the content of its own quotedplus register
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200147 " onto it. Second, it tries to substitute test_response for the pasted
Bram Moolenaar5074a0e2017-02-26 15:08:21 +0100148 " sentence. If the sentence is identical to test_call, the substitution
149 " should succeed. Third, it tries to yank the result of the substitution
150 " to its own quoteplus register, and last it quits. When system()
151 " returns, the content of the quoteplus register should be identical to
152 " test_response if those quoteplus registers are synchronized properly
153 " with/through the X11 clipboard.
154 let @+ = test_call
155 call system(run_vimtest)
156 call assert_equal(test_response, @+)
157
158 let @+ = quoteplus_saved
159 endif
160
161 if !empty(skipped)
162 throw skipped
163 endif
164endfunc
165
Bram Moolenaar87748452017-03-12 17:10:33 +0100166func Test_set_background()
167 let background_saved = &background
168
169 set background&
170 call assert_equal('light', &background)
171
172 set background=dark
173 call assert_equal('dark', &background)
174
175 let &background = background_saved
176endfunc
177
Bram Moolenaard5841f22017-03-05 13:27:25 +0100178func Test_set_balloondelay()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200179 CheckOption balloondelay
Bram Moolenaard5841f22017-03-05 13:27:25 +0100180
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()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200214 CheckOption ballooneval
Bram Moolenaard5841f22017-03-05 13:27:25 +0100215
216 let ballooneval_saved = &ballooneval
217
218 set ballooneval&
219 call assert_equal(0, &ballooneval)
220
221 set ballooneval
222 call assert_notequal(0, &ballooneval)
223
224 set noballooneval
225 call assert_equal(0, &ballooneval)
226
227 let &ballooneval = ballooneval_saved
228endfunc
229
230func Test_set_balloonexpr()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200231 CheckOption balloonexpr
Bram Moolenaard5841f22017-03-05 13:27:25 +0100232
233 let balloonexpr_saved = &balloonexpr
234
235 " Default value
236 set balloonexpr&
237 call assert_equal('', &balloonexpr)
238
239 " User-defined function
240 new
241 func MyBalloonExpr()
242 return 'Cursor is at line ' . v:beval_lnum .
243 \', column ' . v:beval_col .
244 \ ' of file ' . bufname(v:beval_bufnr) .
245 \ ' on word "' . v:beval_text . '"' .
246 \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')'
247 endfunc
248 setl balloonexpr=MyBalloonExpr()
249 setl ballooneval
250 call assert_equal('MyBalloonExpr()', &balloonexpr)
251 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200252 " and check if the content of the balloon is the same as what is expected.
Bram Moolenaard5841f22017-03-05 13:27:25 +0100253 " Also, check if textlock works as expected.
254 setl balloonexpr&
255 call assert_equal('', &balloonexpr)
256 delfunc MyBalloonExpr
257 bwipe!
258
259 " Multiline support
260 if has('balloon_multiline')
261 " Multiline balloon using NL
262 new
263 func MyBalloonFuncForMultilineUsingNL()
264 return "Multiline\nSuppported\nBalloon\nusing NL"
265 endfunc
266 setl balloonexpr=MyBalloonFuncForMultilineUsingNL()
267 setl ballooneval
268 call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr)
269 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200270 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100271 " expected. Also, check if textlock works as expected.
272 setl balloonexpr&
273 delfunc MyBalloonFuncForMultilineUsingNL
274 bwipe!
275
276 " Multiline balloon using List
277 new
278 func MyBalloonFuncForMultilineUsingList()
279 return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ]
280 endfunc
281 setl balloonexpr=MyBalloonFuncForMultilineUsingList()
282 setl ballooneval
283 call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr)
284 " TODO Read non-empty text, place the pointer at a character of a word,
Bram Moolenaar027df2a2018-05-14 21:31:08 +0200285 " and check if the content of the balloon is the same as what is
Bram Moolenaard5841f22017-03-05 13:27:25 +0100286 " expected. Also, check if textlock works as expected.
287 setl balloonexpr&
288 delfunc MyBalloonFuncForMultilineUsingList
289 bwipe!
290 endif
291
292 let &balloonexpr = balloonexpr_saved
293endfunc
294
Bram Moolenaar87748452017-03-12 17:10:33 +0100295" Invalid arguments are tested with test_options in conjunction with segfaults
296" caused by them (Patch 8.0.0357, 24922ec233).
297func Test_set_guicursor()
298 let guicursor_saved = &guicursor
299
300 let default = [
301 \ "n-v-c:block-Cursor/lCursor",
302 \ "ve:ver35-Cursor",
303 \ "o:hor50-Cursor",
304 \ "i-ci:ver25-Cursor/lCursor",
305 \ "r-cr:hor20-Cursor/lCursor",
306 \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
307 \ ]
308
309 " Default Value
310 set guicursor&
311 call assert_equal(join(default, ','), &guicursor)
312
313 " Argument List Example 1
314 let opt_list = copy(default)
315 let opt_list[0] = "n-c-v:block-nCursor"
316 exec "set guicursor=" . join(opt_list, ',')
317 call assert_equal(join(opt_list, ','), &guicursor)
318 unlet opt_list
319
320 " Argument List Example 2
321 let opt_list = copy(default)
322 let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
323 exec "set guicursor=" . join(opt_list, ',')
324 call assert_equal(join(opt_list, ','), &guicursor)
325 unlet opt_list
326
327 " 'a' Mode
328 set guicursor&
329 let &guicursor .= ',a:blinkon0'
330 call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
331
332 let &guicursor = guicursor_saved
333endfunc
334
Bram Moolenaar43dded82017-02-09 16:06:17 +0100335func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100336 let skipped = ''
337
338 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100339 if has('xfontset')
340 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100341 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100342 set guifontset=
343 endif
344
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100345 if !g:x11_based_gui
346 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100347 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100348 " Non-empty font list with invalid font names.
349 "
350 " This test is twofold: (1) It checks if the command fails as expected
351 " when there are no loadable fonts found in the list. (2) It checks if
352 " 'guifont' remains the same after the command loads none of the fonts
353 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100354 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100355 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100356 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100357
358 " Non-empty font list with a valid font name. Should pick up the first
359 " valid font.
360 set guifont=-notexist1-*,fixed,-notexist2-*
Bram Moolenaar87748452017-03-12 17:10:33 +0100361 let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
362 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100363
364 " Empty list. Should fallback to the built-in default.
365 set guifont=
Bram Moolenaar87748452017-03-12 17:10:33 +0100366 let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
367 call assert_match(pat, getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100368
369 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
370 " For GTK, what we refer to as 'font names' in our manual are actually
371 " 'initial font patterns'. A valid font which matches the 'canonical font
372 " pattern' constructed from a given 'initial pattern' is to be looked up
373 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
374 " font names'.
375 "
376 " Non-empty list. Should always pick up the first element, no matter how
377 " strange it is, as explained above.
378 set guifont=(´・ω・`)\ 12,Courier\ 12
379 call assert_equal('(´・ω・`) 12', getfontname())
380
381 " Empty list. Should fallback to the built-in default.
382 set guifont=
383 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100384 endif
385
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200386 if has('win32')
387 " Invalid font names are accepted in GTK GUI
388 call assert_fails('set guifont=xa1bc23d7f', 'E596:')
Bram Moolenaar2c78a772020-12-09 12:01:03 +0100389 endif
Bram Moolenaar1b3e0722020-12-08 21:12:40 +0100390
Bram Moolenaar2c78a772020-12-09 12:01:03 +0100391 if exists('+renderoptions')
Bram Moolenaar1b3e0722020-12-08 21:12:40 +0100392 " doing this four times used to cause a crash
Bram Moolenaar2c78a772020-12-09 12:01:03 +0100393 set renderoptions=type:directx
394 for i in range(5)
395 set guifont=
396 endfor
397 set renderoptions=
398 for i in range(5)
399 set guifont=
400 endfor
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200401 endif
402
Bram Moolenaar43dded82017-02-09 16:06:17 +0100403 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100404 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100405 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100406 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100407
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100408 if !empty(skipped)
409 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100410 endif
411endfunc
412
Bram Moolenaar10434672017-02-12 19:59:08 +0100413func Test_set_guifontset()
Bram Moolenaarce90e362019-09-08 18:58:44 +0200414 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100415 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100416
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200417 call assert_fails('set guifontset=*', 'E597:')
418
Bram Moolenaarce90e362019-09-08 18:58:44 +0200419 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100420
Bram Moolenaarce90e362019-09-08 18:58:44 +0200421 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
422 " be chosen meticulously.
423 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100424
Bram Moolenaarce90e362019-09-08 18:58:44 +0200425 let font_aw70 = font_head . '-130-75-75-c-70'
426 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100427
Bram Moolenaarce90e362019-09-08 18:58:44 +0200428 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
429 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100430
Bram Moolenaarce90e362019-09-08 18:58:44 +0200431 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
432 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
433 let singleton = font_head . '-*'
434 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100435
Bram Moolenaarce90e362019-09-08 18:58:44 +0200436 " Second, among 'locales', look up such a locale that gets 'set
437 " guifontset=' to work successfully with every fontset specified with
438 " 'fontsets'.
439 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
440 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100441
Bram Moolenaarce90e362019-09-08 18:58:44 +0200442 let feasible = 0
443 for locale in locales
444 try
445 exec 'language ctype' locale
446 catch /^Vim\%((\a\+)\)\=:E197/
447 continue
448 endtry
449 let done = 0
450 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100451 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200452 exec 'set guifontset=' . fontset
453 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
454 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100455 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200456 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100457 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200458 if done == len(fontsets)
459 let feasible = 1
460 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100461 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200462 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100463
Bram Moolenaarce90e362019-09-08 18:58:44 +0200464 " Third, give a set of tests if it is found feasible.
465 if !feasible
466 let skipped = g:not_hosted
467 else
468 " N.B. 'v:ctype' has already been set to an appropriate value in the
469 " previous loop.
470 for fontset in fontsets
471 exec 'set guifontset=' . fontset
472 call assert_equal(fontset, &guifontset)
473 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100474 endif
475
Bram Moolenaarce90e362019-09-08 18:58:44 +0200476 " Finally, restore ctype.
477 exec 'language ctype' ctype_saved
478
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100479 if !empty(skipped)
480 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100481 endif
482endfunc
483
484func Test_set_guifontwide()
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200485 call assert_fails('set guifontwide=*', 'E533:')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100486 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100487
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100488 if !g:x11_based_gui
489 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100490 elseif has('gui_gtk')
491 let guifont_saved = &guifont
492 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100493
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100494 let fc_match = exepath('fc-match')
495 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100496 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100497 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100498 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
499 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
500 exec 'set guifontwide=' . fnameescape(wide)
501 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100502 endif
503
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100504 let &guifontwide = guifontwide_saved
505 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100506
507 elseif has('gui_athena') || has('gui_motif')
508 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100509 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100510 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100511 else
512 let encoding_saved = &encoding
513 let guifont_saved = &guifont
514 let guifontset_saved = &guifontset
515 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100516
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100517 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
518 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100519
520 set encoding=utf-8
521
522 " Case 1: guifontset is empty
523 set guifontset=
524
525 " Case 1-1: Automatic selection
526 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100527 exec 'set guifont=' . nfont
528 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100529
530 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100531 exec 'set guifontwide=' . wfont
532 exec 'set guifont=' . nfont
533 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100534
535 " Case 2: guifontset is invalid
536 try
537 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100538 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100539 catch
Bram Moolenaare2e40752020-09-04 21:18:46 +0200540 call assert_exception('E598:')
Bram Moolenaar10434672017-02-12 19:59:08 +0100541 endtry
542 " Set it to an invalid value brutally for preparation.
543 let &guifontset = '-*-notexist-*'
544
545 " Case 2-1: Automatic selection
546 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100547 exec 'set guifont=' . nfont
548 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100549
550 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100551 exec 'set guifontwide=' . wfont
552 exec 'set guifont=' . nfont
553 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100554
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100555 let &guifontwide = guifontwide_saved
556 let &guifontset = guifontset_saved
557 let &guifont = guifont_saved
558 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100559 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100560 endif
561
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100562 if !empty(skipped)
563 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100564 endif
565endfunc
566
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100567func Test_set_guiheadroom()
568 let skipped = ''
569
570 if !g:x11_based_gui
571 let skipped = g:not_supported . 'guiheadroom'
572 else
573 " Since this script is to be read together with '-U NONE', the default
574 " value must be preserved.
575 call assert_equal(50, &guiheadroom)
576 endif
577
578 if !empty(skipped)
579 throw skipped
580 endif
581endfunc
582
Bram Moolenaar87748452017-03-12 17:10:33 +0100583func Test_set_guioptions()
584 let guioptions_saved = &guioptions
585 let duration = '200m'
586
587 if has('win32')
588 " Default Value
589 set guioptions&
590 call assert_equal('egmrLtT', &guioptions)
591
592 else
593 " Default Value
594 set guioptions&
595 call assert_equal('aegimrLtT', &guioptions)
596
597 " To activate scrollbars of type 'L' or 'R'.
598 wincmd v
599 redraw!
600
601 " Remove all default GUI ornaments
602 set guioptions-=T
603 exec 'sleep' . duration
604 call assert_equal('aegimrLt', &guioptions)
605 set guioptions-=t
606 exec 'sleep' . duration
607 call assert_equal('aegimrL', &guioptions)
608 set guioptions-=L
609 exec 'sleep' . duration
610 call assert_equal('aegimr', &guioptions)
611 set guioptions-=r
612 exec 'sleep' . duration
613 call assert_equal('aegim', &guioptions)
614 set guioptions-=m
615 exec 'sleep' . duration
616 call assert_equal('aegi', &guioptions)
617
618 " Try non-default GUI ornaments
619 set guioptions+=l
620 exec 'sleep' . duration
621 call assert_equal('aegil', &guioptions)
622 set guioptions-=l
623 exec 'sleep' . duration
624 call assert_equal('aegi', &guioptions)
625
626 set guioptions+=R
627 exec 'sleep' . duration
628 call assert_equal('aegiR', &guioptions)
629 set guioptions-=R
630 exec 'sleep' . duration
631 call assert_equal('aegi', &guioptions)
632
633 set guioptions+=b
634 exec 'sleep' . duration
635 call assert_equal('aegib', &guioptions)
636 set guioptions+=h
637 exec 'sleep' . duration
638 call assert_equal('aegibh', &guioptions)
639 set guioptions-=h
640 exec 'sleep' . duration
641 call assert_equal('aegib', &guioptions)
642 set guioptions-=b
643 exec 'sleep' . duration
644 call assert_equal('aegi', &guioptions)
645
646 set guioptions+=v
647 exec 'sleep' . duration
648 call assert_equal('aegiv', &guioptions)
649 set guioptions-=v
650 exec 'sleep' . duration
651 call assert_equal('aegi', &guioptions)
652
653 if has('gui_motif')
654 set guioptions+=F
655 exec 'sleep' . duration
656 call assert_equal('aegiF', &guioptions)
657 set guioptions-=F
658 exec 'sleep' . duration
659 call assert_equal('aegi', &guioptions)
660 endif
661
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200662 if has('gui_gtk3')
663 set guioptions+=d
664 exec 'sleep' . duration
665 call assert_equal('aegid', &guioptions)
666 set guioptions-=d
667 exec 'sleep' . duration
668 call assert_equal('aegi', &guioptions)
669 endif
670
Bram Moolenaar87748452017-03-12 17:10:33 +0100671 " Restore GUI ornaments to the default state.
672 set guioptions+=m
673 exec 'sleep' . duration
674 call assert_equal('aegim', &guioptions)
675 set guioptions+=r
676 exec 'sleep' . duration
677 call assert_equal('aegimr', &guioptions)
678 set guioptions+=L
679 exec 'sleep' . duration
680 call assert_equal('aegimrL', &guioptions)
681 set guioptions+=t
682 exec 'sleep' . duration
683 call assert_equal('aegimrLt', &guioptions)
684 set guioptions+=T
685 exec 'sleep' . duration
686 call assert_equal("aegimrLtT", &guioptions)
687
688 wincmd o
689 redraw!
690 endif
691
692 let &guioptions = guioptions_saved
693endfunc
694
Bram Moolenaarab186732018-09-14 21:27:06 +0200695func Test_scrollbars()
696 new
697 " buffer with 200 lines
698 call setline(1, repeat(['one', 'two'], 100))
699 set guioptions+=rlb
700
701 " scroll to move line 11 at top, moves the cursor there
Bram Moolenaarce90e362019-09-08 18:58:44 +0200702 eval 10->test_scrollbar('left', 0)
Bram Moolenaarab186732018-09-14 21:27:06 +0200703 redraw
704 call assert_equal(1, winline())
705 call assert_equal(11, line('.'))
706
707 " scroll to move line 1 at top, cursor stays in line 11
708 call test_scrollbar('right', 0, 0)
709 redraw
710 call assert_equal(11, winline())
711 call assert_equal(11, line('.'))
712
713 set nowrap
714 call setline(11, repeat('x', 150))
715 redraw
716 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200717 set number
718 redraw
719 call assert_equal(5, wincol())
720 set nonumber
721 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200722 call assert_equal(1, col('.'))
723
724 " scroll to character 11, cursor is moved
725 call test_scrollbar('hor', 10, 0)
726 redraw
727 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200728 set number
729 redraw
730 call assert_equal(5, wincol())
731 set nonumber
732 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200733 call assert_equal(11, col('.'))
734
735 set guioptions&
736 set wrap&
737 bwipe!
738endfunc
739
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100740func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100741 CheckFeature quickfix
742
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100743 " Check Help menu exists
744 let help_menu = execute('menu Help')
745 call assert_match('Overview', help_menu)
746
747 " Check Help menu works
748 emenu Help.Overview
749 call assert_equal('help', &buftype)
750 close
751
752 " Check deleting menu doesn't cause trouble.
753 aunmenu Help
Bram Moolenaarb45cd362020-09-28 21:41:49 +0200754 if exists(':tlmenu')
755 tlunmenu Help
756 endif
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100757 call assert_fails('menu Help', 'E329:')
758endfunc
759
Bram Moolenaar87748452017-03-12 17:10:33 +0100760func Test_set_guipty()
761 let guipty_saved = &guipty
762
763 " Default Value
764 set guipty&
765 call assert_equal(1, &guipty)
766
767 set noguipty
768 call assert_equal(0, &guipty)
769
770 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100771endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100772
Bram Moolenaarc701f322019-03-28 21:49:21 +0100773func Test_encoding_conversion()
774 " GTK supports conversion between 'encoding' and "utf-8"
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200775 CheckFeature gui_gtk
776 let encoding_saved = &encoding
777 set encoding=latin1
Bram Moolenaarc701f322019-03-28 21:49:21 +0100778
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200779 " would be nice if we could take a screenshot
780 intro
781 " sets the window title
782 edit SomeFile
Bram Moolenaarc701f322019-03-28 21:49:21 +0100783
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200784 let &encoding = encoding_saved
Bram Moolenaarc701f322019-03-28 21:49:21 +0100785endfunc
786
Bram Moolenaar877e9572016-08-04 20:05:50 +0200787func Test_shell_command()
788 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200789 r !echo hello
790 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200791 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200792endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100793
Bram Moolenaar87748452017-03-12 17:10:33 +0100794func Test_syntax_colortest()
795 runtime syntax/colortest.vim
796 redraw!
797 sleep 200m
798 bwipe!
799endfunc
800
801func Test_set_term()
802 " It's enough to check the current value since setting 'term' to anything
803 " other than builtin_gui makes no sense at all.
804 call assert_equal('builtin_gui', &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200805 call assert_fails('set term=xterm', 'E530:')
Bram Moolenaar87748452017-03-12 17:10:33 +0100806endfunc
807
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100808func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100809 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100810 call assert_true(v:windowid > 0)
811 else
812 call assert_equal(0, v:windowid)
813 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100814endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200815
816" Test "vim -g" and also the GUIEnter autocommand.
817func Test_gui_dash_g()
818 let cmd = GetVimCommand('Xscriptgui')
819 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200820 let lines =<< trim END
821 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
822 au GUIEnter * qall
823 END
824 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200825 call system(cmd . ' -g')
826 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
827
828 call delete('Xscriptgui')
829 call delete('Xtestgui')
830endfunc
831
832" Test "vim -7" and also the GUIEnter autocommand.
833func Test_gui_dash_y()
834 let cmd = GetVimCommand('Xscriptgui')
835 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200836 let lines =<< trim END
837 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
838 au GUIEnter * qall
839 END
840 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200841 call system(cmd . ' -y')
842 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
843
844 call delete('Xscriptgui')
845 call delete('Xtestgui')
846endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100847
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200848" Test for "!" option in 'guioptions'. Use a terminal for running external
849" commands
850func Test_gui_run_cmd_in_terminal()
Bram Moolenaar4457e1d2020-05-15 22:46:44 +0200851 CheckFeature terminal
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200852 let save_guioptions = &guioptions
853 set guioptions+=!
854 if has('win32')
855 let cmd = 'type'
856 else
857 " assume all the other systems have a cat command
858 let cmd = 'cat'
859 endif
Bram Moolenaar98f16712020-05-22 13:34:01 +0200860 exe "silent !" . cmd . " test_gui.vim"
Bram Moolenaar91689ea2020-05-11 22:04:53 +0200861 " TODO: how to check that the command ran in a separate terminal?
862 " Maybe check for $TERM (dumb vs xterm) in the spawned shell?
863 let &guioptions = save_guioptions
864endfunc
865
Bram Moolenaar46cd43b2020-06-04 22:22:11 +0200866func Test_gui_recursive_mapping()
867 nmap ' <C-W>
868 nmap <C-W>a :let didit = 1<CR>
869 call feedkeys("'a", 'xt')
870 call assert_equal(1, didit)
871
872 nunmap '
873 nunmap <C-W>a
874endfunc
875
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100876" vim: shiftwidth=2 sts=2 expandtab