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