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