comparison src/testdir/test_terminal.vim @ 20365:6bcd12791bf1 v8.2.0738

patch 8.2.0738: mouse handling in a terminal window not well tested Commit: https://github.com/vim/vim/commit/91689ea8ae01acb3daf8ba0ee91acd729af7c84c Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 11 22:04:53 2020 +0200 patch 8.2.0738: mouse handling in a terminal window not well tested Problem: Mouse handling in a terminal window not well tested. Solution: Add tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6052)
author Bram Moolenaar <Bram@vim.org>
date Mon, 11 May 2020 22:15:04 +0200
parents a85a3207679f
children 42ab4d40e78f
comparison
equal deleted inserted replaced
20364:79d3567389f1 20365:6bcd12791bf1
3 source check.vim 3 source check.vim
4 CheckFeature terminal 4 CheckFeature terminal
5 5
6 source shared.vim 6 source shared.vim
7 source screendump.vim 7 source screendump.vim
8 source mouse.vim
8 9
9 let s:python = PythonProg() 10 let s:python = PythonProg()
10 let $PROMPT_COMMAND='' 11 let $PROMPT_COMMAND=''
11 12
12 " Open a terminal with a shell, assign the job to g:job and return the buffer 13 " Open a terminal with a shell, assign the job to g:job and return the buffer
1204 call delete('Xcomposing') 1205 call delete('Xcomposing')
1205 call delete('Xdump') 1206 call delete('Xdump')
1206 let &encoding = save_enc 1207 let &encoding = save_enc
1207 endfunc 1208 endfunc
1208 1209
1210 " Tests for failures in the term_dumpwrite() function
1211 func Test_terminal_dumpwrite_errors()
1212 CheckRunVimInTerminal
1213 call assert_fails("call term_dumpwrite({}, 'Xtest.dump')", 'E728:')
1214 let buf = RunVimInTerminal('', {})
1215 call term_wait(buf)
1216 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump', '')", 'E715:')
1217 call assert_fails("call term_dumpwrite(buf, [])", 'E730:')
1218 call writefile([], 'Xtest.dump')
1219 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E953:')
1220 call delete('Xtest.dump')
1221 call assert_fails("call term_dumpwrite(buf, '')", 'E482:')
1222 call assert_fails("call term_dumpwrite(buf, test_null_string())", 'E482:')
1223 call StopVimInTerminal(buf)
1224 call term_wait(buf)
1225 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E958:')
1226 call assert_fails('call term_sendkeys([], ":q\<CR>")', 'E745:')
1227 call assert_equal(0, term_sendkeys(buf, ":q\<CR>"))
1228 endfunc
1229
1209 " just testing basic functionality. 1230 " just testing basic functionality.
1210 func Test_terminal_dumpload() 1231 func Test_terminal_dumpload()
1211 let curbuf = winbufnr('') 1232 let curbuf = winbufnr('')
1212 call assert_equal(1, winnr('$')) 1233 call assert_equal(1, winnr('$'))
1213 let buf = term_dumpload('dumps/Test_popup_command_01.dump') 1234 let buf = term_dumpload('dumps/Test_popup_command_01.dump')
1229 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:') 1250 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:')
1230 new 1251 new
1231 let closedbuf = winbufnr('') 1252 let closedbuf = winbufnr('')
1232 quit 1253 quit
1233 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:') 1254 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:')
1255 call assert_fails('call term_dumpload([])', 'E474:')
1256 call assert_fails('call term_dumpload("xabcy.dump")', 'E485:')
1234 1257
1235 quit 1258 quit
1236 endfunc 1259 endfunc
1237 1260
1238 func Test_terminal_dumpload_dump() 1261 func Test_terminal_dumpload_dump()
1256 call assert_equal(62, line('$')) 1279 call assert_equal(62, line('$'))
1257 call Check_dump01(0) 1280 call Check_dump01(0)
1258 call Check_dump01(42) 1281 call Check_dump01(42)
1259 call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) 1282 call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29])
1260 quit 1283 quit
1284
1285 call assert_fails('call term_dumpdiff("X1.dump", [])', 'E474:')
1286 call assert_fails('call term_dumpdiff("X1.dump", "X2.dump")', 'E485:')
1287 call writefile([], 'X1.dump')
1288 call assert_fails('call term_dumpdiff("X1.dump", "X2.dump")', 'E485:')
1289 call delete('X1.dump')
1261 endfunc 1290 endfunc
1262 1291
1263 func Test_terminal_dumpdiff_swap() 1292 func Test_terminal_dumpdiff_swap()
1264 call assert_equal(1, winnr('$')) 1293 call assert_equal(1, winnr('$'))
1265 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_03.dump') 1294 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_03.dump')
2650 call assert_fails('call term_setapi([], "")', 'E745:') 2679 call assert_fails('call term_setapi([], "")', 'E745:')
2651 call assert_fails('call term_setrestore([], "")', 'E745:') 2680 call assert_fails('call term_setrestore([], "")', 'E745:')
2652 call assert_fails('call term_setkill([], "")', 'E745:') 2681 call assert_fails('call term_setkill([], "")', 'E745:')
2653 endfunc 2682 endfunc
2654 2683
2684 " Test for sending various special keycodes to a terminal
2685 func Test_term_keycode_translation()
2686 CheckRunVimInTerminal
2687
2688 let buf = RunVimInTerminal('', {})
2689 call term_sendkeys(buf, ":set nocompatible\<CR>")
2690
2691 let keys = ["\<F1>", "\<F2>", "\<F3>", "\<F4>", "\<F5>", "\<F6>", "\<F7>",
2692 \ "\<F8>", "\<F9>", "\<F10>", "\<F11>", "\<F12>", "\<Home>",
2693 \ "\<S-Home>", "\<C-Home>", "\<End>", "\<S-End>", "\<C-End>",
2694 \ "\<Ins>", "\<Del>", "\<Left>", "\<S-Left>", "\<C-Left>", "\<Right>",
2695 \ "\<S-Right>", "\<C-Right>", "\<Up>", "\<S-Up>", "\<Down>",
2696 \ "\<S-Down>"]
2697 let output = ['<F1>', '<F2>', '<F3>', '<F4>', '<F5>', '<F6>', '<F7>',
2698 \ '<F8>', '<F9>', '<F10>', '<F11>', '<F12>', '<Home>', '<S-Home>',
2699 \ '<C-Home>', '<End>', '<S-End>', '<C-End>', '<Insert>', '<Del>',
2700 \ '<Left>', '<S-Left>', '<C-Left>', '<Right>', '<S-Right>',
2701 \ '<C-Right>', '<Up>', '<S-Up>', '<Down>', '<S-Down>',
2702 \ '0123456789', "\t\t.+-*/"]
2703
2704 for k in keys
2705 call term_sendkeys(buf, "i\<C-K>" .. k .. "\<CR>\<C-\>\<C-N>")
2706 endfor
2707 call term_sendkeys(buf, "i\<K0>\<K1>\<K2>\<K3>\<K4>\<K5>\<K6>\<K7>")
2708 call term_sendkeys(buf, "\<K8>\<K9>\<kEnter>\<kPoint>\<kPlus>")
2709 call term_sendkeys(buf, "\<kMinus>\<kMultiply>\<kDivide>\<C-\>\<C-N>")
2710 call term_sendkeys(buf, "\<Home>\<Ins>\<Tab>\<S-Tab>\<C-\>\<C-N>")
2711
2712 call term_sendkeys(buf, ":write Xkeycodes\<CR>")
2713 call term_wait(buf)
2714 call StopVimInTerminal(buf)
2715 call assert_equal(output, readfile('Xkeycodes'))
2716 call delete('Xkeycodes')
2717 endfunc
2718
2719 " Test for using the mouse in a terminal
2720 func Test_term_mouse()
2721 CheckNotGui
2722 CheckRunVimInTerminal
2723
2724 let save_mouse = &mouse
2725 let save_term = &term
2726 let save_ttymouse = &ttymouse
2727 let save_clipboard = &clipboard
2728 call test_override('no_query_mouse', 1)
2729 set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard=
2730
2731 let lines =<< trim END
2732 one two three four five
2733 red green yellow red blue
2734 vim emacs sublime nano
2735 END
2736 call writefile(lines, 'Xtest_mouse')
2737
2738 let buf = RunVimInTerminal('Xtest_mouse -n', {})
2739 call term_sendkeys(buf, ":set nocompatible\<CR>")
2740 call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>")
2741 call term_sendkeys(buf, ":set clipboard=\<CR>")
2742 call term_sendkeys(buf, ":set mousemodel=extend\<CR>")
2743 call term_wait(buf)
2744 redraw!
2745
2746 " Test for <LeftMouse> click/release
2747 call test_setmouse(2, 5)
2748 call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt')
2749 call test_setmouse(3, 8)
2750 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>")
2751 call term_wait(buf, 50)
2752 call term_sendkeys(buf, ":call writefile([json_encode(getpos('.'))], 'Xbuf')\<CR>")
2753 call term_wait(buf, 50)
2754 let pos = json_decode(readfile('Xbuf')[0])
2755 call assert_equal([3, 8], pos[1:2])
2756
2757 " Test for selecting text using mouse
2758 call delete('Xbuf')
2759 call test_setmouse(2, 11)
2760 call term_sendkeys(buf, "\<LeftMouse>")
2761 call test_setmouse(2, 16)
2762 call term_sendkeys(buf, "\<LeftRelease>y")
2763 call term_wait(buf, 50)
2764 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
2765 call term_wait(buf, 50)
2766 call assert_equal('yellow', readfile('Xbuf')[0])
2767
2768 " Test for selecting text using doubleclick
2769 call delete('Xbuf')
2770 call test_setmouse(1, 11)
2771 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>")
2772 call test_setmouse(1, 17)
2773 call term_sendkeys(buf, "\<LeftRelease>y")
2774 call term_wait(buf, 50)
2775 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
2776 call term_wait(buf, 50)
2777 call assert_equal('three four', readfile('Xbuf')[0])
2778
2779 " Test for selecting a line using triple click
2780 call delete('Xbuf')
2781 call test_setmouse(3, 2)
2782 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>y")
2783 call term_wait(buf, 50)
2784 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
2785 call term_wait(buf, 50)
2786 call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0])
2787
2788 " Test for selecting a block using qudraple click
2789 call delete('Xbuf')
2790 call test_setmouse(1, 11)
2791 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>")
2792 call test_setmouse(3, 13)
2793 call term_sendkeys(buf, "\<LeftRelease>y")
2794 call term_wait(buf, 50)
2795 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
2796 call term_wait(buf, 50)
2797 call assert_equal("ree\nyel\nsub", readfile('Xbuf')[0])
2798
2799 " Test for extending a selection using right click
2800 call delete('Xbuf')
2801 call test_setmouse(2, 9)
2802 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>")
2803 call test_setmouse(2, 16)
2804 call term_sendkeys(buf, "\<RightMouse>\<RightRelease>y")
2805 call term_wait(buf, 50)
2806 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
2807 call term_wait(buf, 50)
2808 call assert_equal("n yellow", readfile('Xbuf')[0])
2809
2810 " Test for pasting text using middle click
2811 call delete('Xbuf')
2812 call term_sendkeys(buf, ":let @r='bright '\<CR>")
2813 call test_setmouse(2, 22)
2814 call term_sendkeys(buf, "\"r\<MiddleMouse>\<MiddleRelease>")
2815 call term_wait(buf, 50)
2816 call term_sendkeys(buf, ":call writefile([getline(2)], 'Xbuf')\<CR>")
2817 call term_wait(buf, 50)
2818 call assert_equal("red bright blue", readfile('Xbuf')[0][-15:])
2819
2820 " cleanup
2821 call term_wait(buf)
2822 call StopVimInTerminal(buf)
2823 let &mouse = save_mouse
2824 let &term = save_term
2825 let &ttymouse = save_ttymouse
2826 let &clipboard = save_clipboard
2827 set mousetime&
2828 call test_override('no_query_mouse', 0)
2829 call delete('Xtest_mouse')
2830 call delete('Xbuf')
2831 endfunc
2832
2833 " Test for modeless selection in a terminal
2834 func Test_term_modeless_selection()
2835 CheckUnix
2836 CheckNotGui
2837 CheckRunVimInTerminal
2838 CheckFeature clipboard_working
2839
2840 let save_mouse = &mouse
2841 let save_term = &term
2842 let save_ttymouse = &ttymouse
2843 call test_override('no_query_mouse', 1)
2844 set mouse=a term=xterm ttymouse=sgr mousetime=200
2845 set clipboard=autoselectml
2846
2847 let lines =<< trim END
2848 one two three four five
2849 red green yellow red blue
2850 vim emacs sublime nano
2851 END
2852 call writefile(lines, 'Xtest_modeless')
2853
2854 let buf = RunVimInTerminal('Xtest_modeless -n', {})
2855 call term_sendkeys(buf, ":set nocompatible\<CR>")
2856 call term_sendkeys(buf, ":set mouse=\<CR>")
2857 call term_wait(buf)
2858 redraw!
2859
2860 " Test for copying a modeless selection to clipboard
2861 let @* = 'clean'
2862 " communicating with X server may take a little time
2863 sleep 100m
2864 call feedkeys(MouseLeftClickCode(2, 3), 'x')
2865 call feedkeys(MouseLeftDragCode(2, 11), 'x')
2866 call feedkeys(MouseLeftReleaseCode(2, 11), 'x')
2867 call assert_equal("d green y", @*)
2868
2869 " cleanup
2870 call term_wait(buf)
2871 call StopVimInTerminal(buf)
2872 let &mouse = save_mouse
2873 let &term = save_term
2874 let &ttymouse = save_ttymouse
2875 set mousetime& clipboard&
2876 call test_override('no_query_mouse', 0)
2877 call delete('Xtest_modeless')
2878 endfunc
2879
2655 " vim: shiftwidth=2 sts=2 expandtab 2880 " vim: shiftwidth=2 sts=2 expandtab