blob: 54ba588f7f1bc099ad640e1585873296abc38f83 [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
391 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100392 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100393 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100394 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100395
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100396 if !empty(skipped)
397 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100398 endif
399endfunc
400
Bram Moolenaar10434672017-02-12 19:59:08 +0100401func Test_set_guifontset()
Bram Moolenaarce90e362019-09-08 18:58:44 +0200402 CheckFeature xfontset
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100403 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100404
Bram Moolenaarce90e362019-09-08 18:58:44 +0200405 let ctype_saved = v:ctype
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100406
Bram Moolenaarce90e362019-09-08 18:58:44 +0200407 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
408 " be chosen meticulously.
409 let font_head = '-misc-fixed-medium-r-normal--14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100410
Bram Moolenaarce90e362019-09-08 18:58:44 +0200411 let font_aw70 = font_head . '-130-75-75-c-70'
412 let font_aw140 = font_head . '-130-75-75-c-140'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100413
Bram Moolenaarce90e362019-09-08 18:58:44 +0200414 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
415 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100416
Bram Moolenaarce90e362019-09-08 18:58:44 +0200417 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
418 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
419 let singleton = font_head . '-*'
420 let aliases = 'k14,r14'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100421
Bram Moolenaarce90e362019-09-08 18:58:44 +0200422 " Second, among 'locales', look up such a locale that gets 'set
423 " guifontset=' to work successfully with every fontset specified with
424 " 'fontsets'.
425 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
426 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100427
Bram Moolenaarce90e362019-09-08 18:58:44 +0200428 let feasible = 0
429 for locale in locales
430 try
431 exec 'language ctype' locale
432 catch /^Vim\%((\a\+)\)\=:E197/
433 continue
434 endtry
435 let done = 0
436 for fontset in fontsets
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100437 try
Bram Moolenaarce90e362019-09-08 18:58:44 +0200438 exec 'set guifontset=' . fontset
439 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
440 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100441 endtry
Bram Moolenaarce90e362019-09-08 18:58:44 +0200442 let done += 1
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100443 endfor
Bram Moolenaarce90e362019-09-08 18:58:44 +0200444 if done == len(fontsets)
445 let feasible = 1
446 break
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100447 endif
Bram Moolenaarce90e362019-09-08 18:58:44 +0200448 endfor
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100449
Bram Moolenaarce90e362019-09-08 18:58:44 +0200450 " Third, give a set of tests if it is found feasible.
451 if !feasible
452 let skipped = g:not_hosted
453 else
454 " N.B. 'v:ctype' has already been set to an appropriate value in the
455 " previous loop.
456 for fontset in fontsets
457 exec 'set guifontset=' . fontset
458 call assert_equal(fontset, &guifontset)
459 endfor
Bram Moolenaar10434672017-02-12 19:59:08 +0100460 endif
461
Bram Moolenaarce90e362019-09-08 18:58:44 +0200462 " Finally, restore ctype.
463 exec 'language ctype' ctype_saved
464
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100465 if !empty(skipped)
466 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100467 endif
468endfunc
469
470func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100471 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100472
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100473 if !g:x11_based_gui
474 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100475 elseif has('gui_gtk')
476 let guifont_saved = &guifont
477 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100478
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100479 let fc_match = exepath('fc-match')
480 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100481 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100482 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100483 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
484 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
485 exec 'set guifontwide=' . fnameescape(wide)
486 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100487 endif
488
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100489 let &guifontwide = guifontwide_saved
490 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100491
492 elseif has('gui_athena') || has('gui_motif')
493 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100494 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100495 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100496 else
497 let encoding_saved = &encoding
498 let guifont_saved = &guifont
499 let guifontset_saved = &guifontset
500 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100501
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100502 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
503 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100504
505 set encoding=utf-8
506
507 " Case 1: guifontset is empty
508 set guifontset=
509
510 " Case 1-1: Automatic selection
511 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100512 exec 'set guifont=' . nfont
513 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100514
515 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100516 exec 'set guifontwide=' . wfont
517 exec 'set guifont=' . nfont
518 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100519
520 " Case 2: guifontset is invalid
521 try
522 set guifontset=-*-notexist-*
Bram Moolenaar37175402017-03-18 20:18:45 +0100523 call assert_report("'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100524 catch
525 call assert_exception('E598')
526 endtry
527 " Set it to an invalid value brutally for preparation.
528 let &guifontset = '-*-notexist-*'
529
530 " Case 2-1: Automatic selection
531 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100532 exec 'set guifont=' . nfont
533 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100534
535 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100536 exec 'set guifontwide=' . wfont
537 exec 'set guifont=' . nfont
538 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100539
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100540 let &guifontwide = guifontwide_saved
541 let &guifontset = guifontset_saved
542 let &guifont = guifont_saved
543 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100544 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100545 endif
546
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100547 if !empty(skipped)
548 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100549 endif
550endfunc
551
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100552func Test_set_guiheadroom()
553 let skipped = ''
554
555 if !g:x11_based_gui
556 let skipped = g:not_supported . 'guiheadroom'
557 else
558 " Since this script is to be read together with '-U NONE', the default
559 " value must be preserved.
560 call assert_equal(50, &guiheadroom)
561 endif
562
563 if !empty(skipped)
564 throw skipped
565 endif
566endfunc
567
Bram Moolenaar87748452017-03-12 17:10:33 +0100568func Test_set_guioptions()
569 let guioptions_saved = &guioptions
570 let duration = '200m'
571
572 if has('win32')
573 " Default Value
574 set guioptions&
575 call assert_equal('egmrLtT', &guioptions)
576
577 else
578 " Default Value
579 set guioptions&
580 call assert_equal('aegimrLtT', &guioptions)
581
582 " To activate scrollbars of type 'L' or 'R'.
583 wincmd v
584 redraw!
585
586 " Remove all default GUI ornaments
587 set guioptions-=T
588 exec 'sleep' . duration
589 call assert_equal('aegimrLt', &guioptions)
590 set guioptions-=t
591 exec 'sleep' . duration
592 call assert_equal('aegimrL', &guioptions)
593 set guioptions-=L
594 exec 'sleep' . duration
595 call assert_equal('aegimr', &guioptions)
596 set guioptions-=r
597 exec 'sleep' . duration
598 call assert_equal('aegim', &guioptions)
599 set guioptions-=m
600 exec 'sleep' . duration
601 call assert_equal('aegi', &guioptions)
602
603 " Try non-default GUI ornaments
604 set guioptions+=l
605 exec 'sleep' . duration
606 call assert_equal('aegil', &guioptions)
607 set guioptions-=l
608 exec 'sleep' . duration
609 call assert_equal('aegi', &guioptions)
610
611 set guioptions+=R
612 exec 'sleep' . duration
613 call assert_equal('aegiR', &guioptions)
614 set guioptions-=R
615 exec 'sleep' . duration
616 call assert_equal('aegi', &guioptions)
617
618 set guioptions+=b
619 exec 'sleep' . duration
620 call assert_equal('aegib', &guioptions)
621 set guioptions+=h
622 exec 'sleep' . duration
623 call assert_equal('aegibh', &guioptions)
624 set guioptions-=h
625 exec 'sleep' . duration
626 call assert_equal('aegib', &guioptions)
627 set guioptions-=b
628 exec 'sleep' . duration
629 call assert_equal('aegi', &guioptions)
630
631 set guioptions+=v
632 exec 'sleep' . duration
633 call assert_equal('aegiv', &guioptions)
634 set guioptions-=v
635 exec 'sleep' . duration
636 call assert_equal('aegi', &guioptions)
637
638 if has('gui_motif')
639 set guioptions+=F
640 exec 'sleep' . duration
641 call assert_equal('aegiF', &guioptions)
642 set guioptions-=F
643 exec 'sleep' . duration
644 call assert_equal('aegi', &guioptions)
645 endif
646
Bram Moolenaar50bf7ce2019-09-15 13:17:00 +0200647 if has('gui_gtk3')
648 set guioptions+=d
649 exec 'sleep' . duration
650 call assert_equal('aegid', &guioptions)
651 set guioptions-=d
652 exec 'sleep' . duration
653 call assert_equal('aegi', &guioptions)
654 endif
655
Bram Moolenaar87748452017-03-12 17:10:33 +0100656 " Restore GUI ornaments to the default state.
657 set guioptions+=m
658 exec 'sleep' . duration
659 call assert_equal('aegim', &guioptions)
660 set guioptions+=r
661 exec 'sleep' . duration
662 call assert_equal('aegimr', &guioptions)
663 set guioptions+=L
664 exec 'sleep' . duration
665 call assert_equal('aegimrL', &guioptions)
666 set guioptions+=t
667 exec 'sleep' . duration
668 call assert_equal('aegimrLt', &guioptions)
669 set guioptions+=T
670 exec 'sleep' . duration
671 call assert_equal("aegimrLtT", &guioptions)
672
673 wincmd o
674 redraw!
675 endif
676
677 let &guioptions = guioptions_saved
678endfunc
679
Bram Moolenaarab186732018-09-14 21:27:06 +0200680func Test_scrollbars()
681 new
682 " buffer with 200 lines
683 call setline(1, repeat(['one', 'two'], 100))
684 set guioptions+=rlb
685
686 " scroll to move line 11 at top, moves the cursor there
Bram Moolenaarce90e362019-09-08 18:58:44 +0200687 eval 10->test_scrollbar('left', 0)
Bram Moolenaarab186732018-09-14 21:27:06 +0200688 redraw
689 call assert_equal(1, winline())
690 call assert_equal(11, line('.'))
691
692 " scroll to move line 1 at top, cursor stays in line 11
693 call test_scrollbar('right', 0, 0)
694 redraw
695 call assert_equal(11, winline())
696 call assert_equal(11, line('.'))
697
698 set nowrap
699 call setline(11, repeat('x', 150))
700 redraw
701 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200702 set number
703 redraw
704 call assert_equal(5, wincol())
705 set nonumber
706 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200707 call assert_equal(1, col('.'))
708
709 " scroll to character 11, cursor is moved
710 call test_scrollbar('hor', 10, 0)
711 redraw
712 call assert_equal(1, wincol())
Bram Moolenaarf6d50f12019-06-06 15:40:08 +0200713 set number
714 redraw
715 call assert_equal(5, wincol())
716 set nonumber
717 redraw
Bram Moolenaarab186732018-09-14 21:27:06 +0200718 call assert_equal(11, col('.'))
719
720 set guioptions&
721 set wrap&
722 bwipe!
723endfunc
724
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100725func Test_menu()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100726 CheckFeature quickfix
727
Bram Moolenaar47cf1cc2019-03-28 22:04:56 +0100728 " Check Help menu exists
729 let help_menu = execute('menu Help')
730 call assert_match('Overview', help_menu)
731
732 " Check Help menu works
733 emenu Help.Overview
734 call assert_equal('help', &buftype)
735 close
736
737 " Check deleting menu doesn't cause trouble.
738 aunmenu Help
739 call assert_fails('menu Help', 'E329:')
740endfunc
741
Bram Moolenaar87748452017-03-12 17:10:33 +0100742func Test_set_guipty()
743 let guipty_saved = &guipty
744
745 " Default Value
746 set guipty&
747 call assert_equal(1, &guipty)
748
749 set noguipty
750 call assert_equal(0, &guipty)
751
752 let &guipty = guipty_saved
Bram Moolenaar6f785742017-02-06 22:11:55 +0100753endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100754
Bram Moolenaarc701f322019-03-28 21:49:21 +0100755func Test_encoding_conversion()
756 " GTK supports conversion between 'encoding' and "utf-8"
757 if has('gui_gtk')
758 let encoding_saved = &encoding
759 set encoding=latin1
760
761 " would be nice if we could take a screenshot
762 intro
763 " sets the window title
764 edit SomeFile
765
766 let &encoding = encoding_saved
767 endif
768endfunc
769
Bram Moolenaar877e9572016-08-04 20:05:50 +0200770func Test_shell_command()
771 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200772 r !echo hello
773 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200774 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200775endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100776
Bram Moolenaar87748452017-03-12 17:10:33 +0100777func Test_syntax_colortest()
778 runtime syntax/colortest.vim
779 redraw!
780 sleep 200m
781 bwipe!
782endfunc
783
784func Test_set_term()
785 " It's enough to check the current value since setting 'term' to anything
786 " other than builtin_gui makes no sense at all.
787 call assert_equal('builtin_gui', &term)
788endfunc
789
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100790func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100791 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100792 call assert_true(v:windowid > 0)
793 else
794 call assert_equal(0, v:windowid)
795 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100796endfunc
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200797
798" Test "vim -g" and also the GUIEnter autocommand.
799func Test_gui_dash_g()
800 let cmd = GetVimCommand('Xscriptgui')
801 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200802 let lines =<< trim END
803 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
804 au GUIEnter * qall
805 END
806 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200807 call system(cmd . ' -g')
808 call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
809
810 call delete('Xscriptgui')
811 call delete('Xtestgui')
812endfunc
813
814" Test "vim -7" and also the GUIEnter autocommand.
815func Test_gui_dash_y()
816 let cmd = GetVimCommand('Xscriptgui')
817 call writefile([""], "Xtestgui")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200818 let lines =<< trim END
819 au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
820 au GUIEnter * qall
821 END
822 call writefile(lines, 'Xscriptgui')
Bram Moolenaar248be5c2018-05-05 15:47:19 +0200823 call system(cmd . ' -y')
824 call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
825
826 call delete('Xscriptgui')
827 call delete('Xtestgui')
828endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100829
830" vim: shiftwidth=2 sts=2 expandtab