Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 1 | " Tests specifically for the GUI |
| 2 | |
Bram Moolenaar | 9f0139a | 2017-08-13 20:26:20 +0200 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 4 | source check.vim |
| 5 | CheckCanRunGui |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 6 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 7 | source setup_gui.vim |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 8 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 9 | func Setup() |
| 10 | call GUISetUpCommon() |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 11 | endfunc |
| 12 | |
| 13 | func TearDown() |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 14 | call GUITearDownCommon() |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 15 | endfunc |
| 16 | |
| 17 | " Test for resetting "secure" flag after GUI has started. |
Bram Moolenaar | 5d7ead3 | 2018-02-27 17:17:42 +0100 | [diff] [blame] | 18 | " Must be run first, since it starts the GUI on Unix. |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 19 | func Test_1_set_secure() |
| 20 | set exrc secure |
| 21 | gui -f |
| 22 | call assert_equal(1, has('gui_running')) |
| 23 | endfunc |
| 24 | |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 25 | " As for non-GUI, a balloon_show() test was already added with patch 8.0.0401 |
| 26 | func Test_balloon_show() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 27 | CheckFeature balloon_eval |
| 28 | " This won't do anything but must not crash either. |
| 29 | call balloon_show('hi!') |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 30 | endfunc |
| 31 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 32 | func Test_colorscheme() |
Bram Moolenaar | acc770a | 2020-04-12 15:11:06 +0200 | [diff] [blame] | 33 | call assert_equal('16777216', &t_Co) |
| 34 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 35 | let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default' |
Bram Moolenaar | 60a6836 | 2018-04-30 15:40:48 +0200 | [diff] [blame] | 36 | 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 Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 42 | |
| 43 | colorscheme torte |
| 44 | redraw! |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 45 | call assert_equal('dark', &background) |
Bram Moolenaar | 60a6836 | 2018-04-30 15:40:48 +0200 | [diff] [blame] | 46 | call assert_equal(1, g:before_colors) |
| 47 | call assert_equal(2, g:after_colors) |
Bram Moolenaar | 6d4470b | 2019-01-08 21:05:51 +0100 | [diff] [blame] | 48 | 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 Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 54 | |
| 55 | exec 'colorscheme' colorscheme_saved |
Bram Moolenaar | 60a6836 | 2018-04-30 15:40:48 +0200 | [diff] [blame] | 56 | augroup TestColors |
| 57 | au! |
| 58 | augroup END |
| 59 | unlet g:color_count g:after_colors g:before_colors |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 60 | redraw! |
| 61 | endfunc |
| 62 | |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 63 | func Test_getfontname_with_arg() |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 64 | let skipped = '' |
| 65 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 66 | if !g:x11_based_gui |
| 67 | let skipped = g:not_implemented |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 68 | elseif has('gui_athena') || has('gui_motif') |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 69 | " 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 Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 73 | let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1' |
| 74 | call assert_match(fname, getfontname(fname)) |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 75 | |
| 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 Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 79 | call assert_equal('', getfontname('*')) |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 80 | |
| 81 | " Valid font name. This is usually the real name of Monospace by default. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 82 | 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 Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 88 | endif |
| 89 | endfunc |
| 90 | |
| 91 | func Test_getfontname_without_arg() |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 92 | let skipped = '' |
| 93 | |
| 94 | let fname = getfontname() |
| 95 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 96 | if !g:x11_based_gui |
| 97 | let skipped = g:not_implemented |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 98 | elseif has('gui_kde') |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 99 | " 'expected' is the value specified by SetUp() above. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 100 | call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname) |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 101 | elseif has('gui_athena') || has('gui_motif') |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 102 | " '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 Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 105 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 106 | " 'expected' is DEFAULT_FONT of gui_gtk_x11.c. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 107 | call assert_equal('Monospace 10', fname) |
| 108 | endif |
| 109 | |
| 110 | if !empty(skipped) |
| 111 | throw skipped |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 112 | endif |
| 113 | endfunc |
| 114 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 115 | func 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 Moolenaar | 027df2a | 2018-05-14 21:31:08 +0200 | [diff] [blame] | 119 | call assert_equal([getwinposx(), getwinposy()], getwinpos()) |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 120 | endfunc |
| 121 | |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 122 | func Test_quoteplus() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 123 | let g:test_is_flaky = 1 |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 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 Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 133 | let vim_exe = GetVimCommand() |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 134 | let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;' |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 135 | \ . vim_exe . ' --noplugin --not-a-term -c ''%s''' |
Bram Moolenaar | f8ab1b1 | 2017-03-01 18:30:34 +0100 | [diff] [blame] | 136 | " Ignore the "failed to create input context" error. |
Bram Moolenaar | 24d7636 | 2017-03-04 13:32:10 +0100 | [diff] [blame] | 137 | let cmd = 'call test_ignore_error("E285") | ' |
| 138 | \ . 'gui -f | ' |
| 139 | \ . 'call feedkeys("' |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 140 | \ . '\"+p' |
| 141 | \ . ':s/' . test_call . '/' . test_response . '/\<CR>' |
| 142 | \ . '\"+yis' |
| 143 | \ . ':q!\<CR>", "tx")' |
Bram Moolenaar | 24d7636 | 2017-03-04 13:32:10 +0100 | [diff] [blame] | 144 | let run_vimtest = printf(testee, cmd) |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 145 | |
| 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 Moolenaar | 027df2a | 2018-05-14 21:31:08 +0200 | [diff] [blame] | 148 | " onto it. Second, it tries to substitute test_response for the pasted |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 149 | " 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 |
| 165 | endfunc |
| 166 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 167 | func 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 |
| 177 | endfunc |
| 178 | |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 179 | func Test_set_balloondelay() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 180 | CheckOption balloondelay |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 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 Moolenaar | 0f9ea22 | 2017-03-05 13:48:13 +0100 | [diff] [blame] | 207 | " to check if balloondelay works with 0x7fffffff (32 bits) for now. |
| 208 | set balloondelay=2147483647 |
| 209 | call assert_equal(2147483647, &balloondelay) |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 210 | |
| 211 | let &balloondelay = balloondelay_saved |
| 212 | endfunc |
| 213 | |
| 214 | func Test_set_ballooneval() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 215 | CheckOption ballooneval |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 216 | |
| 217 | let ballooneval_saved = &ballooneval |
| 218 | |
| 219 | set ballooneval& |
| 220 | call assert_equal(0, &ballooneval) |
| 221 | |
| 222 | set ballooneval |
| 223 | call assert_notequal(0, &ballooneval) |
| 224 | |
| 225 | set noballooneval |
| 226 | call assert_equal(0, &ballooneval) |
| 227 | |
| 228 | let &ballooneval = ballooneval_saved |
| 229 | endfunc |
| 230 | |
| 231 | func Test_set_balloonexpr() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 232 | CheckOption balloonexpr |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 233 | |
| 234 | let balloonexpr_saved = &balloonexpr |
| 235 | |
| 236 | " Default value |
| 237 | set balloonexpr& |
| 238 | call assert_equal('', &balloonexpr) |
| 239 | |
| 240 | " User-defined function |
| 241 | new |
| 242 | func MyBalloonExpr() |
| 243 | return 'Cursor is at line ' . v:beval_lnum . |
| 244 | \', column ' . v:beval_col . |
| 245 | \ ' of file ' . bufname(v:beval_bufnr) . |
| 246 | \ ' on word "' . v:beval_text . '"' . |
| 247 | \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')' |
| 248 | endfunc |
| 249 | setl balloonexpr=MyBalloonExpr() |
| 250 | setl ballooneval |
| 251 | call assert_equal('MyBalloonExpr()', &balloonexpr) |
| 252 | " TODO Read non-empty text, place the pointer at a character of a word, |
Bram Moolenaar | 027df2a | 2018-05-14 21:31:08 +0200 | [diff] [blame] | 253 | " and check if the content of the balloon is the same as what is expected. |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 254 | " Also, check if textlock works as expected. |
| 255 | setl balloonexpr& |
| 256 | call assert_equal('', &balloonexpr) |
| 257 | delfunc MyBalloonExpr |
| 258 | bwipe! |
| 259 | |
| 260 | " Multiline support |
| 261 | if has('balloon_multiline') |
| 262 | " Multiline balloon using NL |
| 263 | new |
| 264 | func MyBalloonFuncForMultilineUsingNL() |
| 265 | return "Multiline\nSuppported\nBalloon\nusing NL" |
| 266 | endfunc |
| 267 | setl balloonexpr=MyBalloonFuncForMultilineUsingNL() |
| 268 | setl ballooneval |
| 269 | call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr) |
| 270 | " TODO Read non-empty text, place the pointer at a character of a word, |
Bram Moolenaar | 027df2a | 2018-05-14 21:31:08 +0200 | [diff] [blame] | 271 | " and check if the content of the balloon is the same as what is |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 272 | " expected. Also, check if textlock works as expected. |
| 273 | setl balloonexpr& |
| 274 | delfunc MyBalloonFuncForMultilineUsingNL |
| 275 | bwipe! |
| 276 | |
| 277 | " Multiline balloon using List |
| 278 | new |
| 279 | func MyBalloonFuncForMultilineUsingList() |
| 280 | return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ] |
| 281 | endfunc |
| 282 | setl balloonexpr=MyBalloonFuncForMultilineUsingList() |
| 283 | setl ballooneval |
| 284 | call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr) |
| 285 | " TODO Read non-empty text, place the pointer at a character of a word, |
Bram Moolenaar | 027df2a | 2018-05-14 21:31:08 +0200 | [diff] [blame] | 286 | " and check if the content of the balloon is the same as what is |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 287 | " expected. Also, check if textlock works as expected. |
| 288 | setl balloonexpr& |
| 289 | delfunc MyBalloonFuncForMultilineUsingList |
| 290 | bwipe! |
| 291 | endif |
| 292 | |
| 293 | let &balloonexpr = balloonexpr_saved |
| 294 | endfunc |
| 295 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 296 | " Invalid arguments are tested with test_options in conjunction with segfaults |
| 297 | " caused by them (Patch 8.0.0357, 24922ec233). |
| 298 | func Test_set_guicursor() |
| 299 | let guicursor_saved = &guicursor |
| 300 | |
| 301 | let default = [ |
| 302 | \ "n-v-c:block-Cursor/lCursor", |
| 303 | \ "ve:ver35-Cursor", |
| 304 | \ "o:hor50-Cursor", |
| 305 | \ "i-ci:ver25-Cursor/lCursor", |
| 306 | \ "r-cr:hor20-Cursor/lCursor", |
| 307 | \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175" |
| 308 | \ ] |
| 309 | |
| 310 | " Default Value |
| 311 | set guicursor& |
| 312 | call assert_equal(join(default, ','), &guicursor) |
| 313 | |
| 314 | " Argument List Example 1 |
| 315 | let opt_list = copy(default) |
| 316 | let opt_list[0] = "n-c-v:block-nCursor" |
| 317 | exec "set guicursor=" . join(opt_list, ',') |
| 318 | call assert_equal(join(opt_list, ','), &guicursor) |
| 319 | unlet opt_list |
| 320 | |
| 321 | " Argument List Example 2 |
| 322 | let opt_list = copy(default) |
| 323 | let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150" |
| 324 | exec "set guicursor=" . join(opt_list, ',') |
| 325 | call assert_equal(join(opt_list, ','), &guicursor) |
| 326 | unlet opt_list |
| 327 | |
| 328 | " 'a' Mode |
| 329 | set guicursor& |
| 330 | let &guicursor .= ',a:blinkon0' |
| 331 | call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor) |
| 332 | |
| 333 | let &guicursor = guicursor_saved |
| 334 | endfunc |
| 335 | |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 336 | func Test_set_guifont() |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 337 | let skipped = '' |
| 338 | |
| 339 | let guifont_saved = &guifont |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 340 | if has('xfontset') |
| 341 | " Prevent 'guifontset' from canceling 'guifont'. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 342 | let guifontset_saved = &guifontset |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 343 | set guifontset= |
| 344 | endif |
| 345 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 346 | if !g:x11_based_gui |
| 347 | let skipped = g:not_implemented |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 348 | elseif has('gui_athena') || has('gui_motif') |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 349 | " Non-empty font list with invalid font names. |
| 350 | " |
| 351 | " This test is twofold: (1) It checks if the command fails as expected |
| 352 | " when there are no loadable fonts found in the list. (2) It checks if |
| 353 | " 'guifont' remains the same after the command loads none of the fonts |
| 354 | " listed. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 355 | let flist = &guifont |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 356 | call assert_fails('set guifont=-notexist1-*,-notexist2-*') |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 357 | call assert_equal(flist, &guifont) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 358 | |
| 359 | " Non-empty font list with a valid font name. Should pick up the first |
| 360 | " valid font. |
| 361 | set guifont=-notexist1-*,fixed,-notexist2-* |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 362 | let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)' |
| 363 | call assert_match(pat, getfontname()) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 364 | |
| 365 | " Empty list. Should fallback to the built-in default. |
| 366 | set guifont= |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 367 | let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)' |
| 368 | call assert_match(pat, getfontname()) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 369 | |
| 370 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 371 | " For GTK, what we refer to as 'font names' in our manual are actually |
| 372 | " 'initial font patterns'. A valid font which matches the 'canonical font |
| 373 | " pattern' constructed from a given 'initial pattern' is to be looked up |
| 374 | " and loaded. That explains why the GTK GUIs appear to accept 'invalid |
| 375 | " font names'. |
| 376 | " |
| 377 | " Non-empty list. Should always pick up the first element, no matter how |
| 378 | " strange it is, as explained above. |
| 379 | set guifont=(´・ω・`)\ 12,Courier\ 12 |
| 380 | call assert_equal('(´・ω・`) 12', getfontname()) |
| 381 | |
| 382 | " Empty list. Should fallback to the built-in default. |
| 383 | set guifont= |
| 384 | call assert_equal('Monospace 10', getfontname()) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 385 | endif |
| 386 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 387 | if has('win32') |
| 388 | " Invalid font names are accepted in GTK GUI |
| 389 | call assert_fails('set guifont=xa1bc23d7f', 'E596:') |
Bram Moolenaar | 2c78a77 | 2020-12-09 12:01:03 +0100 | [diff] [blame] | 390 | endif |
Bram Moolenaar | 1b3e072 | 2020-12-08 21:12:40 +0100 | [diff] [blame] | 391 | |
Bram Moolenaar | 3650fd7 | 2021-02-28 23:13:40 +0100 | [diff] [blame] | 392 | " This only works if 'renderoptions' exists and does not work for Windows XP |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 393 | " and older. |
Bram Moolenaar | 3650fd7 | 2021-02-28 23:13:40 +0100 | [diff] [blame] | 394 | if exists('+renderoptions') && windowsversion() !~ '^[345]\.' |
Bram Moolenaar | 1b3e072 | 2020-12-08 21:12:40 +0100 | [diff] [blame] | 395 | " doing this four times used to cause a crash |
Bram Moolenaar | 2c78a77 | 2020-12-09 12:01:03 +0100 | [diff] [blame] | 396 | set renderoptions=type:directx |
| 397 | for i in range(5) |
| 398 | set guifont= |
| 399 | endfor |
| 400 | set renderoptions= |
| 401 | for i in range(5) |
| 402 | set guifont= |
| 403 | endfor |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 404 | endif |
| 405 | |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 406 | if has('xfontset') |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 407 | let &guifontset = guifontset_saved |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 408 | endif |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 409 | let &guifont = guifont_saved |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 410 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 411 | if !empty(skipped) |
| 412 | throw skipped |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 413 | endif |
| 414 | endfunc |
| 415 | |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 416 | func Test_set_guifontset() |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 417 | CheckFeature xfontset |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 418 | let skipped = '' |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 419 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 420 | call assert_fails('set guifontset=*', 'E597:') |
| 421 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 422 | let ctype_saved = v:ctype |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 423 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 424 | " First, since XCreateFontSet(3) is very sensitive to locale, fonts must |
| 425 | " be chosen meticulously. |
| 426 | let font_head = '-misc-fixed-medium-r-normal--14' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 427 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 428 | let font_aw70 = font_head . '-130-75-75-c-70' |
| 429 | let font_aw140 = font_head . '-130-75-75-c-140' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 430 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 431 | let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' |
| 432 | let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 433 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 434 | let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') |
| 435 | let short_XLFDs = join([ font_aw140, font_aw70 ], ',') |
| 436 | let singleton = font_head . '-*' |
| 437 | let aliases = 'k14,r14' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 438 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 439 | " Second, among 'locales', look up such a locale that gets 'set |
| 440 | " guifontset=' to work successfully with every fontset specified with |
| 441 | " 'fontsets'. |
| 442 | let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] |
| 443 | let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 444 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 445 | let feasible = 0 |
| 446 | for locale in locales |
| 447 | try |
| 448 | exec 'language ctype' locale |
| 449 | catch /^Vim\%((\a\+)\)\=:E197/ |
| 450 | continue |
| 451 | endtry |
| 452 | let done = 0 |
| 453 | for fontset in fontsets |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 454 | try |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 455 | exec 'set guifontset=' . fontset |
| 456 | catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ |
| 457 | break |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 458 | endtry |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 459 | let done += 1 |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 460 | endfor |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 461 | if done == len(fontsets) |
| 462 | let feasible = 1 |
| 463 | break |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 464 | endif |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 465 | endfor |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 466 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 467 | " Third, give a set of tests if it is found feasible. |
| 468 | if !feasible |
| 469 | let skipped = g:not_hosted |
| 470 | else |
| 471 | " N.B. 'v:ctype' has already been set to an appropriate value in the |
| 472 | " previous loop. |
| 473 | for fontset in fontsets |
| 474 | exec 'set guifontset=' . fontset |
| 475 | call assert_equal(fontset, &guifontset) |
| 476 | endfor |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 477 | endif |
| 478 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 479 | " Finally, restore ctype. |
| 480 | exec 'language ctype' ctype_saved |
| 481 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 482 | if !empty(skipped) |
| 483 | throw skipped |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 484 | endif |
| 485 | endfunc |
| 486 | |
| 487 | func Test_set_guifontwide() |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 488 | call assert_fails('set guifontwide=*', 'E533:') |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 489 | let skipped = '' |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 490 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 491 | if !g:x11_based_gui |
| 492 | let skipped = g:not_implemented |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 493 | elseif has('gui_gtk') |
| 494 | let guifont_saved = &guifont |
| 495 | let guifontwide_saved = &guifontwide |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 496 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 497 | let fc_match = exepath('fc-match') |
| 498 | if empty(fc_match) |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 499 | let skipped = g:not_hosted |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 500 | else |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 501 | let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en') |
| 502 | let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja') |
| 503 | exec 'set guifontwide=' . fnameescape(wide) |
| 504 | call assert_equal(wide, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 505 | endif |
| 506 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 507 | let &guifontwide = guifontwide_saved |
| 508 | let &guifont = guifont_saved |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 509 | |
| 510 | elseif has('gui_athena') || has('gui_motif') |
| 511 | " guifontwide is premised upon the xfontset feature. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 512 | if !has('xfontset') |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 513 | let skipped = g:not_supported . 'xfontset' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 514 | else |
| 515 | let encoding_saved = &encoding |
| 516 | let guifont_saved = &guifont |
| 517 | let guifontset_saved = &guifontset |
| 518 | let guifontwide_saved = &guifontwide |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 519 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 520 | let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1' |
| 521 | let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1' |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 522 | |
| 523 | set encoding=utf-8 |
| 524 | |
| 525 | " Case 1: guifontset is empty |
| 526 | set guifontset= |
| 527 | |
| 528 | " Case 1-1: Automatic selection |
| 529 | set guifontwide= |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 530 | exec 'set guifont=' . nfont |
| 531 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 532 | |
| 533 | " Case 1-2: Manual selection |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 534 | exec 'set guifontwide=' . wfont |
| 535 | exec 'set guifont=' . nfont |
| 536 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 537 | |
| 538 | " Case 2: guifontset is invalid |
| 539 | try |
| 540 | set guifontset=-*-notexist-* |
Bram Moolenaar | 3717540 | 2017-03-18 20:18:45 +0100 | [diff] [blame] | 541 | call assert_report("'set guifontset=-*-notexist-*' should have failed") |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 542 | catch |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 543 | call assert_exception('E598:') |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 544 | endtry |
| 545 | " Set it to an invalid value brutally for preparation. |
| 546 | let &guifontset = '-*-notexist-*' |
| 547 | |
| 548 | " Case 2-1: Automatic selection |
| 549 | set guifontwide= |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 550 | exec 'set guifont=' . nfont |
| 551 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 552 | |
| 553 | " Case 2-2: Manual selection |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 554 | exec 'set guifontwide=' . wfont |
| 555 | exec 'set guifont=' . nfont |
| 556 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 557 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 558 | let &guifontwide = guifontwide_saved |
| 559 | let &guifontset = guifontset_saved |
| 560 | let &guifont = guifont_saved |
| 561 | let &encoding = encoding_saved |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 562 | endif |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 563 | endif |
| 564 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 565 | if !empty(skipped) |
| 566 | throw skipped |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 567 | endif |
| 568 | endfunc |
| 569 | |
Dusan Popovic | 4eeedc0 | 2021-10-16 20:52:05 +0100 | [diff] [blame] | 570 | func Test_set_guiligatures() |
| 571 | let skipped = '' |
| 572 | |
| 573 | if !g:x11_based_gui |
| 574 | let skipped = g:not_supported . 'guiligatures' |
| 575 | else |
| 576 | if has('gui_gtk') || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 577 | " Try correct value |
| 578 | set guiligatures=<>=ab |
| 579 | call assert_equal("<>=ab", &guiligatures) |
| 580 | " Try to throw error |
| 581 | try |
| 582 | set guiligatures=<>=šab |
| 583 | call assert_report("'set guiligatures=<>=šab should have failed") |
| 584 | catch |
| 585 | call assert_exception('E1243:') |
| 586 | endtry |
| 587 | endif |
| 588 | endif |
| 589 | |
| 590 | if !empty(skipped) |
| 591 | throw skipped |
| 592 | endif |
| 593 | endfunc |
| 594 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 595 | func Test_set_guiheadroom() |
| 596 | let skipped = '' |
| 597 | |
| 598 | if !g:x11_based_gui |
| 599 | let skipped = g:not_supported . 'guiheadroom' |
| 600 | else |
| 601 | " Since this script is to be read together with '-U NONE', the default |
| 602 | " value must be preserved. |
| 603 | call assert_equal(50, &guiheadroom) |
| 604 | endif |
| 605 | |
| 606 | if !empty(skipped) |
| 607 | throw skipped |
| 608 | endif |
| 609 | endfunc |
| 610 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 611 | func Test_set_guioptions() |
| 612 | let guioptions_saved = &guioptions |
| 613 | let duration = '200m' |
| 614 | |
| 615 | if has('win32') |
| 616 | " Default Value |
| 617 | set guioptions& |
| 618 | call assert_equal('egmrLtT', &guioptions) |
| 619 | |
| 620 | else |
| 621 | " Default Value |
| 622 | set guioptions& |
| 623 | call assert_equal('aegimrLtT', &guioptions) |
| 624 | |
| 625 | " To activate scrollbars of type 'L' or 'R'. |
| 626 | wincmd v |
| 627 | redraw! |
| 628 | |
| 629 | " Remove all default GUI ornaments |
| 630 | set guioptions-=T |
| 631 | exec 'sleep' . duration |
| 632 | call assert_equal('aegimrLt', &guioptions) |
| 633 | set guioptions-=t |
| 634 | exec 'sleep' . duration |
| 635 | call assert_equal('aegimrL', &guioptions) |
| 636 | set guioptions-=L |
| 637 | exec 'sleep' . duration |
| 638 | call assert_equal('aegimr', &guioptions) |
| 639 | set guioptions-=r |
| 640 | exec 'sleep' . duration |
| 641 | call assert_equal('aegim', &guioptions) |
| 642 | set guioptions-=m |
| 643 | exec 'sleep' . duration |
| 644 | call assert_equal('aegi', &guioptions) |
| 645 | |
| 646 | " Try non-default GUI ornaments |
| 647 | set guioptions+=l |
| 648 | exec 'sleep' . duration |
| 649 | call assert_equal('aegil', &guioptions) |
| 650 | set guioptions-=l |
| 651 | exec 'sleep' . duration |
| 652 | call assert_equal('aegi', &guioptions) |
| 653 | |
| 654 | set guioptions+=R |
| 655 | exec 'sleep' . duration |
| 656 | call assert_equal('aegiR', &guioptions) |
| 657 | set guioptions-=R |
| 658 | exec 'sleep' . duration |
| 659 | call assert_equal('aegi', &guioptions) |
| 660 | |
| 661 | set guioptions+=b |
| 662 | exec 'sleep' . duration |
| 663 | call assert_equal('aegib', &guioptions) |
| 664 | set guioptions+=h |
| 665 | exec 'sleep' . duration |
| 666 | call assert_equal('aegibh', &guioptions) |
| 667 | set guioptions-=h |
| 668 | exec 'sleep' . duration |
| 669 | call assert_equal('aegib', &guioptions) |
| 670 | set guioptions-=b |
| 671 | exec 'sleep' . duration |
| 672 | call assert_equal('aegi', &guioptions) |
| 673 | |
| 674 | set guioptions+=v |
| 675 | exec 'sleep' . duration |
| 676 | call assert_equal('aegiv', &guioptions) |
| 677 | set guioptions-=v |
| 678 | exec 'sleep' . duration |
| 679 | call assert_equal('aegi', &guioptions) |
| 680 | |
| 681 | if has('gui_motif') |
| 682 | set guioptions+=F |
| 683 | exec 'sleep' . duration |
| 684 | call assert_equal('aegiF', &guioptions) |
| 685 | set guioptions-=F |
| 686 | exec 'sleep' . duration |
| 687 | call assert_equal('aegi', &guioptions) |
| 688 | endif |
| 689 | |
Bram Moolenaar | 50bf7ce | 2019-09-15 13:17:00 +0200 | [diff] [blame] | 690 | if has('gui_gtk3') |
| 691 | set guioptions+=d |
| 692 | exec 'sleep' . duration |
| 693 | call assert_equal('aegid', &guioptions) |
| 694 | set guioptions-=d |
| 695 | exec 'sleep' . duration |
| 696 | call assert_equal('aegi', &guioptions) |
| 697 | endif |
| 698 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 699 | " Restore GUI ornaments to the default state. |
| 700 | set guioptions+=m |
| 701 | exec 'sleep' . duration |
| 702 | call assert_equal('aegim', &guioptions) |
| 703 | set guioptions+=r |
| 704 | exec 'sleep' . duration |
| 705 | call assert_equal('aegimr', &guioptions) |
| 706 | set guioptions+=L |
| 707 | exec 'sleep' . duration |
| 708 | call assert_equal('aegimrL', &guioptions) |
| 709 | set guioptions+=t |
| 710 | exec 'sleep' . duration |
| 711 | call assert_equal('aegimrLt', &guioptions) |
| 712 | set guioptions+=T |
| 713 | exec 'sleep' . duration |
| 714 | call assert_equal("aegimrLtT", &guioptions) |
| 715 | |
| 716 | wincmd o |
| 717 | redraw! |
| 718 | endif |
| 719 | |
| 720 | let &guioptions = guioptions_saved |
| 721 | endfunc |
| 722 | |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 723 | func Test_scrollbars() |
| 724 | new |
| 725 | " buffer with 200 lines |
| 726 | call setline(1, repeat(['one', 'two'], 100)) |
| 727 | set guioptions+=rlb |
| 728 | |
| 729 | " scroll to move line 11 at top, moves the cursor there |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 730 | eval 10->test_scrollbar('left', 0) |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 731 | redraw |
| 732 | call assert_equal(1, winline()) |
| 733 | call assert_equal(11, line('.')) |
| 734 | |
| 735 | " scroll to move line 1 at top, cursor stays in line 11 |
| 736 | call test_scrollbar('right', 0, 0) |
| 737 | redraw |
| 738 | call assert_equal(11, winline()) |
| 739 | call assert_equal(11, line('.')) |
| 740 | |
| 741 | set nowrap |
| 742 | call setline(11, repeat('x', 150)) |
| 743 | redraw |
| 744 | call assert_equal(1, wincol()) |
Bram Moolenaar | f6d50f1 | 2019-06-06 15:40:08 +0200 | [diff] [blame] | 745 | set number |
| 746 | redraw |
| 747 | call assert_equal(5, wincol()) |
| 748 | set nonumber |
| 749 | redraw |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 750 | call assert_equal(1, col('.')) |
| 751 | |
| 752 | " scroll to character 11, cursor is moved |
| 753 | call test_scrollbar('hor', 10, 0) |
| 754 | redraw |
| 755 | call assert_equal(1, wincol()) |
Bram Moolenaar | f6d50f1 | 2019-06-06 15:40:08 +0200 | [diff] [blame] | 756 | set number |
| 757 | redraw |
| 758 | call assert_equal(5, wincol()) |
| 759 | set nonumber |
| 760 | redraw |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 761 | call assert_equal(11, col('.')) |
| 762 | |
| 763 | set guioptions& |
| 764 | set wrap& |
| 765 | bwipe! |
| 766 | endfunc |
| 767 | |
Bram Moolenaar | 47cf1cc | 2019-03-28 22:04:56 +0100 | [diff] [blame] | 768 | func Test_menu() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 769 | CheckFeature quickfix |
| 770 | |
Bram Moolenaar | 47cf1cc | 2019-03-28 22:04:56 +0100 | [diff] [blame] | 771 | " Check Help menu exists |
| 772 | let help_menu = execute('menu Help') |
| 773 | call assert_match('Overview', help_menu) |
| 774 | |
| 775 | " Check Help menu works |
| 776 | emenu Help.Overview |
| 777 | call assert_equal('help', &buftype) |
| 778 | close |
| 779 | |
| 780 | " Check deleting menu doesn't cause trouble. |
| 781 | aunmenu Help |
Bram Moolenaar | b45cd36 | 2020-09-28 21:41:49 +0200 | [diff] [blame] | 782 | if exists(':tlmenu') |
| 783 | tlunmenu Help |
| 784 | endif |
Bram Moolenaar | 47cf1cc | 2019-03-28 22:04:56 +0100 | [diff] [blame] | 785 | call assert_fails('menu Help', 'E329:') |
| 786 | endfunc |
| 787 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 788 | func Test_set_guipty() |
| 789 | let guipty_saved = &guipty |
| 790 | |
| 791 | " Default Value |
| 792 | set guipty& |
| 793 | call assert_equal(1, &guipty) |
| 794 | |
| 795 | set noguipty |
| 796 | call assert_equal(0, &guipty) |
| 797 | |
| 798 | let &guipty = guipty_saved |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 799 | endfunc |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 800 | |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 801 | func Test_encoding_conversion() |
| 802 | " GTK supports conversion between 'encoding' and "utf-8" |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 803 | CheckFeature gui_gtk |
| 804 | let encoding_saved = &encoding |
| 805 | set encoding=latin1 |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 806 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 807 | " would be nice if we could take a screenshot |
| 808 | intro |
| 809 | " sets the window title |
| 810 | edit SomeFile |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 811 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 812 | let &encoding = encoding_saved |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 813 | endfunc |
| 814 | |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 815 | func Test_shell_command() |
| 816 | new |
Bram Moolenaar | 9d5b876 | 2016-08-04 21:21:13 +0200 | [diff] [blame] | 817 | r !echo hello |
| 818 | call assert_equal('hello', substitute(getline(2), '\W', '', 'g')) |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 819 | bwipe! |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 820 | endfunc |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 821 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 822 | func Test_syntax_colortest() |
| 823 | runtime syntax/colortest.vim |
| 824 | redraw! |
| 825 | sleep 200m |
| 826 | bwipe! |
| 827 | endfunc |
| 828 | |
| 829 | func Test_set_term() |
| 830 | " It's enough to check the current value since setting 'term' to anything |
| 831 | " other than builtin_gui makes no sense at all. |
| 832 | call assert_equal('builtin_gui', &term) |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 833 | call assert_fails('set term=xterm', 'E530:') |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 834 | endfunc |
| 835 | |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 836 | func Test_windowid_variable() |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 837 | if g:x11_based_gui || has('win32') |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 838 | call assert_true(v:windowid > 0) |
| 839 | else |
| 840 | call assert_equal(0, v:windowid) |
| 841 | endif |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 842 | endfunc |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 843 | |
| 844 | " Test "vim -g" and also the GUIEnter autocommand. |
| 845 | func Test_gui_dash_g() |
| 846 | let cmd = GetVimCommand('Xscriptgui') |
| 847 | call writefile([""], "Xtestgui") |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 848 | let lines =<< trim END |
| 849 | au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui") |
| 850 | au GUIEnter * qall |
| 851 | END |
| 852 | call writefile(lines, 'Xscriptgui') |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 853 | call system(cmd . ' -g') |
| 854 | call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))}) |
| 855 | |
| 856 | call delete('Xscriptgui') |
| 857 | call delete('Xtestgui') |
| 858 | endfunc |
| 859 | |
| 860 | " Test "vim -7" and also the GUIEnter autocommand. |
| 861 | func Test_gui_dash_y() |
| 862 | let cmd = GetVimCommand('Xscriptgui') |
| 863 | call writefile([""], "Xtestgui") |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 864 | let lines =<< trim END |
| 865 | au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui") |
| 866 | au GUIEnter * qall |
| 867 | END |
| 868 | call writefile(lines, 'Xscriptgui') |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 869 | call system(cmd . ' -y') |
| 870 | call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))}) |
| 871 | |
| 872 | call delete('Xscriptgui') |
| 873 | call delete('Xtestgui') |
| 874 | endfunc |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 875 | |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 876 | " Test for "!" option in 'guioptions'. Use a terminal for running external |
| 877 | " commands |
| 878 | func Test_gui_run_cmd_in_terminal() |
Bram Moolenaar | 4457e1d | 2020-05-15 22:46:44 +0200 | [diff] [blame] | 879 | CheckFeature terminal |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 880 | let save_guioptions = &guioptions |
| 881 | set guioptions+=! |
| 882 | if has('win32') |
| 883 | let cmd = 'type' |
| 884 | else |
| 885 | " assume all the other systems have a cat command |
| 886 | let cmd = 'cat' |
| 887 | endif |
Bram Moolenaar | 98f1671 | 2020-05-22 13:34:01 +0200 | [diff] [blame] | 888 | exe "silent !" . cmd . " test_gui.vim" |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 889 | " TODO: how to check that the command ran in a separate terminal? |
| 890 | " Maybe check for $TERM (dumb vs xterm) in the spawned shell? |
| 891 | let &guioptions = save_guioptions |
| 892 | endfunc |
| 893 | |
Bram Moolenaar | 46cd43b | 2020-06-04 22:22:11 +0200 | [diff] [blame] | 894 | func Test_gui_recursive_mapping() |
| 895 | nmap ' <C-W> |
| 896 | nmap <C-W>a :let didit = 1<CR> |
| 897 | call feedkeys("'a", 'xt') |
| 898 | call assert_equal(1, didit) |
| 899 | |
| 900 | nunmap ' |
| 901 | nunmap <C-W>a |
| 902 | endfunc |
| 903 | |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 904 | " Test GUI mouse events |
| 905 | func Test_gui_mouse_event() |
| 906 | set mousemodel=extend |
| 907 | call test_override('no_query_mouse', 1) |
| 908 | new |
| 909 | call setline(1, ['one two three', 'four five six']) |
| 910 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 911 | " place the cursor using left click in normal mode |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 912 | call cursor(1, 1) |
| 913 | call test_gui_mouse_event(0, 2, 4, 0, 0) |
| 914 | call test_gui_mouse_event(3, 2, 4, 0, 0) |
| 915 | call feedkeys("\<Esc>", 'Lx!') |
| 916 | call assert_equal([0, 2, 4, 0], getpos('.')) |
| 917 | |
| 918 | " select and yank a word |
| 919 | let @" = '' |
| 920 | call test_gui_mouse_event(0, 1, 9, 0, 0) |
| 921 | call test_gui_mouse_event(0, 1, 9, 1, 0) |
| 922 | call test_gui_mouse_event(3, 1, 9, 0, 0) |
| 923 | call feedkeys("y", 'Lx!') |
| 924 | call assert_equal('three', @") |
| 925 | |
| 926 | " create visual selection using right click |
| 927 | let @" = '' |
| 928 | call test_gui_mouse_event(0, 2, 6, 0, 0) |
| 929 | call test_gui_mouse_event(3, 2, 6, 0, 0) |
| 930 | call test_gui_mouse_event(2, 2, 13, 0, 0) |
| 931 | call test_gui_mouse_event(3, 2, 13, 0, 0) |
| 932 | call feedkeys("y", 'Lx!') |
| 933 | call assert_equal('five six', @") |
| 934 | |
| 935 | " paste using middle mouse button |
| 936 | let @* = 'abc ' |
| 937 | call feedkeys('""', 'Lx!') |
| 938 | call test_gui_mouse_event(1, 1, 9, 0, 0) |
| 939 | call test_gui_mouse_event(3, 1, 9, 0, 0) |
| 940 | call feedkeys("\<Esc>", 'Lx!') |
| 941 | call assert_equal(['one two abc three', 'four five six'], getline(1, '$')) |
| 942 | |
| 943 | " extend visual selection using right click in visual mode |
| 944 | let @" = '' |
| 945 | call cursor(1, 1) |
| 946 | call feedkeys('v', 'Lx!') |
| 947 | call test_gui_mouse_event(2, 1, 17, 0, 0) |
| 948 | call test_gui_mouse_event(3, 1, 17, 0, 0) |
| 949 | call feedkeys("y", 'Lx!') |
| 950 | call assert_equal('one two abc three', @") |
| 951 | |
| 952 | " extend visual selection using mouse drag |
| 953 | let @" = '' |
| 954 | call cursor(1, 1) |
| 955 | call test_gui_mouse_event(0, 2, 1, 0, 0) |
| 956 | call test_gui_mouse_event(0x43, 2, 9, 0, 0) |
| 957 | call test_gui_mouse_event(0x3, 2, 9, 0, 0) |
| 958 | call feedkeys("y", 'Lx!') |
| 959 | call assert_equal('four five', @") |
| 960 | |
| 961 | " select text by moving the mouse |
| 962 | let @" = '' |
| 963 | call cursor(1, 1) |
| 964 | redraw! |
| 965 | call test_gui_mouse_event(0, 1, 4, 0, 0) |
| 966 | call test_gui_mouse_event(0x700, 1, 9, 0, 0) |
| 967 | call test_gui_mouse_event(0x700, 1, 13, 0, 0) |
| 968 | call test_gui_mouse_event(0x3, 1, 13, 0, 0) |
| 969 | call feedkeys("y", 'Lx!') |
| 970 | call assert_equal(' two abc t', @") |
| 971 | |
| 972 | " Using mouse in insert mode |
| 973 | call cursor(1, 1) |
| 974 | call feedkeys('i', 't') |
| 975 | call test_gui_mouse_event(0, 2, 11, 0, 0) |
| 976 | call test_gui_mouse_event(3, 2, 11, 0, 0) |
| 977 | call feedkeys("po\<Esc>", 'Lx!') |
| 978 | call assert_equal(['one two abc three', 'four five posix'], getline(1, '$')) |
| 979 | |
| 980 | %d _ |
| 981 | call setline(1, range(1, 100)) |
| 982 | " scroll up |
| 983 | call test_gui_mouse_event(0x200, 2, 1, 0, 0) |
| 984 | call test_gui_mouse_event(0x200, 2, 1, 0, 0) |
| 985 | call test_gui_mouse_event(0x200, 2, 1, 0, 0) |
| 986 | call feedkeys("H", 'Lx!') |
| 987 | call assert_equal(10, line('.')) |
| 988 | |
| 989 | " scroll down |
| 990 | call test_gui_mouse_event(0x100, 2, 1, 0, 0) |
| 991 | call test_gui_mouse_event(0x100, 2, 1, 0, 0) |
| 992 | call feedkeys("H", 'Lx!') |
| 993 | call assert_equal(4, line('.')) |
| 994 | |
| 995 | %d _ |
| 996 | set nowrap |
| 997 | call setline(1, range(10)->join('')->repeat(10)) |
| 998 | " scroll left |
| 999 | call test_gui_mouse_event(0x500, 1, 5, 0, 0) |
| 1000 | call test_gui_mouse_event(0x500, 1, 10, 0, 0) |
| 1001 | call test_gui_mouse_event(0x500, 1, 15, 0, 0) |
| 1002 | call feedkeys('g0', 'Lx!') |
| 1003 | call assert_equal(19, col('.')) |
| 1004 | |
| 1005 | " scroll right |
| 1006 | call test_gui_mouse_event(0x600, 1, 15, 0, 0) |
| 1007 | call test_gui_mouse_event(0x600, 1, 10, 0, 0) |
| 1008 | call feedkeys('g0', 'Lx!') |
| 1009 | call assert_equal(7, col('.')) |
| 1010 | set wrap& |
| 1011 | |
| 1012 | %d _ |
| 1013 | call setline(1, repeat([repeat('a', 60)], 10)) |
| 1014 | |
| 1015 | " record various mouse events |
| 1016 | let mouseEventNames = [ |
| 1017 | \ 'LeftMouse', 'LeftRelease', '2-LeftMouse', '3-LeftMouse', |
| 1018 | \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', |
| 1019 | \ 'MiddleRelease', '2-MiddleMouse', '3-MiddleMouse', |
| 1020 | \ 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse', |
| 1021 | \ 'RightMouse', 'RightRelease', '2-RightMouse', |
| 1022 | \ '3-RightMouse', 'S-RightMouse', 'A-RightMouse', 'C-RightMouse', |
| 1023 | \ 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', 'C-X1Mouse', 'X2Mouse', |
| 1024 | \ 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse' |
| 1025 | \ ] |
| 1026 | let mouseEventCodes = map(copy(mouseEventNames), "'<' .. v:val .. '>'") |
| 1027 | let g:events = [] |
| 1028 | for e in mouseEventCodes |
| 1029 | exe 'nnoremap ' .. e .. ' <Cmd>call add(g:events, "' .. |
| 1030 | \ substitute(e, '[<>]', '', 'g') .. '")<CR>' |
| 1031 | endfor |
| 1032 | |
| 1033 | " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1, |
| 1034 | " 0x300- X2) |
| 1035 | for button in [0, 1, 2, 0x300, 0x400] |
| 1036 | " Single click |
| 1037 | call test_gui_mouse_event(button, 2, 5, 0, 0) |
| 1038 | call test_gui_mouse_event(3, 2, 5, 0, 0) |
| 1039 | |
| 1040 | " Double/Triple click is supported by only the Left/Middle/Right mouse |
| 1041 | " buttons |
| 1042 | if button <= 2 |
| 1043 | " Double Click |
| 1044 | call test_gui_mouse_event(button, 2, 5, 0, 0) |
| 1045 | call test_gui_mouse_event(button, 2, 5, 1, 0) |
| 1046 | call test_gui_mouse_event(3, 2, 5, 0, 0) |
| 1047 | |
| 1048 | " Triple Click |
| 1049 | call test_gui_mouse_event(button, 2, 5, 0, 0) |
| 1050 | call test_gui_mouse_event(button, 2, 5, 1, 0) |
| 1051 | call test_gui_mouse_event(button, 2, 5, 1, 0) |
| 1052 | call test_gui_mouse_event(3, 2, 5, 0, 0) |
| 1053 | endif |
| 1054 | |
| 1055 | " Shift click |
| 1056 | call test_gui_mouse_event(button, 3, 7, 0, 4) |
| 1057 | call test_gui_mouse_event(3, 3, 7, 0, 4) |
| 1058 | |
| 1059 | " Alt click |
| 1060 | call test_gui_mouse_event(button, 3, 7, 0, 8) |
| 1061 | call test_gui_mouse_event(3, 3, 7, 0, 8) |
| 1062 | |
| 1063 | " Ctrl click |
| 1064 | call test_gui_mouse_event(button, 3, 7, 0, 16) |
| 1065 | call test_gui_mouse_event(3, 3, 7, 0, 16) |
| 1066 | |
| 1067 | call feedkeys("\<Esc>", 'Lx!') |
| 1068 | endfor |
| 1069 | |
| 1070 | call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse', |
| 1071 | \ 'LeftMouse', '2-LeftMouse', '3-LeftMouse', 'S-LeftMouse', |
| 1072 | \ 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', 'MiddleRelease', |
| 1073 | \ 'MiddleMouse', '2-MiddleMouse', 'MiddleMouse', '2-MiddleMouse', |
| 1074 | \ '3-MiddleMouse', 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse', |
| 1075 | \ 'RightMouse', 'RightRelease', 'RightMouse', '2-RightMouse', |
| 1076 | \ 'RightMouse', '2-RightMouse', '3-RightMouse', 'S-RightMouse', |
| 1077 | \ 'A-RightMouse', 'C-RightMouse', 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', |
| 1078 | \ 'C-X1Mouse', 'X2Mouse', 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'], |
| 1079 | \ g:events) |
| 1080 | |
| 1081 | for e in mouseEventCodes |
| 1082 | exe 'nunmap ' .. e |
| 1083 | endfor |
| 1084 | |
| 1085 | " modeless selection |
| 1086 | set mouse= |
| 1087 | let save_guioptions = &guioptions |
| 1088 | set guioptions+=A |
| 1089 | %d _ |
| 1090 | call setline(1, ['one two three', 'four five sixteen']) |
| 1091 | call cursor(1, 1) |
| 1092 | redraw! |
| 1093 | " Double click should select the word and copy it to clipboard |
| 1094 | let @* = '' |
| 1095 | call test_gui_mouse_event(0, 2, 11, 0, 0) |
| 1096 | call test_gui_mouse_event(0, 2, 11, 1, 0) |
| 1097 | call test_gui_mouse_event(3, 2, 11, 0, 0) |
| 1098 | call feedkeys("\<Esc>", 'Lx!') |
| 1099 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1100 | call assert_equal('sixteen', @*) |
| 1101 | " Right click should extend the selection from cursor |
| 1102 | call cursor(1, 6) |
| 1103 | redraw! |
| 1104 | let @* = '' |
| 1105 | call test_gui_mouse_event(2, 1, 11, 0, 0) |
| 1106 | call test_gui_mouse_event(3, 1, 11, 0, 0) |
| 1107 | call feedkeys("\<Esc>", 'Lx!') |
| 1108 | call assert_equal([0, 1, 6, 0], getpos('.')) |
| 1109 | call assert_equal('wo thr', @*) |
| 1110 | " Middle click should paste the clipboard contents |
| 1111 | call cursor(2, 1) |
| 1112 | redraw! |
| 1113 | call test_gui_mouse_event(1, 1, 11, 0, 0) |
| 1114 | call test_gui_mouse_event(3, 1, 11, 0, 0) |
| 1115 | call feedkeys("\<Esc>", 'Lx!') |
| 1116 | call assert_equal([0, 2, 7, 0], getpos('.')) |
| 1117 | call assert_equal('wo thrfour five sixteen', getline(2)) |
| 1118 | set mouse& |
| 1119 | let &guioptions = save_guioptions |
| 1120 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1121 | " Test invalid parameters for test_gui_mouse_event() |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1122 | call assert_fails('call test_gui_mouse_event("", 1, 2, 3, 4)', 'E1210:') |
| 1123 | call assert_fails('call test_gui_mouse_event(0, "", 2, 3, 4)', 'E1210:') |
| 1124 | call assert_fails('call test_gui_mouse_event(0, 1, "", 3, 4)', 'E1210:') |
| 1125 | call assert_fails('call test_gui_mouse_event(0, 1, 2, "", 4)', 'E1210:') |
| 1126 | call assert_fails('call test_gui_mouse_event(0, 1, 2, 3, "")', 'E1210:') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1127 | |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1128 | bw! |
| 1129 | call test_override('no_query_mouse', 0) |
| 1130 | set mousemodel& |
| 1131 | endfunc |
| 1132 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1133 | " Test for 'guitablabel' and 'guitabtooltip' options |
| 1134 | func TestGuiTabLabel() |
| 1135 | call add(g:TabLabels, v:lnum + 100) |
| 1136 | let bufnrlist = tabpagebuflist(v:lnum) |
| 1137 | return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) |
| 1138 | endfunc |
| 1139 | |
| 1140 | func TestGuiTabToolTip() |
| 1141 | call add(g:TabToolTips, v:lnum + 200) |
| 1142 | let bufnrlist = tabpagebuflist(v:lnum) |
| 1143 | return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) |
| 1144 | endfunc |
| 1145 | |
| 1146 | func Test_gui_tablabel_tooltip() |
Bram Moolenaar | fb773a3 | 2021-07-03 21:37:59 +0200 | [diff] [blame] | 1147 | CheckNotFeature gui_athena |
| 1148 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1149 | %bw! |
| 1150 | " Removing the tabline at the end of this test, reduces the window height by |
| 1151 | " one. Save and restore it after the test. |
| 1152 | let save_lines = &lines |
| 1153 | edit one |
| 1154 | set modified |
| 1155 | tabnew two |
| 1156 | set modified |
| 1157 | tabnew three |
| 1158 | set modified |
| 1159 | let g:TabLabels = [] |
| 1160 | set guitablabel=%{TestGuiTabLabel()} |
| 1161 | call test_override('starting', 1) |
| 1162 | redrawtabline |
| 1163 | call test_override('starting', 0) |
| 1164 | call assert_true(index(g:TabLabels, 101) != -1) |
| 1165 | call assert_true(index(g:TabLabels, 102) != -1) |
| 1166 | call assert_true(index(g:TabLabels, 103) != -1) |
| 1167 | set guitablabel& |
| 1168 | unlet g:TabLabels |
| 1169 | |
| 1170 | if has('gui_gtk') |
| 1171 | " Only on GTK+, the tooltip function is called even if the mouse is not |
| 1172 | " on the tabline. on Win32 and Motif, the tooltip function is called only |
| 1173 | " when the mouse pointer is over the tabline. |
| 1174 | let g:TabToolTips = [] |
| 1175 | set guitabtooltip=%{TestGuiTabToolTip()} |
| 1176 | call test_override('starting', 1) |
| 1177 | redrawtabline |
| 1178 | call test_override('starting', 0) |
| 1179 | call assert_true(index(g:TabToolTips, 201) != -1) |
| 1180 | call assert_true(index(g:TabToolTips, 202) != -1) |
| 1181 | call assert_true(index(g:TabToolTips, 203) != -1) |
| 1182 | set guitabtooltip& |
| 1183 | unlet g:TabToolTips |
| 1184 | endif |
| 1185 | %bw! |
| 1186 | let &lines = save_lines |
| 1187 | endfunc |
| 1188 | |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1189 | " Test for dropping files into a window in GUI |
| 1190 | func DropFilesInCmdLine() |
Bram Moolenaar | 1d1ce61 | 2021-06-27 19:02:52 +0200 | [diff] [blame] | 1191 | CheckFeature drop_file |
| 1192 | |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1193 | call feedkeys(":\"", 'L') |
| 1194 | call test_gui_drop_files(['a.c', 'b.c'], &lines, 1, 0) |
| 1195 | call feedkeys("\<CR>", 'L') |
| 1196 | endfunc |
| 1197 | |
| 1198 | func Test_gui_drop_files() |
Bram Moolenaar | 1d1ce61 | 2021-06-27 19:02:52 +0200 | [diff] [blame] | 1199 | CheckFeature drop_file |
| 1200 | |
Yegappan Lakshmanan | 5bca906 | 2021-07-24 21:33:26 +0200 | [diff] [blame] | 1201 | call assert_fails('call test_gui_drop_files(1, 1, 1, 0)', 'E1211:') |
| 1202 | call assert_fails('call test_gui_drop_files(["x"], "", 1, 0)', 'E1210:') |
| 1203 | call assert_fails('call test_gui_drop_files(["x"], 1, "", 0)', 'E1210:') |
| 1204 | call assert_fails('call test_gui_drop_files(["x"], 1, 1, "")', 'E1210:') |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1205 | |
| 1206 | %bw! |
| 1207 | %argdelete |
| 1208 | call test_gui_drop_files([], 1, 1, 0) |
| 1209 | call assert_equal([], argv()) |
| 1210 | call test_gui_drop_files([1, 2], 1, 1, 0) |
| 1211 | call assert_equal([], argv()) |
| 1212 | |
| 1213 | call test_gui_drop_files(['a.c', 'b.c'], 1, 1, 0) |
| 1214 | call assert_equal(['a.c', 'b.c'], argv()) |
| 1215 | %bw! |
| 1216 | %argdelete |
| 1217 | call test_gui_drop_files([], 1, 1, 0) |
| 1218 | call assert_equal([], argv()) |
| 1219 | %bw! |
| 1220 | " if the buffer in the window is modified, then the file should be opened in |
| 1221 | " a new window |
| 1222 | set modified |
| 1223 | call test_gui_drop_files(['x.c', 'y.c'], 1, 1, 0) |
| 1224 | call assert_equal(['x.c', 'y.c'], argv()) |
| 1225 | call assert_equal(2, winnr('$')) |
| 1226 | call assert_equal('x.c', bufname(winbufnr(1))) |
| 1227 | %bw! |
| 1228 | %argdelete |
| 1229 | " if Ctrl is pressed, then the file should be opened in a new window |
| 1230 | call test_gui_drop_files(['s.py', 't.py'], 1, 1, 0x10) |
| 1231 | call assert_equal(['s.py', 't.py'], argv()) |
| 1232 | call assert_equal(2, winnr('$')) |
| 1233 | call assert_equal('s.py', bufname(winbufnr(1))) |
| 1234 | %bw! |
| 1235 | %argdelete |
| 1236 | " drop the files in a non-current window |
| 1237 | belowright new |
| 1238 | call test_gui_drop_files(['a.py', 'b.py'], 1, 1, 0) |
| 1239 | call assert_equal(['a.py', 'b.py'], argv()) |
| 1240 | call assert_equal(2, winnr('$')) |
| 1241 | call assert_equal(1, winnr()) |
| 1242 | call assert_equal('a.py', bufname(winbufnr(1))) |
| 1243 | %bw! |
| 1244 | %argdelete |
| 1245 | " pressing shift when dropping files should change directory |
| 1246 | let save_cwd = getcwd() |
| 1247 | call mkdir('Xdir1') |
| 1248 | call writefile([], 'Xdir1/Xfile1') |
| 1249 | call writefile([], 'Xdir1/Xfile2') |
| 1250 | call test_gui_drop_files(['Xdir1/Xfile1', 'Xdir1/Xfile2'], 1, 1, 0x4) |
| 1251 | call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) |
| 1252 | call assert_equal('Xfile1', @%) |
| 1253 | call chdir(save_cwd) |
| 1254 | " pressing shift when dropping directory and files should change directory |
| 1255 | call test_gui_drop_files(['Xdir1', 'Xdir1/Xfile2'], 1, 1, 0x4) |
| 1256 | call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) |
| 1257 | call assert_equal('Xdir1', fnamemodify(@%, ':t')) |
| 1258 | call chdir(save_cwd) |
| 1259 | %bw! |
| 1260 | %argdelete |
| 1261 | " dropping a directory should edit it |
| 1262 | call test_gui_drop_files(['Xdir1'], 1, 1, 0) |
| 1263 | call assert_equal('Xdir1', @%) |
| 1264 | %bw! |
| 1265 | %argdelete |
| 1266 | " dropping only a directory name with Shift should ignore it |
| 1267 | call test_gui_drop_files(['Xdir1'], 1, 1, 0x4) |
| 1268 | call assert_equal('', @%) |
| 1269 | %bw! |
| 1270 | %argdelete |
| 1271 | call delete('Xdir1', 'rf') |
| 1272 | " drop files in the command line. The GUI drop files adds the file names to |
| 1273 | " the low level input buffer. So need to use a cmdline map and feedkeys() |
| 1274 | " with 'Lx!' to process it in this function itself. |
| 1275 | cnoremap <expr> <buffer> <F4> DropFilesInCmdLine() |
| 1276 | call feedkeys(":\"\<F4>\<CR>", 'xt') |
| 1277 | call feedkeys('k', 'Lx!') |
| 1278 | call assert_equal('"a.c b.c', @:) |
| 1279 | cunmap <buffer> <F4> |
| 1280 | endfunc |
| 1281 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1282 | " vim: shiftwidth=2 sts=2 expandtab |