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