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