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') |
Bram Moolenaar | 98feace | 2022-05-14 12:34:43 +0100 | [diff] [blame] | 51 | " FIXME: temporarily check less while the colorscheme changes |
| 52 | " call assert_match("\nSearch xxx term=reverse cterm=reverse ctermfg=196 ctermbg=16 gui=reverse guifg=#ff0000 guibg=#000000", a) |
| 53 | call assert_match("\nSearch xxx term=reverse ", a) |
Bram Moolenaar | 6d4470b | 2019-01-08 21:05:51 +0100 | [diff] [blame] | 54 | |
| 55 | call assert_fails('colorscheme does_not_exist', 'E185:') |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 56 | |
| 57 | exec 'colorscheme' colorscheme_saved |
Bram Moolenaar | 60a6836 | 2018-04-30 15:40:48 +0200 | [diff] [blame] | 58 | augroup TestColors |
| 59 | au! |
| 60 | augroup END |
| 61 | unlet g:color_count g:after_colors g:before_colors |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 62 | redraw! |
| 63 | endfunc |
| 64 | |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 65 | func Test_getfontname_with_arg() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 66 | CheckX11BasedGui |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 67 | |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 68 | if 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 |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 85 | endfunc |
| 86 | |
| 87 | func Test_getfontname_without_arg() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 88 | CheckX11BasedGui |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 89 | |
| 90 | let fname = getfontname() |
| 91 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 92 | if has('gui_kde') |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 93 | " 'expected' is the value specified by SetUp() above. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 94 | call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname) |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 95 | elseif has('gui_motif') |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 96 | " 'expected' is DFLT_FONT of gui_x11.c or its real name. |
| 97 | let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)' |
| 98 | call assert_match(pat, fname) |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 99 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 100 | " 'expected' is DEFAULT_FONT of gui_gtk_x11.c. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 101 | call assert_equal('Monospace 10', fname) |
| 102 | endif |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 103 | endfunc |
| 104 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 105 | func Test_getwinpos() |
| 106 | call assert_match('Window position: X \d\+, Y \d\+', execute('winpos')) |
| 107 | call assert_true(getwinposx() >= 0) |
| 108 | call assert_true(getwinposy() >= 0) |
Bram Moolenaar | 027df2a | 2018-05-14 21:31:08 +0200 | [diff] [blame] | 109 | call assert_equal([getwinposx(), getwinposy()], getwinpos()) |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 110 | endfunc |
| 111 | |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 112 | func Test_quoteplus() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 113 | CheckX11BasedGui |
| 114 | |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 115 | let g:test_is_flaky = 1 |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 116 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 117 | let quoteplus_saved = @+ |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 118 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 119 | let test_call = 'Can you hear me?' |
| 120 | let test_response = 'Yes, I can.' |
| 121 | let vim_exe = GetVimCommand() |
| 122 | let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;' |
| 123 | \ . vim_exe . ' --noplugin --not-a-term -c ''%s''' |
| 124 | " Ignore the "failed to create input context" error. |
| 125 | let cmd = 'call test_ignore_error("E285") | ' |
| 126 | \ . 'gui -f | ' |
| 127 | \ . 'call feedkeys("' |
| 128 | \ . '\"+p' |
| 129 | \ . ':s/' . test_call . '/' . test_response . '/\<CR>' |
| 130 | \ . '\"+yis' |
| 131 | \ . ':q!\<CR>", "tx")' |
| 132 | let run_vimtest = printf(testee, cmd) |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 133 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 134 | " Set the quoteplus register to test_call, and another gvim will launched. |
| 135 | " Then, it first tries to paste the content of its own quotedplus register |
| 136 | " onto it. Second, it tries to substitute test_response for the pasted |
| 137 | " sentence. If the sentence is identical to test_call, the substitution |
| 138 | " should succeed. Third, it tries to yank the result of the substitution |
| 139 | " to its own quoteplus register, and last it quits. When system() |
| 140 | " returns, the content of the quoteplus register should be identical to |
| 141 | " test_response if those quoteplus registers are synchronized properly |
| 142 | " with/through the X11 clipboard. |
| 143 | let @+ = test_call |
| 144 | call system(run_vimtest) |
| 145 | call assert_equal(test_response, @+) |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 146 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 147 | let @+ = quoteplus_saved |
Bram Moolenaar | 5074a0e | 2017-02-26 15:08:21 +0100 | [diff] [blame] | 148 | endfunc |
| 149 | |
Bram Moolenaar | d68a004 | 2021-10-20 23:08:11 +0100 | [diff] [blame] | 150 | func Test_gui_read_stdin() |
| 151 | CheckUnix |
| 152 | |
| 153 | call writefile(['some', 'lines'], 'Xstdin') |
| 154 | let script =<< trim END |
| 155 | call writefile(getline(1, '$'), 'XstdinOK') |
| 156 | qa! |
| 157 | END |
| 158 | call writefile(script, 'Xscript') |
| 159 | |
| 160 | " Cannot use --not-a-term here, the "reading from stdin" message would not be |
| 161 | " displayed. |
Bram Moolenaar | b5912e0 | 2022-05-31 17:03:14 +0100 | [diff] [blame] | 162 | " However, when using XIM we might get E285, do use it then. |
| 163 | if has('xim') |
| 164 | let vimcmd = GetVimCommand() |
| 165 | else |
| 166 | let vimcmd = substitute(GetVimCommand(), '--not-a-term', '', '') |
| 167 | endif |
Bram Moolenaar | d68a004 | 2021-10-20 23:08:11 +0100 | [diff] [blame] | 168 | |
| 169 | call system('cat Xstdin | ' .. vimcmd .. ' -f -g -S Xscript -') |
| 170 | call assert_equal(['some', 'lines'], readfile('XstdinOK')) |
| 171 | |
| 172 | call delete('Xstdin') |
| 173 | call delete('XstdinOK') |
| 174 | call delete('Xscript') |
| 175 | endfunc |
| 176 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 177 | func Test_set_background() |
| 178 | let background_saved = &background |
| 179 | |
| 180 | set background& |
| 181 | call assert_equal('light', &background) |
| 182 | |
| 183 | set background=dark |
| 184 | call assert_equal('dark', &background) |
| 185 | |
| 186 | let &background = background_saved |
| 187 | endfunc |
| 188 | |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 189 | func Test_set_balloondelay() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 190 | CheckOption balloondelay |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 191 | |
| 192 | let balloondelay_saved = &balloondelay |
| 193 | |
| 194 | " Check if the default value is identical to that described in the manual. |
| 195 | set balloondelay& |
| 196 | call assert_equal(600, &balloondelay) |
| 197 | |
| 198 | " Edge cases |
| 199 | |
| 200 | " XXX This fact should be hidden so that people won't be tempted to write |
| 201 | " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source |
| 202 | " code. |
| 203 | set balloondelay=-1 |
| 204 | call assert_equal(-1, &balloondelay) |
| 205 | |
| 206 | " Though it's possible to interpret the zero delay to be 'as soon as |
| 207 | " possible' or even 'indefinite', its actual meaning depends on the GUI |
| 208 | " toolkit in use after all. |
| 209 | set balloondelay=0 |
| 210 | call assert_equal(0, &balloondelay) |
| 211 | |
| 212 | set balloondelay=1 |
| 213 | call assert_equal(1, &balloondelay) |
| 214 | |
| 215 | " Since p_bdelay is of type long currently, the upper bound can be |
| 216 | " impractically huge and machine-dependent. Practically, it's sufficient |
Bram Moolenaar | 0f9ea22 | 2017-03-05 13:48:13 +0100 | [diff] [blame] | 217 | " to check if balloondelay works with 0x7fffffff (32 bits) for now. |
| 218 | set balloondelay=2147483647 |
| 219 | call assert_equal(2147483647, &balloondelay) |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 220 | |
| 221 | let &balloondelay = balloondelay_saved |
| 222 | endfunc |
| 223 | |
| 224 | func Test_set_ballooneval() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 225 | CheckOption ballooneval |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 226 | |
| 227 | let ballooneval_saved = &ballooneval |
| 228 | |
| 229 | set ballooneval& |
| 230 | call assert_equal(0, &ballooneval) |
| 231 | |
| 232 | set ballooneval |
| 233 | call assert_notequal(0, &ballooneval) |
| 234 | |
| 235 | set noballooneval |
| 236 | call assert_equal(0, &ballooneval) |
| 237 | |
| 238 | let &ballooneval = ballooneval_saved |
| 239 | endfunc |
| 240 | |
| 241 | func Test_set_balloonexpr() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 242 | CheckOption balloonexpr |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 243 | |
| 244 | let balloonexpr_saved = &balloonexpr |
| 245 | |
| 246 | " Default value |
| 247 | set balloonexpr& |
| 248 | call assert_equal('', &balloonexpr) |
| 249 | |
| 250 | " User-defined function |
| 251 | new |
| 252 | func MyBalloonExpr() |
| 253 | return 'Cursor is at line ' . v:beval_lnum . |
| 254 | \', column ' . v:beval_col . |
| 255 | \ ' of file ' . bufname(v:beval_bufnr) . |
| 256 | \ ' on word "' . v:beval_text . '"' . |
| 257 | \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')' |
| 258 | endfunc |
| 259 | setl balloonexpr=MyBalloonExpr() |
| 260 | setl ballooneval |
| 261 | call assert_equal('MyBalloonExpr()', &balloonexpr) |
| 262 | " 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] | 263 | " 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] | 264 | " Also, check if textlock works as expected. |
| 265 | setl balloonexpr& |
| 266 | call assert_equal('', &balloonexpr) |
| 267 | delfunc MyBalloonExpr |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 268 | |
| 269 | " Using a script-local function |
| 270 | func s:NewBalloonExpr() |
| 271 | endfunc |
| 272 | set balloonexpr=s:NewBalloonExpr() |
| 273 | call assert_equal(expand('<SID>') .. 'NewBalloonExpr()', &balloonexpr) |
| 274 | set balloonexpr=<SID>NewBalloonExpr() |
| 275 | call assert_equal(expand('<SID>') .. 'NewBalloonExpr()', &balloonexpr) |
| 276 | delfunc s:NewBalloonExpr |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 277 | bwipe! |
| 278 | |
| 279 | " Multiline support |
| 280 | if has('balloon_multiline') |
| 281 | " Multiline balloon using NL |
| 282 | new |
| 283 | func MyBalloonFuncForMultilineUsingNL() |
Dominique Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 284 | return "Multiline\nSupported\nBalloon\nusing NL" |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 285 | endfunc |
| 286 | setl balloonexpr=MyBalloonFuncForMultilineUsingNL() |
| 287 | setl ballooneval |
| 288 | call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr) |
| 289 | " 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] | 290 | " 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] | 291 | " expected. Also, check if textlock works as expected. |
| 292 | setl balloonexpr& |
| 293 | delfunc MyBalloonFuncForMultilineUsingNL |
| 294 | bwipe! |
| 295 | |
| 296 | " Multiline balloon using List |
| 297 | new |
| 298 | func MyBalloonFuncForMultilineUsingList() |
Dominique Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 299 | return [ 'Multiline', 'Supported', 'Balloon', 'using List' ] |
Bram Moolenaar | d5841f2 | 2017-03-05 13:27:25 +0100 | [diff] [blame] | 300 | endfunc |
| 301 | setl balloonexpr=MyBalloonFuncForMultilineUsingList() |
| 302 | setl ballooneval |
| 303 | call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr) |
| 304 | " 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] | 305 | " 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] | 306 | " expected. Also, check if textlock works as expected. |
| 307 | setl balloonexpr& |
| 308 | delfunc MyBalloonFuncForMultilineUsingList |
| 309 | bwipe! |
| 310 | endif |
| 311 | |
| 312 | let &balloonexpr = balloonexpr_saved |
| 313 | endfunc |
| 314 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 315 | " Invalid arguments are tested with test_options in conjunction with segfaults |
| 316 | " caused by them (Patch 8.0.0357, 24922ec233). |
| 317 | func Test_set_guicursor() |
| 318 | let guicursor_saved = &guicursor |
| 319 | |
| 320 | let default = [ |
| 321 | \ "n-v-c:block-Cursor/lCursor", |
| 322 | \ "ve:ver35-Cursor", |
| 323 | \ "o:hor50-Cursor", |
| 324 | \ "i-ci:ver25-Cursor/lCursor", |
| 325 | \ "r-cr:hor20-Cursor/lCursor", |
| 326 | \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175" |
| 327 | \ ] |
| 328 | |
| 329 | " Default Value |
| 330 | set guicursor& |
| 331 | call assert_equal(join(default, ','), &guicursor) |
| 332 | |
| 333 | " Argument List Example 1 |
| 334 | let opt_list = copy(default) |
| 335 | let opt_list[0] = "n-c-v:block-nCursor" |
| 336 | exec "set guicursor=" . join(opt_list, ',') |
| 337 | call assert_equal(join(opt_list, ','), &guicursor) |
| 338 | unlet opt_list |
| 339 | |
| 340 | " Argument List Example 2 |
| 341 | let opt_list = copy(default) |
| 342 | let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150" |
| 343 | exec "set guicursor=" . join(opt_list, ',') |
| 344 | call assert_equal(join(opt_list, ','), &guicursor) |
| 345 | unlet opt_list |
| 346 | |
| 347 | " 'a' Mode |
| 348 | set guicursor& |
| 349 | let &guicursor .= ',a:blinkon0' |
| 350 | call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor) |
| 351 | |
| 352 | let &guicursor = guicursor_saved |
| 353 | endfunc |
| 354 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 355 | func Test_set_guifont_errors() |
| 356 | if has('win32') |
| 357 | " Invalid font names are accepted in GTK GUI |
| 358 | call assert_fails('set guifont=xa1bc23d7f', 'E596:') |
| 359 | endif |
| 360 | |
| 361 | " This only works if 'renderoptions' exists and does not work for Windows XP |
| 362 | " and older. |
| 363 | if exists('+renderoptions') && windowsversion() !~ '^[345]\.' |
| 364 | " doing this four times used to cause a crash |
| 365 | set renderoptions=type:directx |
| 366 | for i in range(5) |
| 367 | set guifont= |
| 368 | endfor |
| 369 | set renderoptions= |
| 370 | for i in range(5) |
| 371 | set guifont= |
| 372 | endfor |
| 373 | endif |
| 374 | endfunc |
| 375 | |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 376 | func Test_set_guifont() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 377 | CheckX11BasedGui |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 378 | |
| 379 | let guifont_saved = &guifont |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 380 | if has('xfontset') |
| 381 | " Prevent 'guifontset' from canceling 'guifont'. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 382 | let guifontset_saved = &guifontset |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 383 | set guifontset= |
| 384 | endif |
| 385 | |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 386 | if has('gui_motif') |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 387 | " Non-empty font list with invalid font names. |
| 388 | " |
| 389 | " This test is twofold: (1) It checks if the command fails as expected |
| 390 | " when there are no loadable fonts found in the list. (2) It checks if |
| 391 | " 'guifont' remains the same after the command loads none of the fonts |
| 392 | " listed. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 393 | let flist = &guifont |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 394 | call assert_fails('set guifont=-notexist1-*,-notexist2-*') |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 395 | call assert_equal(flist, &guifont) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 396 | |
| 397 | " Non-empty font list with a valid font name. Should pick up the first |
| 398 | " valid font. |
| 399 | set guifont=-notexist1-*,fixed,-notexist2-* |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 400 | let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)' |
| 401 | call assert_match(pat, getfontname()) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 402 | |
| 403 | " Empty list. Should fallback to the built-in default. |
| 404 | set guifont= |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 405 | let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)' |
| 406 | call assert_match(pat, getfontname()) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 407 | |
| 408 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 409 | " For GTK, what we refer to as 'font names' in our manual are actually |
| 410 | " 'initial font patterns'. A valid font which matches the 'canonical font |
| 411 | " pattern' constructed from a given 'initial pattern' is to be looked up |
| 412 | " and loaded. That explains why the GTK GUIs appear to accept 'invalid |
| 413 | " font names'. |
| 414 | " |
| 415 | " Non-empty list. Should always pick up the first element, no matter how |
| 416 | " strange it is, as explained above. |
| 417 | set guifont=(´・ω・`)\ 12,Courier\ 12 |
| 418 | call assert_equal('(´・ω・`) 12', getfontname()) |
| 419 | |
| 420 | " Empty list. Should fallback to the built-in default. |
| 421 | set guifont= |
| 422 | call assert_equal('Monospace 10', getfontname()) |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 423 | endif |
| 424 | |
| 425 | if has('xfontset') |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 426 | let &guifontset = guifontset_saved |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 427 | endif |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 428 | let &guifont = guifont_saved |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 429 | endfunc |
| 430 | |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 431 | func Test_set_guifontset() |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 432 | CheckFeature xfontset |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 433 | let skipped = '' |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 434 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 435 | call assert_fails('set guifontset=*', 'E597:') |
| 436 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 437 | let ctype_saved = v:ctype |
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 | " First, since XCreateFontSet(3) is very sensitive to locale, fonts must |
| 440 | " be chosen meticulously. |
| 441 | let font_head = '-misc-fixed-medium-r-normal--14' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 442 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 443 | let font_aw70 = font_head . '-130-75-75-c-70' |
| 444 | let font_aw140 = font_head . '-130-75-75-c-140' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 445 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 446 | let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' |
| 447 | let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 448 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 449 | let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') |
| 450 | let short_XLFDs = join([ font_aw140, font_aw70 ], ',') |
| 451 | let singleton = font_head . '-*' |
| 452 | let aliases = 'k14,r14' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 453 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 454 | " Second, among 'locales', look up such a locale that gets 'set |
| 455 | " guifontset=' to work successfully with every fontset specified with |
| 456 | " 'fontsets'. |
| 457 | let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] |
| 458 | let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 459 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 460 | let feasible = 0 |
| 461 | for locale in locales |
| 462 | try |
| 463 | exec 'language ctype' locale |
| 464 | catch /^Vim\%((\a\+)\)\=:E197/ |
| 465 | continue |
| 466 | endtry |
| 467 | let done = 0 |
| 468 | for fontset in fontsets |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 469 | try |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 470 | exec 'set guifontset=' . fontset |
| 471 | catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ |
| 472 | break |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 473 | endtry |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 474 | let done += 1 |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 475 | endfor |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 476 | if done == len(fontsets) |
| 477 | let feasible = 1 |
| 478 | break |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 479 | endif |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 480 | endfor |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 481 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 482 | " Third, give a set of tests if it is found feasible. |
| 483 | if !feasible |
| 484 | let skipped = g:not_hosted |
| 485 | else |
| 486 | " N.B. 'v:ctype' has already been set to an appropriate value in the |
| 487 | " previous loop. |
| 488 | for fontset in fontsets |
| 489 | exec 'set guifontset=' . fontset |
| 490 | call assert_equal(fontset, &guifontset) |
| 491 | endfor |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 492 | endif |
| 493 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 494 | " Finally, restore ctype. |
| 495 | exec 'language ctype' ctype_saved |
| 496 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 497 | if !empty(skipped) |
| 498 | throw skipped |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 499 | endif |
| 500 | endfunc |
| 501 | |
| 502 | func Test_set_guifontwide() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 503 | CheckX11BasedGui |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 504 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 505 | call assert_fails('set guifontwide=*', 'E533:') |
| 506 | |
| 507 | if has('gui_gtk') |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 508 | let guifont_saved = &guifont |
| 509 | let guifontwide_saved = &guifontwide |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 510 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 511 | let fc_match = exepath('fc-match') |
| 512 | if empty(fc_match) |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 513 | let skipped = g:not_hosted |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 514 | else |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 515 | let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en') |
| 516 | let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja') |
| 517 | exec 'set guifontwide=' . fnameescape(wide) |
| 518 | call assert_equal(wide, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 519 | endif |
| 520 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 521 | let &guifontwide = guifontwide_saved |
| 522 | let &guifont = guifont_saved |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 523 | |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 524 | elseif has('gui_motif') |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 525 | " guifontwide is premised upon the xfontset feature. |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 526 | if !has('xfontset') |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 527 | let skipped = g:not_supported . 'xfontset' |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 528 | else |
| 529 | let encoding_saved = &encoding |
| 530 | let guifont_saved = &guifont |
| 531 | let guifontset_saved = &guifontset |
| 532 | let guifontwide_saved = &guifontwide |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 533 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 534 | let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1' |
| 535 | 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] | 536 | |
| 537 | set encoding=utf-8 |
| 538 | |
| 539 | " Case 1: guifontset is empty |
| 540 | set guifontset= |
| 541 | |
| 542 | " Case 1-1: Automatic selection |
| 543 | set guifontwide= |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 544 | exec 'set guifont=' . nfont |
| 545 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 546 | |
| 547 | " Case 1-2: Manual selection |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 548 | exec 'set guifontwide=' . wfont |
| 549 | exec 'set guifont=' . nfont |
| 550 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 551 | |
| 552 | " Case 2: guifontset is invalid |
| 553 | try |
| 554 | set guifontset=-*-notexist-* |
Bram Moolenaar | 3717540 | 2017-03-18 20:18:45 +0100 | [diff] [blame] | 555 | call assert_report("'set guifontset=-*-notexist-*' should have failed") |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 556 | catch |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 557 | call assert_exception('E598:') |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 558 | endtry |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 559 | |
| 560 | " Case 2-1: Automatic selection |
| 561 | set guifontwide= |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 562 | exec 'set guifont=' . nfont |
| 563 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 564 | |
| 565 | " Case 2-2: Manual selection |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 566 | exec 'set guifontwide=' . wfont |
| 567 | exec 'set guifont=' . nfont |
| 568 | call assert_equal(wfont, &guifontwide) |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 569 | |
Bram Moolenaar | 4e9dbc7 | 2017-02-17 13:44:48 +0100 | [diff] [blame] | 570 | let &guifontwide = guifontwide_saved |
| 571 | let &guifontset = guifontset_saved |
| 572 | let &guifont = guifont_saved |
| 573 | let &encoding = encoding_saved |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 574 | endif |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 575 | endif |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 576 | endfunc |
| 577 | |
Dusan Popovic | 4eeedc0 | 2021-10-16 20:52:05 +0100 | [diff] [blame] | 578 | func Test_set_guiligatures() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 579 | CheckX11BasedGui |
Dusan Popovic | 4eeedc0 | 2021-10-16 20:52:05 +0100 | [diff] [blame] | 580 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 581 | if has('gui_gtk') || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 582 | " Try correct value |
| 583 | set guiligatures=<>=ab |
| 584 | call assert_equal("<>=ab", &guiligatures) |
| 585 | " Try to throw error |
| 586 | try |
| 587 | set guiligatures=<>=šab |
| 588 | call assert_report("'set guiligatures=<>=šab should have failed") |
| 589 | catch |
| 590 | call assert_exception('E1243:') |
| 591 | endtry |
Dusan Popovic | 4eeedc0 | 2021-10-16 20:52:05 +0100 | [diff] [blame] | 592 | endif |
| 593 | endfunc |
| 594 | |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 595 | func Test_set_guiheadroom() |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 596 | CheckX11BasedGui |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 597 | |
Bram Moolenaar | 40bd5a1 | 2021-10-16 21:58:27 +0100 | [diff] [blame] | 598 | " Since this script is to be read together with '-U NONE', the default |
| 599 | " value must be preserved. |
| 600 | call assert_equal(50, &guiheadroom) |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 601 | endfunc |
| 602 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 603 | func Test_set_guioptions() |
| 604 | let guioptions_saved = &guioptions |
| 605 | let duration = '200m' |
| 606 | |
| 607 | if has('win32') |
| 608 | " Default Value |
| 609 | set guioptions& |
| 610 | call assert_equal('egmrLtT', &guioptions) |
| 611 | |
| 612 | else |
| 613 | " Default Value |
| 614 | set guioptions& |
| 615 | call assert_equal('aegimrLtT', &guioptions) |
| 616 | |
| 617 | " To activate scrollbars of type 'L' or 'R'. |
| 618 | wincmd v |
| 619 | redraw! |
| 620 | |
| 621 | " Remove all default GUI ornaments |
| 622 | set guioptions-=T |
| 623 | exec 'sleep' . duration |
| 624 | call assert_equal('aegimrLt', &guioptions) |
| 625 | set guioptions-=t |
| 626 | exec 'sleep' . duration |
| 627 | call assert_equal('aegimrL', &guioptions) |
| 628 | set guioptions-=L |
| 629 | exec 'sleep' . duration |
| 630 | call assert_equal('aegimr', &guioptions) |
| 631 | set guioptions-=r |
| 632 | exec 'sleep' . duration |
| 633 | call assert_equal('aegim', &guioptions) |
| 634 | set guioptions-=m |
| 635 | exec 'sleep' . duration |
| 636 | call assert_equal('aegi', &guioptions) |
| 637 | |
| 638 | " Try non-default GUI ornaments |
| 639 | set guioptions+=l |
| 640 | exec 'sleep' . duration |
| 641 | call assert_equal('aegil', &guioptions) |
| 642 | set guioptions-=l |
| 643 | exec 'sleep' . duration |
| 644 | call assert_equal('aegi', &guioptions) |
| 645 | |
| 646 | set guioptions+=R |
| 647 | exec 'sleep' . duration |
| 648 | call assert_equal('aegiR', &guioptions) |
| 649 | set guioptions-=R |
| 650 | exec 'sleep' . duration |
| 651 | call assert_equal('aegi', &guioptions) |
| 652 | |
| 653 | set guioptions+=b |
| 654 | exec 'sleep' . duration |
| 655 | call assert_equal('aegib', &guioptions) |
| 656 | set guioptions+=h |
| 657 | exec 'sleep' . duration |
| 658 | call assert_equal('aegibh', &guioptions) |
| 659 | set guioptions-=h |
| 660 | exec 'sleep' . duration |
| 661 | call assert_equal('aegib', &guioptions) |
| 662 | set guioptions-=b |
| 663 | exec 'sleep' . duration |
| 664 | call assert_equal('aegi', &guioptions) |
| 665 | |
| 666 | set guioptions+=v |
| 667 | exec 'sleep' . duration |
| 668 | call assert_equal('aegiv', &guioptions) |
| 669 | set guioptions-=v |
| 670 | exec 'sleep' . duration |
| 671 | call assert_equal('aegi', &guioptions) |
| 672 | |
| 673 | if has('gui_motif') |
| 674 | set guioptions+=F |
| 675 | exec 'sleep' . duration |
| 676 | call assert_equal('aegiF', &guioptions) |
| 677 | set guioptions-=F |
| 678 | exec 'sleep' . duration |
| 679 | call assert_equal('aegi', &guioptions) |
| 680 | endif |
| 681 | |
Bram Moolenaar | 50bf7ce | 2019-09-15 13:17:00 +0200 | [diff] [blame] | 682 | if has('gui_gtk3') |
| 683 | set guioptions+=d |
| 684 | exec 'sleep' . duration |
| 685 | call assert_equal('aegid', &guioptions) |
| 686 | set guioptions-=d |
| 687 | exec 'sleep' . duration |
| 688 | call assert_equal('aegi', &guioptions) |
| 689 | endif |
| 690 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 691 | " Restore GUI ornaments to the default state. |
| 692 | set guioptions+=m |
| 693 | exec 'sleep' . duration |
| 694 | call assert_equal('aegim', &guioptions) |
| 695 | set guioptions+=r |
| 696 | exec 'sleep' . duration |
| 697 | call assert_equal('aegimr', &guioptions) |
| 698 | set guioptions+=L |
| 699 | exec 'sleep' . duration |
| 700 | call assert_equal('aegimrL', &guioptions) |
| 701 | set guioptions+=t |
| 702 | exec 'sleep' . duration |
| 703 | call assert_equal('aegimrLt', &guioptions) |
| 704 | set guioptions+=T |
| 705 | exec 'sleep' . duration |
| 706 | call assert_equal("aegimrLtT", &guioptions) |
| 707 | |
| 708 | wincmd o |
| 709 | redraw! |
| 710 | endif |
| 711 | |
| 712 | let &guioptions = guioptions_saved |
| 713 | endfunc |
| 714 | |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 715 | func Test_scrollbars() |
| 716 | new |
| 717 | " buffer with 200 lines |
| 718 | call setline(1, repeat(['one', 'two'], 100)) |
| 719 | set guioptions+=rlb |
| 720 | |
| 721 | " scroll to move line 11 at top, moves the cursor there |
Yegappan Lakshmanan | 9e0208f | 2022-01-31 17:40:55 +0000 | [diff] [blame] | 722 | let args = #{which: 'left', value: 10, dragging: 0} |
| 723 | call test_gui_event('scrollbar', args) |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 724 | redraw |
| 725 | call assert_equal(1, winline()) |
| 726 | call assert_equal(11, line('.')) |
| 727 | |
| 728 | " scroll to move line 1 at top, cursor stays in line 11 |
Yegappan Lakshmanan | 9e0208f | 2022-01-31 17:40:55 +0000 | [diff] [blame] | 729 | let args = #{which: 'right', value: 0, dragging: 0} |
| 730 | call test_gui_event('scrollbar', args) |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 731 | redraw |
| 732 | call assert_equal(11, winline()) |
| 733 | call assert_equal(11, line('.')) |
| 734 | |
| 735 | set nowrap |
| 736 | call setline(11, repeat('x', 150)) |
| 737 | redraw |
| 738 | call assert_equal(1, wincol()) |
Bram Moolenaar | f6d50f1 | 2019-06-06 15:40:08 +0200 | [diff] [blame] | 739 | set number |
| 740 | redraw |
| 741 | call assert_equal(5, wincol()) |
| 742 | set nonumber |
| 743 | redraw |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 744 | call assert_equal(1, col('.')) |
| 745 | |
| 746 | " scroll to character 11, cursor is moved |
Yegappan Lakshmanan | 9e0208f | 2022-01-31 17:40:55 +0000 | [diff] [blame] | 747 | let args = #{which: 'hor', value: 10, dragging: 0} |
| 748 | call test_gui_event('scrollbar', args) |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 749 | redraw |
| 750 | call assert_equal(1, wincol()) |
Bram Moolenaar | f6d50f1 | 2019-06-06 15:40:08 +0200 | [diff] [blame] | 751 | set number |
| 752 | redraw |
| 753 | call assert_equal(5, wincol()) |
| 754 | set nonumber |
| 755 | redraw |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 756 | call assert_equal(11, col('.')) |
| 757 | |
Yegappan Lakshmanan | 9e0208f | 2022-01-31 17:40:55 +0000 | [diff] [blame] | 758 | " Invalid arguments |
| 759 | call assert_false(test_gui_event('scrollbar', {})) |
| 760 | call assert_false(test_gui_event('scrollbar', #{value: 10, dragging: 0})) |
| 761 | call assert_false(test_gui_event('scrollbar', #{which: 'hor', dragging: 0})) |
| 762 | call assert_false(test_gui_event('scrollbar', #{which: 'hor', value: 1})) |
| 763 | call assert_fails("call test_gui_event('scrollbar', #{which: 'a', value: 1, dragging: 0})", 'E475:') |
| 764 | |
Bram Moolenaar | ab18673 | 2018-09-14 21:27:06 +0200 | [diff] [blame] | 765 | set guioptions& |
| 766 | set wrap& |
| 767 | bwipe! |
| 768 | endfunc |
| 769 | |
Bram Moolenaar | 47cf1cc | 2019-03-28 22:04:56 +0100 | [diff] [blame] | 770 | func Test_menu() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 771 | CheckFeature quickfix |
| 772 | |
Bram Moolenaar | 47cf1cc | 2019-03-28 22:04:56 +0100 | [diff] [blame] | 773 | " Check Help menu exists |
| 774 | let help_menu = execute('menu Help') |
| 775 | call assert_match('Overview', help_menu) |
| 776 | |
| 777 | " Check Help menu works |
| 778 | emenu Help.Overview |
| 779 | call assert_equal('help', &buftype) |
| 780 | close |
| 781 | |
| 782 | " Check deleting menu doesn't cause trouble. |
| 783 | aunmenu Help |
Bram Moolenaar | b45cd36 | 2020-09-28 21:41:49 +0200 | [diff] [blame] | 784 | if exists(':tlmenu') |
| 785 | tlunmenu Help |
| 786 | endif |
Bram Moolenaar | 47cf1cc | 2019-03-28 22:04:56 +0100 | [diff] [blame] | 787 | call assert_fails('menu Help', 'E329:') |
| 788 | endfunc |
| 789 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 790 | func Test_set_guipty() |
| 791 | let guipty_saved = &guipty |
| 792 | |
| 793 | " Default Value |
| 794 | set guipty& |
| 795 | call assert_equal(1, &guipty) |
| 796 | |
| 797 | set noguipty |
| 798 | call assert_equal(0, &guipty) |
| 799 | |
| 800 | let &guipty = guipty_saved |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 801 | endfunc |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 802 | |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 803 | func Test_encoding_conversion() |
| 804 | " GTK supports conversion between 'encoding' and "utf-8" |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 805 | CheckFeature gui_gtk |
| 806 | let encoding_saved = &encoding |
| 807 | set encoding=latin1 |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 808 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 809 | " would be nice if we could take a screenshot |
| 810 | intro |
| 811 | " sets the window title |
| 812 | edit SomeFile |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 813 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 814 | let &encoding = encoding_saved |
Bram Moolenaar | c701f32 | 2019-03-28 21:49:21 +0100 | [diff] [blame] | 815 | endfunc |
| 816 | |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 817 | func Test_shell_command() |
| 818 | new |
Bram Moolenaar | 9d5b876 | 2016-08-04 21:21:13 +0200 | [diff] [blame] | 819 | r !echo hello |
| 820 | call assert_equal('hello', substitute(getline(2), '\W', '', 'g')) |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 821 | bwipe! |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 822 | endfunc |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 823 | |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 824 | func Test_syntax_colortest() |
| 825 | runtime syntax/colortest.vim |
| 826 | redraw! |
| 827 | sleep 200m |
| 828 | bwipe! |
| 829 | endfunc |
| 830 | |
| 831 | func Test_set_term() |
| 832 | " It's enough to check the current value since setting 'term' to anything |
| 833 | " other than builtin_gui makes no sense at all. |
| 834 | call assert_equal('builtin_gui', &term) |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 835 | call assert_fails('set term=xterm', 'E530:') |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 836 | endfunc |
| 837 | |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 838 | func Test_windowid_variable() |
Bram Moolenaar | 8be2fbb | 2017-02-23 19:32:47 +0100 | [diff] [blame] | 839 | if g:x11_based_gui || has('win32') |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 840 | call assert_true(v:windowid > 0) |
| 841 | else |
| 842 | call assert_equal(0, v:windowid) |
| 843 | endif |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 844 | endfunc |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 845 | |
| 846 | " Test "vim -g" and also the GUIEnter autocommand. |
| 847 | func Test_gui_dash_g() |
| 848 | let cmd = GetVimCommand('Xscriptgui') |
| 849 | call writefile([""], "Xtestgui") |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 850 | let lines =<< trim END |
| 851 | au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui") |
| 852 | au GUIEnter * qall |
| 853 | END |
| 854 | call writefile(lines, 'Xscriptgui') |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 855 | call system(cmd . ' -g') |
| 856 | call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))}) |
| 857 | |
| 858 | call delete('Xscriptgui') |
| 859 | call delete('Xtestgui') |
| 860 | endfunc |
| 861 | |
| 862 | " Test "vim -7" and also the GUIEnter autocommand. |
| 863 | func Test_gui_dash_y() |
| 864 | let cmd = GetVimCommand('Xscriptgui') |
| 865 | call writefile([""], "Xtestgui") |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 866 | let lines =<< trim END |
| 867 | au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui") |
| 868 | au GUIEnter * qall |
| 869 | END |
| 870 | call writefile(lines, 'Xscriptgui') |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 871 | call system(cmd . ' -y') |
| 872 | call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))}) |
| 873 | |
| 874 | call delete('Xscriptgui') |
| 875 | call delete('Xtestgui') |
| 876 | endfunc |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 877 | |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 878 | " Test for "!" option in 'guioptions'. Use a terminal for running external |
| 879 | " commands |
| 880 | func Test_gui_run_cmd_in_terminal() |
Bram Moolenaar | 4457e1d | 2020-05-15 22:46:44 +0200 | [diff] [blame] | 881 | CheckFeature terminal |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 882 | let save_guioptions = &guioptions |
| 883 | set guioptions+=! |
| 884 | if has('win32') |
| 885 | let cmd = 'type' |
| 886 | else |
| 887 | " assume all the other systems have a cat command |
| 888 | let cmd = 'cat' |
| 889 | endif |
Bram Moolenaar | 98f1671 | 2020-05-22 13:34:01 +0200 | [diff] [blame] | 890 | exe "silent !" . cmd . " test_gui.vim" |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 891 | " TODO: how to check that the command ran in a separate terminal? |
| 892 | " Maybe check for $TERM (dumb vs xterm) in the spawned shell? |
| 893 | let &guioptions = save_guioptions |
| 894 | endfunc |
| 895 | |
Bram Moolenaar | 46cd43b | 2020-06-04 22:22:11 +0200 | [diff] [blame] | 896 | func Test_gui_recursive_mapping() |
| 897 | nmap ' <C-W> |
| 898 | nmap <C-W>a :let didit = 1<CR> |
| 899 | call feedkeys("'a", 'xt') |
| 900 | call assert_equal(1, didit) |
| 901 | |
| 902 | nunmap ' |
| 903 | nunmap <C-W>a |
| 904 | endfunc |
| 905 | |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 906 | " Test GUI mouse events |
| 907 | func Test_gui_mouse_event() |
| 908 | set mousemodel=extend |
| 909 | call test_override('no_query_mouse', 1) |
| 910 | new |
| 911 | call setline(1, ['one two three', 'four five six']) |
| 912 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 913 | " place the cursor using left click in normal mode |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 914 | call cursor(1, 1) |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 915 | let args = #{button: 0, row: 2, col: 4, multiclick: 0, modifiers: 0} |
| 916 | call test_gui_event('mouse', args) |
| 917 | let args.button = 3 |
| 918 | eval 'mouse'->test_gui_event(args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 919 | call feedkeys("\<Esc>", 'Lx!') |
| 920 | call assert_equal([0, 2, 4, 0], getpos('.')) |
| 921 | |
| 922 | " select and yank a word |
| 923 | let @" = '' |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 924 | let args = #{button: 0, row: 1, col: 9, multiclick: 0, modifiers: 0} |
| 925 | call test_gui_event('mouse', args) |
| 926 | let args.multiclick = 1 |
| 927 | call test_gui_event('mouse', args) |
| 928 | let args.button = 3 |
| 929 | let args.multiclick = 0 |
| 930 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 931 | call feedkeys("y", 'Lx!') |
| 932 | call assert_equal('three', @") |
| 933 | |
| 934 | " create visual selection using right click |
| 935 | let @" = '' |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 936 | let args = #{button: 0, row: 2, col: 6, multiclick: 0, modifiers: 0} |
| 937 | call test_gui_event('mouse', args) |
| 938 | let args.button = 3 |
| 939 | call test_gui_event('mouse', args) |
| 940 | let args = #{button: 2, row: 2, col: 13, multiclick: 0, modifiers: 0} |
| 941 | call test_gui_event('mouse', args) |
| 942 | let args.button = 3 |
| 943 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 944 | call feedkeys("y", 'Lx!') |
| 945 | call assert_equal('five six', @") |
| 946 | |
| 947 | " paste using middle mouse button |
| 948 | let @* = 'abc ' |
| 949 | call feedkeys('""', 'Lx!') |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 950 | let args = #{button: 1, row: 1, col: 9, multiclick: 0, modifiers: 0} |
| 951 | call test_gui_event('mouse', args) |
| 952 | let args.button = 3 |
| 953 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 954 | call feedkeys("\<Esc>", 'Lx!') |
| 955 | call assert_equal(['one two abc three', 'four five six'], getline(1, '$')) |
| 956 | |
| 957 | " extend visual selection using right click in visual mode |
| 958 | let @" = '' |
| 959 | call cursor(1, 1) |
| 960 | call feedkeys('v', 'Lx!') |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 961 | let args = #{button: 2, row: 1, col: 17, multiclick: 0, modifiers: 0} |
| 962 | call test_gui_event('mouse', args) |
| 963 | let args.button = 3 |
| 964 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 965 | call feedkeys("y", 'Lx!') |
| 966 | call assert_equal('one two abc three', @") |
| 967 | |
| 968 | " extend visual selection using mouse drag |
| 969 | let @" = '' |
| 970 | call cursor(1, 1) |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 971 | let args = #{button: 0, row: 2, col: 1, multiclick: 0, modifiers: 0} |
| 972 | call test_gui_event('mouse', args) |
| 973 | let args = #{button: 0x43, row: 2, col: 9, multiclick: 0, modifiers: 0} |
| 974 | call test_gui_event('mouse', args) |
| 975 | let args.button = 0x3 |
| 976 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 977 | call feedkeys("y", 'Lx!') |
| 978 | call assert_equal('four five', @") |
| 979 | |
| 980 | " select text by moving the mouse |
| 981 | let @" = '' |
| 982 | call cursor(1, 1) |
| 983 | redraw! |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 984 | let args = #{button: 0, row: 1, col: 4, multiclick: 0, modifiers: 0} |
| 985 | call test_gui_event('mouse', args) |
| 986 | let args.button = 0x700 |
| 987 | let args.col = 9 |
| 988 | call test_gui_event('mouse', args) |
| 989 | let args.col = 13 |
| 990 | call test_gui_event('mouse', args) |
| 991 | let args.button = 3 |
| 992 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 993 | call feedkeys("y", 'Lx!') |
| 994 | call assert_equal(' two abc t', @") |
| 995 | |
| 996 | " Using mouse in insert mode |
| 997 | call cursor(1, 1) |
| 998 | call feedkeys('i', 't') |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 999 | let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0} |
| 1000 | call test_gui_event('mouse', args) |
| 1001 | let args.button = 3 |
| 1002 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1003 | call feedkeys("po\<Esc>", 'Lx!') |
| 1004 | call assert_equal(['one two abc three', 'four five posix'], getline(1, '$')) |
| 1005 | |
| 1006 | %d _ |
LemonBoy | c27747e | 2022-05-07 12:25:40 +0100 | [diff] [blame] | 1007 | set scrolloff=0 |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1008 | call setline(1, range(1, 100)) |
| 1009 | " scroll up |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1010 | let args = #{button: 0x200, row: 2, col: 1, multiclick: 0, modifiers: 0} |
| 1011 | call test_gui_event('mouse', args) |
| 1012 | call test_gui_event('mouse', args) |
| 1013 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1014 | call feedkeys("H", 'Lx!') |
| 1015 | call assert_equal(10, line('.')) |
| 1016 | |
| 1017 | " scroll down |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1018 | let args = #{button: 0x100, row: 2, col: 1, multiclick: 0, modifiers: 0} |
| 1019 | call test_gui_event('mouse', args) |
| 1020 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1021 | call feedkeys("H", 'Lx!') |
| 1022 | call assert_equal(4, line('.')) |
LemonBoy | c27747e | 2022-05-07 12:25:40 +0100 | [diff] [blame] | 1023 | set scrolloff& |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1024 | |
| 1025 | %d _ |
| 1026 | set nowrap |
| 1027 | call setline(1, range(10)->join('')->repeat(10)) |
| 1028 | " scroll left |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1029 | let args = #{button: 0x500, row: 1, col: 5, multiclick: 0, modifiers: 0} |
| 1030 | call test_gui_event('mouse', args) |
| 1031 | let args.col = 10 |
| 1032 | call test_gui_event('mouse', args) |
| 1033 | let args.col = 15 |
| 1034 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1035 | call feedkeys('g0', 'Lx!') |
| 1036 | call assert_equal(19, col('.')) |
| 1037 | |
| 1038 | " scroll right |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1039 | let args = #{button: 0x600, row: 1, col: 15, multiclick: 0, modifiers: 0} |
| 1040 | call test_gui_event('mouse', args) |
| 1041 | let args.col = 10 |
| 1042 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1043 | call feedkeys('g0', 'Lx!') |
| 1044 | call assert_equal(7, col('.')) |
| 1045 | set wrap& |
| 1046 | |
| 1047 | %d _ |
| 1048 | call setline(1, repeat([repeat('a', 60)], 10)) |
| 1049 | |
| 1050 | " record various mouse events |
| 1051 | let mouseEventNames = [ |
| 1052 | \ 'LeftMouse', 'LeftRelease', '2-LeftMouse', '3-LeftMouse', |
| 1053 | \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', |
| 1054 | \ 'MiddleRelease', '2-MiddleMouse', '3-MiddleMouse', |
| 1055 | \ 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse', |
| 1056 | \ 'RightMouse', 'RightRelease', '2-RightMouse', |
| 1057 | \ '3-RightMouse', 'S-RightMouse', 'A-RightMouse', 'C-RightMouse', |
| 1058 | \ 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', 'C-X1Mouse', 'X2Mouse', |
| 1059 | \ 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse' |
| 1060 | \ ] |
| 1061 | let mouseEventCodes = map(copy(mouseEventNames), "'<' .. v:val .. '>'") |
| 1062 | let g:events = [] |
| 1063 | for e in mouseEventCodes |
| 1064 | exe 'nnoremap ' .. e .. ' <Cmd>call add(g:events, "' .. |
| 1065 | \ substitute(e, '[<>]', '', 'g') .. '")<CR>' |
| 1066 | endfor |
| 1067 | |
| 1068 | " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1, |
| 1069 | " 0x300- X2) |
| 1070 | for button in [0, 1, 2, 0x300, 0x400] |
| 1071 | " Single click |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1072 | let args = #{button: button, row: 2, col: 5, multiclick: 0, modifiers: 0} |
| 1073 | call test_gui_event('mouse', args) |
| 1074 | let args.button = 3 |
| 1075 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1076 | |
| 1077 | " Double/Triple click is supported by only the Left/Middle/Right mouse |
| 1078 | " buttons |
| 1079 | if button <= 2 |
| 1080 | " Double Click |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1081 | let args.button = button |
| 1082 | call test_gui_event('mouse', args) |
| 1083 | let args.multiclick = 1 |
| 1084 | call test_gui_event('mouse', args) |
| 1085 | let args.button = 3 |
| 1086 | let args.multiclick = 0 |
| 1087 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1088 | |
| 1089 | " Triple Click |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1090 | let args.button = button |
| 1091 | call test_gui_event('mouse', args) |
| 1092 | let args.multiclick = 1 |
| 1093 | call test_gui_event('mouse', args) |
| 1094 | call test_gui_event('mouse', args) |
| 1095 | let args.button = 3 |
| 1096 | let args.multiclick = 0 |
| 1097 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1098 | endif |
| 1099 | |
| 1100 | " Shift click |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1101 | let args = #{button: button, row: 3, col: 7, multiclick: 0, modifiers: 4} |
| 1102 | call test_gui_event('mouse', args) |
| 1103 | let args.button = 3 |
| 1104 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1105 | |
| 1106 | " Alt click |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1107 | let args.button = button |
| 1108 | let args.modifiers = 8 |
| 1109 | call test_gui_event('mouse', args) |
| 1110 | let args.button = 3 |
| 1111 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1112 | |
| 1113 | " Ctrl click |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1114 | let args.button = button |
| 1115 | let args.modifiers = 16 |
| 1116 | call test_gui_event('mouse', args) |
| 1117 | let args.button = 3 |
| 1118 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1119 | |
| 1120 | call feedkeys("\<Esc>", 'Lx!') |
| 1121 | endfor |
| 1122 | |
| 1123 | call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse', |
| 1124 | \ 'LeftMouse', '2-LeftMouse', '3-LeftMouse', 'S-LeftMouse', |
| 1125 | \ 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', 'MiddleRelease', |
| 1126 | \ 'MiddleMouse', '2-MiddleMouse', 'MiddleMouse', '2-MiddleMouse', |
| 1127 | \ '3-MiddleMouse', 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse', |
| 1128 | \ 'RightMouse', 'RightRelease', 'RightMouse', '2-RightMouse', |
| 1129 | \ 'RightMouse', '2-RightMouse', '3-RightMouse', 'S-RightMouse', |
| 1130 | \ 'A-RightMouse', 'C-RightMouse', 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', |
| 1131 | \ 'C-X1Mouse', 'X2Mouse', 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'], |
| 1132 | \ g:events) |
| 1133 | |
| 1134 | for e in mouseEventCodes |
| 1135 | exe 'nunmap ' .. e |
| 1136 | endfor |
| 1137 | |
| 1138 | " modeless selection |
| 1139 | set mouse= |
| 1140 | let save_guioptions = &guioptions |
| 1141 | set guioptions+=A |
| 1142 | %d _ |
| 1143 | call setline(1, ['one two three', 'four five sixteen']) |
| 1144 | call cursor(1, 1) |
| 1145 | redraw! |
| 1146 | " Double click should select the word and copy it to clipboard |
| 1147 | let @* = '' |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1148 | let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0} |
| 1149 | call test_gui_event('mouse', args) |
| 1150 | let args.multiclick = 1 |
| 1151 | call test_gui_event('mouse', args) |
| 1152 | let args.button = 3 |
| 1153 | let args.multiclick = 0 |
| 1154 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1155 | call feedkeys("\<Esc>", 'Lx!') |
| 1156 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1157 | call assert_equal('sixteen', @*) |
| 1158 | " Right click should extend the selection from cursor |
| 1159 | call cursor(1, 6) |
| 1160 | redraw! |
| 1161 | let @* = '' |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1162 | let args = #{button: 2, row: 1, col: 11, multiclick: 0, modifiers: 0} |
| 1163 | call test_gui_event('mouse', args) |
| 1164 | let args.button = 3 |
| 1165 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1166 | call feedkeys("\<Esc>", 'Lx!') |
| 1167 | call assert_equal([0, 1, 6, 0], getpos('.')) |
| 1168 | call assert_equal('wo thr', @*) |
| 1169 | " Middle click should paste the clipboard contents |
| 1170 | call cursor(2, 1) |
| 1171 | redraw! |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1172 | let args = #{button: 1, row: 1, col: 11, multiclick: 0, modifiers: 0} |
| 1173 | call test_gui_event('mouse', args) |
| 1174 | let args.button = 3 |
| 1175 | call test_gui_event('mouse', args) |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1176 | call feedkeys("\<Esc>", 'Lx!') |
| 1177 | call assert_equal([0, 2, 7, 0], getpos('.')) |
| 1178 | call assert_equal('wo thrfour five sixteen', getline(2)) |
| 1179 | set mouse& |
| 1180 | let &guioptions = save_guioptions |
| 1181 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1182 | " Test invalid parameters for test_gui_event() |
| 1183 | let args = #{row: 2, col: 4, multiclick: 0, modifiers: 0} |
| 1184 | call assert_false(test_gui_event('mouse', args)) |
| 1185 | let args = #{button: 0, col: 4, multiclick: 0, modifiers: 0} |
| 1186 | call assert_false(test_gui_event('mouse', args)) |
| 1187 | let args = #{button: 0, row: 2, multiclick: 0, modifiers: 0} |
| 1188 | call assert_false(test_gui_event('mouse', args)) |
| 1189 | let args = #{button: 0, row: 2, col: 4, modifiers: 0} |
| 1190 | call assert_false(test_gui_event('mouse', args)) |
| 1191 | let args = #{button: 0, row: 2, col: 4, multiclick: 0} |
| 1192 | call assert_false(test_gui_event('mouse', args)) |
| 1193 | |
| 1194 | " Error cases for test_gui_event() |
| 1195 | call assert_fails("call test_gui_event('a1b2c3', args)", 'E475:') |
| 1196 | call assert_fails("call test_gui_event([], args)", 'E1174:') |
| 1197 | call assert_fails("call test_gui_event('abc', [])", 'E1206:') |
| 1198 | call assert_fails("call test_gui_event(test_null_string(), {})", 'E475:') |
| 1199 | call assert_false(test_gui_event('mouse', test_null_dict())) |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1200 | |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 1201 | bw! |
| 1202 | call test_override('no_query_mouse', 0) |
| 1203 | set mousemodel& |
| 1204 | endfunc |
| 1205 | |
Bram Moolenaar | 3b675c2 | 2022-05-16 13:34:44 +0100 | [diff] [blame] | 1206 | " Move the mouse to the top-left in preparation for mouse events |
| 1207 | func PrepareForMouseEvent(args) |
| 1208 | call extend(a:args, #{row: 1, col:1}) |
| 1209 | call test_gui_event('mouse', a:args) |
| 1210 | call feedkeys('', 'Lx!') |
| 1211 | " on MS-Windows the event may have a slight delay |
| 1212 | if has('win32') |
| 1213 | sleep 20m |
| 1214 | endif |
| 1215 | endfunc |
| 1216 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1217 | func MouseWasMoved() |
| 1218 | let pos = getmousepos() |
| 1219 | call add(g:eventlist, #{row: pos.screenrow, col: pos.screencol}) |
| 1220 | endfunc |
| 1221 | |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1222 | func Test_gui_mouse_move_event() |
| 1223 | let args = #{move: 1, button: 0, multiclick: 0, modifiers: 0} |
| 1224 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1225 | " by default, does not generate mouse move events |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1226 | set mousemev& |
| 1227 | call assert_false(&mousemev) |
| 1228 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1229 | let g:eventlist = [] |
| 1230 | nnoremap <special> <silent> <MouseMove> :call MouseWasMoved()<CR> |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1231 | |
| 1232 | " start at mouse pos (1,1), clear counter |
Bram Moolenaar | 3b675c2 | 2022-05-16 13:34:44 +0100 | [diff] [blame] | 1233 | call PrepareForMouseEvent(args) |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1234 | let g:eventlist = [] |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1235 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1236 | call extend(args, #{row: 3, col: 30, cell: v:true}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1237 | call test_gui_event('mouse', args) |
| 1238 | call feedkeys('', 'Lx!') |
| 1239 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1240 | call extend(args, #{row: 10, col: 30, cell: v:true}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1241 | call test_gui_event('mouse', args) |
| 1242 | call feedkeys('', 'Lx!') |
| 1243 | |
| 1244 | " no events since mousemev off |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1245 | call assert_equal([], g:eventlist) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1246 | |
| 1247 | " turn on mouse events and try the same thing |
| 1248 | set mousemev |
Bram Moolenaar | 3b675c2 | 2022-05-16 13:34:44 +0100 | [diff] [blame] | 1249 | call PrepareForMouseEvent(args) |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1250 | let g:eventlist = [] |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1251 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1252 | call extend(args, #{row: 3, col: 30, cell: v:true}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1253 | call test_gui_event('mouse', args) |
| 1254 | call feedkeys('', 'Lx!') |
| 1255 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1256 | call extend(args, #{row: 10, col: 30, cell: v:true}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1257 | call test_gui_event('mouse', args) |
| 1258 | call feedkeys('', 'Lx!') |
| 1259 | |
Bram Moolenaar | 3c25a86 | 2022-05-16 17:07:41 +0100 | [diff] [blame] | 1260 | " FIXME: on MS-Windows we get a stray event first |
| 1261 | if has('win32') && len(g:eventlist) == 3 |
Bram Moolenaar | e5162e7 | 2022-05-16 16:41:35 +0100 | [diff] [blame] | 1262 | let g:eventlist = g:eventlist[1 : ] |
| 1263 | endif |
| 1264 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1265 | call assert_equal([#{row: 4, col: 31}, #{row: 11, col: 31}], g:eventlist) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1266 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1267 | " wiggle the mouse around within a screen cell, shouldn't trigger events |
| 1268 | call extend(args, #{cell: v:false}) |
Bram Moolenaar | 3b675c2 | 2022-05-16 13:34:44 +0100 | [diff] [blame] | 1269 | call PrepareForMouseEvent(args) |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1270 | let g:eventlist = [] |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1271 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1272 | call extend(args, #{row: 1, col: 2, cell: v:false}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1273 | call test_gui_event('mouse', args) |
| 1274 | call feedkeys('', 'Lx!') |
| 1275 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1276 | call extend(args, #{row: 2, col: 2, cell: v:false}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1277 | call test_gui_event('mouse', args) |
| 1278 | call feedkeys('', 'Lx!') |
| 1279 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1280 | call extend(args, #{row: 2, col: 1, cell: v:false}) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1281 | call test_gui_event('mouse', args) |
| 1282 | call feedkeys('', 'Lx!') |
| 1283 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1284 | call assert_equal([], g:eventlist) |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1285 | |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 1286 | unlet g:eventlist |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 1287 | unmap <MouseMove> |
| 1288 | set mousemev& |
| 1289 | endfunc |
| 1290 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1291 | " Test for 'guitablabel' and 'guitabtooltip' options |
| 1292 | func TestGuiTabLabel() |
| 1293 | call add(g:TabLabels, v:lnum + 100) |
| 1294 | let bufnrlist = tabpagebuflist(v:lnum) |
| 1295 | return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) |
| 1296 | endfunc |
| 1297 | |
| 1298 | func TestGuiTabToolTip() |
| 1299 | call add(g:TabToolTips, v:lnum + 200) |
| 1300 | let bufnrlist = tabpagebuflist(v:lnum) |
| 1301 | return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) |
| 1302 | endfunc |
| 1303 | |
| 1304 | func Test_gui_tablabel_tooltip() |
| 1305 | %bw! |
| 1306 | " Removing the tabline at the end of this test, reduces the window height by |
| 1307 | " one. Save and restore it after the test. |
| 1308 | let save_lines = &lines |
| 1309 | edit one |
| 1310 | set modified |
| 1311 | tabnew two |
| 1312 | set modified |
| 1313 | tabnew three |
| 1314 | set modified |
| 1315 | let g:TabLabels = [] |
| 1316 | set guitablabel=%{TestGuiTabLabel()} |
| 1317 | call test_override('starting', 1) |
| 1318 | redrawtabline |
| 1319 | call test_override('starting', 0) |
| 1320 | call assert_true(index(g:TabLabels, 101) != -1) |
| 1321 | call assert_true(index(g:TabLabels, 102) != -1) |
| 1322 | call assert_true(index(g:TabLabels, 103) != -1) |
| 1323 | set guitablabel& |
| 1324 | unlet g:TabLabels |
| 1325 | |
| 1326 | if has('gui_gtk') |
| 1327 | " Only on GTK+, the tooltip function is called even if the mouse is not |
| 1328 | " on the tabline. on Win32 and Motif, the tooltip function is called only |
| 1329 | " when the mouse pointer is over the tabline. |
| 1330 | let g:TabToolTips = [] |
| 1331 | set guitabtooltip=%{TestGuiTabToolTip()} |
| 1332 | call test_override('starting', 1) |
| 1333 | redrawtabline |
| 1334 | call test_override('starting', 0) |
| 1335 | call assert_true(index(g:TabToolTips, 201) != -1) |
| 1336 | call assert_true(index(g:TabToolTips, 202) != -1) |
| 1337 | call assert_true(index(g:TabToolTips, 203) != -1) |
| 1338 | set guitabtooltip& |
| 1339 | unlet g:TabToolTips |
| 1340 | endif |
| 1341 | %bw! |
| 1342 | let &lines = save_lines |
| 1343 | endfunc |
| 1344 | |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1345 | " Test for dropping files into a window in GUI |
| 1346 | func DropFilesInCmdLine() |
Bram Moolenaar | 1d1ce61 | 2021-06-27 19:02:52 +0200 | [diff] [blame] | 1347 | CheckFeature drop_file |
| 1348 | |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1349 | call feedkeys(":\"", 'L') |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1350 | let d = #{files: ['a.c', 'b.c'], row: &lines, col: 1, modifiers: 0} |
| 1351 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1352 | call feedkeys("\<CR>", 'L') |
| 1353 | endfunc |
| 1354 | |
| 1355 | func Test_gui_drop_files() |
Bram Moolenaar | 1d1ce61 | 2021-06-27 19:02:52 +0200 | [diff] [blame] | 1356 | CheckFeature drop_file |
| 1357 | |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1358 | %bw! |
| 1359 | %argdelete |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1360 | let d = #{files: [], row: 1, col: 1, modifiers: 0} |
| 1361 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1362 | call assert_equal([], argv()) |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1363 | let d = #{files: [1, 2], row: 1, col: 1, modifiers: 0} |
| 1364 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1365 | call assert_equal([], argv()) |
| 1366 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1367 | let d = #{files: ['a.c', 'b.c'], row: 1, col: 1, modifiers: 0} |
| 1368 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1369 | call assert_equal(['a.c', 'b.c'], argv()) |
| 1370 | %bw! |
| 1371 | %argdelete |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1372 | let d = #{files: [], row: 1, col: 1, modifiers: 0} |
| 1373 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1374 | call assert_equal([], argv()) |
| 1375 | %bw! |
| 1376 | " if the buffer in the window is modified, then the file should be opened in |
| 1377 | " a new window |
| 1378 | set modified |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1379 | let d = #{files: ['x.c', 'y.c'], row: 1, col: 1, modifiers: 0} |
| 1380 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1381 | call assert_equal(['x.c', 'y.c'], argv()) |
| 1382 | call assert_equal(2, winnr('$')) |
| 1383 | call assert_equal('x.c', bufname(winbufnr(1))) |
| 1384 | %bw! |
| 1385 | %argdelete |
| 1386 | " if Ctrl is pressed, then the file should be opened in a new window |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1387 | let d = #{files: ['s.py', 't.py'], row: 1, col: 1, modifiers: 0x10} |
| 1388 | eval 'dropfiles'->test_gui_event(d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1389 | call assert_equal(['s.py', 't.py'], argv()) |
| 1390 | call assert_equal(2, winnr('$')) |
| 1391 | call assert_equal('s.py', bufname(winbufnr(1))) |
| 1392 | %bw! |
| 1393 | %argdelete |
| 1394 | " drop the files in a non-current window |
| 1395 | belowright new |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1396 | let d = #{files: ['a.py', 'b.py'], row: 1, col: 1, modifiers: 0} |
| 1397 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1398 | call assert_equal(['a.py', 'b.py'], argv()) |
| 1399 | call assert_equal(2, winnr('$')) |
| 1400 | call assert_equal(1, winnr()) |
| 1401 | call assert_equal('a.py', bufname(winbufnr(1))) |
| 1402 | %bw! |
| 1403 | %argdelete |
| 1404 | " pressing shift when dropping files should change directory |
| 1405 | let save_cwd = getcwd() |
| 1406 | call mkdir('Xdir1') |
| 1407 | call writefile([], 'Xdir1/Xfile1') |
| 1408 | call writefile([], 'Xdir1/Xfile2') |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1409 | let d = #{files: ['Xdir1/Xfile1', 'Xdir1/Xfile2'], row: 1, col: 1, |
| 1410 | \ modifiers: 0x4} |
| 1411 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1412 | call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) |
| 1413 | call assert_equal('Xfile1', @%) |
| 1414 | call chdir(save_cwd) |
| 1415 | " pressing shift when dropping directory and files should change directory |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1416 | let d = #{files: ['Xdir1', 'Xdir1/Xfile2'], row: 1, col: 1, modifiers: 0x4} |
| 1417 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1418 | call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) |
| 1419 | call assert_equal('Xdir1', fnamemodify(@%, ':t')) |
| 1420 | call chdir(save_cwd) |
| 1421 | %bw! |
| 1422 | %argdelete |
| 1423 | " dropping a directory should edit it |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1424 | let d = #{files: ['Xdir1'], row: 1, col: 1, modifiers: 0} |
| 1425 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1426 | call assert_equal('Xdir1', @%) |
| 1427 | %bw! |
| 1428 | %argdelete |
| 1429 | " dropping only a directory name with Shift should ignore it |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1430 | let d = #{files: ['Xdir1'], row: 1, col: 1, modifiers: 0x4} |
| 1431 | call test_gui_event('dropfiles', d) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1432 | call assert_equal('', @%) |
| 1433 | %bw! |
| 1434 | %argdelete |
| 1435 | call delete('Xdir1', 'rf') |
| 1436 | " drop files in the command line. The GUI drop files adds the file names to |
| 1437 | " the low level input buffer. So need to use a cmdline map and feedkeys() |
| 1438 | " with 'Lx!' to process it in this function itself. |
| 1439 | cnoremap <expr> <buffer> <F4> DropFilesInCmdLine() |
| 1440 | call feedkeys(":\"\<F4>\<CR>", 'xt') |
| 1441 | call feedkeys('k', 'Lx!') |
| 1442 | call assert_equal('"a.c b.c', @:) |
| 1443 | cunmap <buffer> <F4> |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1444 | |
| 1445 | " Invalid arguments |
| 1446 | call assert_false(test_gui_event("dropfiles", {})) |
| 1447 | let d = #{row: 1, col: 1, modifiers: 0} |
| 1448 | call assert_false(test_gui_event("dropfiles", d)) |
Yegappan Lakshmanan | 9e0208f | 2022-01-31 17:40:55 +0000 | [diff] [blame] | 1449 | let d = #{files: 1, row: 1, col: 1, modifiers: 0} |
| 1450 | call assert_false(test_gui_event("dropfiles", d)) |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1451 | let d = #{files: test_null_list(), row: 1, col: 1, modifiers: 0} |
| 1452 | call assert_false(test_gui_event("dropfiles", d)) |
| 1453 | let d = #{files: [test_null_string()], row: 1, col: 1, modifiers: 0} |
| 1454 | call assert_true(test_gui_event("dropfiles", d)) |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 1455 | endfunc |
| 1456 | |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1457 | " Test for generating a GUI tabline event to select a tab page |
| 1458 | func Test_gui_tabline_event() |
| 1459 | %bw! |
| 1460 | edit Xfile1 |
| 1461 | tabedit Xfile2 |
| 1462 | tabedit Xfile3 |
| 1463 | |
| 1464 | tabfirst |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1465 | call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 2})) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1466 | call feedkeys("y", "Lx!") |
| 1467 | call assert_equal(2, tabpagenr()) |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1468 | call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 3})) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1469 | call feedkeys("y", "Lx!") |
| 1470 | call assert_equal(3, tabpagenr()) |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1471 | call assert_equal(v:false, 'tabline'->test_gui_event(#{tabnr: 3})) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1472 | |
| 1473 | " From the cmdline window, tabline event should not be handled |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1474 | call feedkeys("q::let t = test_gui_event('tabline', #{tabnr: 2})\<CR>:q\<CR>", 'x!') |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1475 | call assert_equal(v:false, t) |
| 1476 | |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1477 | " Invalid arguments |
| 1478 | call assert_false(test_gui_event('tabline', {})) |
| 1479 | call assert_false(test_gui_event('tabline', #{abc: 1})) |
| 1480 | |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1481 | %bw! |
| 1482 | endfunc |
| 1483 | |
| 1484 | " Test for generating a GUI tabline menu event to execute an action |
| 1485 | func Test_gui_tabmenu_event() |
| 1486 | %bw! |
| 1487 | |
| 1488 | " Try to close the last tab page |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1489 | call test_gui_event('tabmenu', #{tabnr: 1, item: 1}) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1490 | call feedkeys("y", "Lx!") |
| 1491 | |
| 1492 | edit Xfile1 |
| 1493 | tabedit Xfile2 |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1494 | call test_gui_event('tabmenu', #{tabnr: 1, item: 1}) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1495 | call feedkeys("y", "Lx!") |
| 1496 | call assert_equal(1, tabpagenr('$')) |
| 1497 | call assert_equal('Xfile2', bufname()) |
| 1498 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1499 | eval 'tabmenu'->test_gui_event(#{tabnr: 1, item: 2}) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1500 | call feedkeys("y", "Lx!") |
| 1501 | call assert_equal(2, tabpagenr('$')) |
| 1502 | |
| 1503 | " If tabnr is 0, then the current tabpage should be used. |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1504 | call test_gui_event('tabmenu', #{tabnr: 0, item: 2}) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1505 | call feedkeys("y", "Lx!") |
| 1506 | call assert_equal(3, tabpagenr('$')) |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 1507 | call test_gui_event('tabmenu', #{tabnr: 0, item: 1}) |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1508 | call feedkeys("y", "Lx!") |
| 1509 | call assert_equal(2, tabpagenr('$')) |
| 1510 | |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1511 | " Invalid arguments |
| 1512 | call assert_false(test_gui_event('tabmenu', {})) |
| 1513 | call assert_false(test_gui_event('tabmenu', #{tabnr: 1})) |
| 1514 | call assert_false(test_gui_event('tabmenu', #{item: 1})) |
| 1515 | call assert_false(test_gui_event('tabmenu', #{abc: 1})) |
| 1516 | |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1517 | %bw! |
| 1518 | endfunc |
| 1519 | |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1520 | " Test for find/replace text dialog event |
| 1521 | func Test_gui_findrepl() |
Yegappan Lakshmanan | 0823804 | 2022-03-07 16:57:22 +0000 | [diff] [blame] | 1522 | " Find/Replace dialog is supported only on GTK, Motif and MS-Windows. |
| 1523 | if !has('gui_gtk') && !has('gui_motif') && !has('gui_win32') |
| 1524 | return |
| 1525 | endif |
| 1526 | |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1527 | new |
| 1528 | call setline(1, ['one two one', 'Twoo One two oneo']) |
| 1529 | |
| 1530 | " Replace all instances of a string with another |
| 1531 | let args = #{find_text: 'one', repl_text: 'ONE', flags: 0x4, forward: 1} |
| 1532 | call test_gui_event('findrepl', args) |
| 1533 | call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$')) |
| 1534 | |
| 1535 | " Replace all instances of a whole string with another |
| 1536 | call cursor(1, 1) |
| 1537 | let args = #{find_text: 'two', repl_text: 'TWO', flags: 0xC, forward: 1} |
| 1538 | call test_gui_event('findrepl', args) |
| 1539 | call assert_equal(['ONE TWO ONE', 'Twoo ONE TWO ONEo'], getline(1, '$')) |
| 1540 | |
Dominique Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 1541 | " Find next occurrence of a string (in a find dialog) |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1542 | call cursor(1, 11) |
| 1543 | let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 1} |
| 1544 | call test_gui_event('findrepl', args) |
| 1545 | call assert_equal([2, 10], [line('.'), col('.')]) |
| 1546 | |
Dominique Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 1547 | " Find previous occurrences of a string (in a find dialog) |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1548 | call cursor(1, 11) |
| 1549 | let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 0} |
| 1550 | call test_gui_event('findrepl', args) |
| 1551 | call assert_equal([1, 5], [line('.'), col('.')]) |
| 1552 | |
Dominique Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 1553 | " Find next occurrence of a string (in a replace dialog) |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1554 | call cursor(1, 1) |
| 1555 | let args = #{find_text: 'Twoo', repl_text: '', flags: 0x2, forward: 1} |
| 1556 | call test_gui_event('findrepl', args) |
| 1557 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1558 | |
Dominique Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 1559 | " Replace only the next occurrence of a string (once) |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1560 | call cursor(1, 5) |
| 1561 | let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x3, forward: 1} |
| 1562 | call test_gui_event('findrepl', args) |
| 1563 | call assert_equal(['ONE two ONE', 'Twoo ONE TWO ONEo'], getline(1, '$')) |
| 1564 | |
| 1565 | " Replace all instances of a whole string with another matching case |
| 1566 | call cursor(1, 1) |
| 1567 | let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x1C, forward: 1} |
| 1568 | call test_gui_event('findrepl', args) |
| 1569 | call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$')) |
Yegappan Lakshmanan | 9e0208f | 2022-01-31 17:40:55 +0000 | [diff] [blame] | 1570 | |
| 1571 | " Invalid arguments |
| 1572 | call assert_false(test_gui_event('findrepl', {})) |
| 1573 | let args = #{repl_text: 'a', flags: 1, forward: 1} |
| 1574 | call assert_false(test_gui_event('findrepl', args)) |
| 1575 | let args = #{find_text: 'a', flags: 1, forward: 1} |
| 1576 | call assert_false(test_gui_event('findrepl', args)) |
| 1577 | let args = #{find_text: 'a', repl_text: 'b', forward: 1} |
| 1578 | call assert_false(test_gui_event('findrepl', args)) |
| 1579 | let args = #{find_text: 'a', repl_text: 'b', flags: 1} |
| 1580 | call assert_false(test_gui_event('findrepl', args)) |
| 1581 | |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 1582 | bw! |
| 1583 | endfunc |
| 1584 | |
zeertzjq | bad8a01 | 2022-04-29 16:44:00 +0100 | [diff] [blame] | 1585 | func Test_gui_CTRL_SHIFT_V() |
| 1586 | call feedkeys(":let g:str = '\<*C-S-V>\<*C-S-I>\<*C-S-V>\<*C-S-@>'\<CR>", 'tx') |
zeertzjq | 758a8d1 | 2022-04-29 11:06:34 +0100 | [diff] [blame] | 1587 | call assert_equal('<C-S-I><C-S-@>', g:str) |
| 1588 | unlet g:str |
| 1589 | endfunc |
| 1590 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1591 | " vim: shiftwidth=2 sts=2 expandtab |