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