Mercurial > vim
comparison src/testdir/test_terminal.vim @ 20508:357dea6b9fde v8.2.0808
patch 8.2.0808: not enough testing for the terminal window
Commit: https://github.com/vim/vim/commit/98f1671cc0ab0ad6139cb9c6ce5262e7f646bc0a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 22 13:34:01 2020 +0200
patch 8.2.0808: not enough testing for the terminal window
Problem: Not enough testing for the terminal window.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6069) Fix memory
leak.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 22 May 2020 13:45:03 +0200 |
parents | f28a49da879d |
children | eb8715fac6c3 |
comparison
equal
deleted
inserted
replaced
20507:6dd44f4380bd | 20508:357dea6b9fde |
---|---|
1218 call writefile([], 'Xtest.dump') | 1218 call writefile([], 'Xtest.dump') |
1219 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E953:') | 1219 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E953:') |
1220 call delete('Xtest.dump') | 1220 call delete('Xtest.dump') |
1221 call assert_fails("call term_dumpwrite(buf, '')", 'E482:') | 1221 call assert_fails("call term_dumpwrite(buf, '')", 'E482:') |
1222 call assert_fails("call term_dumpwrite(buf, test_null_string())", 'E482:') | 1222 call assert_fails("call term_dumpwrite(buf, test_null_string())", 'E482:') |
1223 call test_garbagecollect_now() | |
1223 call StopVimInTerminal(buf) | 1224 call StopVimInTerminal(buf) |
1224 call term_wait(buf) | 1225 call term_wait(buf) |
1225 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E958:') | 1226 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E958:') |
1226 call assert_fails('call term_sendkeys([], ":q\<CR>")', 'E745:') | 1227 call assert_fails('call term_sendkeys([], ":q\<CR>")', 'E745:') |
1227 call assert_equal(0, term_sendkeys(buf, ":q\<CR>")) | 1228 call assert_equal(0, term_sendkeys(buf, ":q\<CR>")) |
1302 normal s | 1303 normal s |
1303 call assert_match('Test_popup_command_03.dump', getline(21)) | 1304 call assert_match('Test_popup_command_03.dump', getline(21)) |
1304 call assert_match('Test_popup_command_01.dump', getline(42)) | 1305 call assert_match('Test_popup_command_01.dump', getline(42)) |
1305 call assert_match('three four five', getline(3)) | 1306 call assert_match('three four five', getline(3)) |
1306 call assert_match('Undo', getline(45)) | 1307 call assert_match('Undo', getline(45)) |
1308 quit | |
1309 | |
1310 " Diff two terminal dump files with different number of rows | |
1311 " Swap the diffs | |
1312 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_winline_rnu.dump') | |
1313 call assert_match('Test_popup_command_01.dump', getline(21)) | |
1314 call assert_match('Test_winline_rnu.dump', getline(42)) | |
1315 normal s | |
1316 call assert_match('Test_winline_rnu.dump', getline(6)) | |
1317 call assert_match('Test_popup_command_01.dump', getline(27)) | |
1307 quit | 1318 quit |
1308 endfunc | 1319 endfunc |
1309 | 1320 |
1310 func Test_terminal_dumpdiff_options() | 1321 func Test_terminal_dumpdiff_options() |
1311 set laststatus=0 | 1322 set laststatus=0 |
1617 | 1628 |
1618 let buf = Run_shell_in_terminal({}) | 1629 let buf = Run_shell_in_terminal({}) |
1619 call assert_equal(colors, term_getansicolors(buf)) | 1630 call assert_equal(colors, term_getansicolors(buf)) |
1620 call StopShellInTerminal(buf) | 1631 call StopShellInTerminal(buf) |
1621 call TermWait(buf) | 1632 call TermWait(buf) |
1633 call assert_equal([], term_getansicolors(buf)) | |
1622 | 1634 |
1623 exe buf . 'bwipe' | 1635 exe buf . 'bwipe' |
1624 endfunc | 1636 endfunc |
1625 | 1637 |
1626 let s:test_colors = [ | 1638 let s:test_colors = [ |
1671 \] | 1683 \] |
1672 eval buf->term_setansicolors(colors) | 1684 eval buf->term_setansicolors(colors) |
1673 | 1685 |
1674 let colors[4] = 'Invalid' | 1686 let colors[4] = 'Invalid' |
1675 call assert_fails('call term_setansicolors(buf, colors)', 'E474:') | 1687 call assert_fails('call term_setansicolors(buf, colors)', 'E474:') |
1688 call assert_fails('call term_setansicolors(buf, {})', 'E714:') | |
1676 | 1689 |
1677 call StopShellInTerminal(buf) | 1690 call StopShellInTerminal(buf) |
1678 call TermWait(buf) | 1691 call TermWait(buf) |
1692 call assert_equal(0, term_setansicolors(buf, [])) | |
1679 exe buf . 'bwipe' | 1693 exe buf . 'bwipe' |
1680 endfunc | 1694 endfunc |
1681 | 1695 |
1682 func Test_terminal_all_ansi_colors() | 1696 func Test_terminal_all_ansi_colors() |
1683 CheckRunVimInTerminal | 1697 CheckRunVimInTerminal |
2027 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) | 2041 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
2028 call feedkeys("\<C-W>N", 'xt') | 2042 call feedkeys("\<C-W>N", 'xt') |
2029 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) | 2043 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
2030 call feedkeys("A", 'xt') | 2044 call feedkeys("A", 'xt') |
2031 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) | 2045 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
2032 call feedkeys("\<C-W>N", 'xt') | 2046 call feedkeys("\<C-\>\<C-N>", 'xt') |
2033 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) | 2047 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
2034 call feedkeys("I", 'xt') | 2048 call feedkeys("I", 'xt') |
2035 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) | 2049 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
2036 call feedkeys("\<C-W>Nv", 'xt') | 2050 call feedkeys("\<C-W>Nv", 'xt') |
2037 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) | 2051 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
2064 call VerifyScreenDump(buf, 'Test_terminal_normal_2', {}) | 2078 call VerifyScreenDump(buf, 'Test_terminal_normal_2', {}) |
2065 | 2079 |
2066 call term_sendkeys(buf, ":set culopt=line\r") | 2080 call term_sendkeys(buf, ":set culopt=line\r") |
2067 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {}) | 2081 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {}) |
2068 | 2082 |
2083 call assert_fails('call term_sendkeys(buf, [])', 'E730:') | |
2069 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>") | 2084 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>") |
2070 call StopVimInTerminal(buf) | 2085 call StopVimInTerminal(buf) |
2071 call delete('XtermNormal') | 2086 call delete('XtermNormal') |
2072 endfunc | 2087 endfunc |
2073 | 2088 |
2176 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) | 2191 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
2177 | 2192 |
2178 call StopShellInTerminal(buf) | 2193 call StopShellInTerminal(buf) |
2179 endfunc | 2194 endfunc |
2180 | 2195 |
2196 " Test for term_gettitle() | |
2181 func Test_term_gettitle() | 2197 func Test_term_gettitle() |
2182 " term_gettitle() returns an empty string for a non-terminal buffer | 2198 " term_gettitle() returns an empty string for a non-terminal buffer |
2183 " and for a non-existing buffer. | 2199 " and for a non-existing buffer. |
2184 call assert_equal('', bufnr('%')->term_gettitle()) | 2200 call assert_equal('', bufnr('%')->term_gettitle()) |
2185 call assert_equal('', term_gettitle(bufnr('$') + 1)) | 2201 call assert_equal('', term_gettitle(bufnr('$') + 1)) |
2186 | 2202 |
2187 if !has('title') || &title == 0 || empty(&t_ts) | 2203 if !has('title') || empty(&t_ts) |
2188 throw "Skipped: can't get/set title" | 2204 throw "Skipped: can't get/set title" |
2189 endif | 2205 endif |
2190 | 2206 |
2191 let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile']) | 2207 let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', '-c', 'set title']) |
2192 if has('autoservername') | 2208 if has('autoservername') |
2193 call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d\+$', term_gettitle(term)) }) | 2209 call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d\+$', term_gettitle(term)) }) |
2194 call term_sendkeys(term, ":e Xfoo\r") | 2210 call term_sendkeys(term, ":e Xfoo\r") |
2195 call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d\+$', term_gettitle(term)) }) | 2211 call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d\+$', term_gettitle(term)) }) |
2196 else | 2212 else |
2690 call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i]) | 2706 call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i]) |
2691 call term_wait(buf) | 2707 call term_wait(buf) |
2692 call assert_equal(output[i], term_getline(buf, 1)) | 2708 call assert_equal(output[i], term_getline(buf, 1)) |
2693 endfor | 2709 endfor |
2694 | 2710 |
2695 "call term_sendkeys(buf, "\<K0>\<K1>\<K2>\<K3>\<K4>\<K5>\<K6>\<K7>\<K8>\<K9>") | |
2696 "call term_sendkeys(buf, "\<kEnter>\<kPoint>\<kPlus>") | |
2697 "call term_sendkeys(buf, "\<kMinus>\<kMultiply>\<kDivide>") | |
2698 "call term_sendkeys(buf, "\<Esc>") | |
2699 "call term_sendkeys(buf, "\<Home>\<Ins>\<Tab>\<S-Tab>") | |
2700 "call term_sendkeys(buf, "\<Esc>") | |
2701 | |
2702 "call term_sendkeys(buf, ":write Xkeycodes\<CR>") | |
2703 | |
2704 let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>", | 2711 let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>", |
2705 \ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>", | 2712 \ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>", |
2706 \ "\<kMinus>", "\<kMultiply>", "\<kDivide>"] | 2713 \ "\<kMinus>", "\<kMultiply>", "\<kDivide>"] |
2707 let keypad_output = ['0', '1', '2', '3', '4', '5', | 2714 let keypad_output = ['0', '1', '2', '3', '4', '5', |
2708 \ '6', '7', '8', '9', '.', '+', | 2715 \ '6', '7', '8', '9', '.', '+', |
2731 | 2738 |
2732 let save_mouse = &mouse | 2739 let save_mouse = &mouse |
2733 let save_term = &term | 2740 let save_term = &term |
2734 let save_ttymouse = &ttymouse | 2741 let save_ttymouse = &ttymouse |
2735 let save_clipboard = &clipboard | 2742 let save_clipboard = &clipboard |
2736 call test_override('no_query_mouse', 1) | |
2737 set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard= | 2743 set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard= |
2738 | 2744 |
2739 let lines =<< trim END | 2745 let lines =<< trim END |
2740 one two three four five | 2746 one two three four five |
2741 red green yellow red blue | 2747 red green yellow red blue |
2742 vim emacs sublime nano | 2748 vim emacs sublime nano |
2743 END | 2749 END |
2744 call writefile(lines, 'Xtest_mouse') | 2750 call writefile(lines, 'Xtest_mouse') |
2745 | 2751 |
2752 " Create a terminal window running Vim for the test with mouse enabled | |
2753 let prev_win = win_getid() | |
2746 let buf = RunVimInTerminal('Xtest_mouse -n', {}) | 2754 let buf = RunVimInTerminal('Xtest_mouse -n', {}) |
2747 call term_sendkeys(buf, ":set nocompatible\<CR>") | 2755 call term_sendkeys(buf, ":set nocompatible\<CR>") |
2748 call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>") | 2756 call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>") |
2749 call term_sendkeys(buf, ":set clipboard=\<CR>") | 2757 call term_sendkeys(buf, ":set clipboard=\<CR>") |
2750 call term_sendkeys(buf, ":set mousemodel=extend\<CR>") | 2758 call term_sendkeys(buf, ":set mousemodel=extend\<CR>") |
2751 call term_wait(buf) | 2759 call term_wait(buf) |
2752 redraw! | 2760 redraw! |
2761 | |
2762 " Use the mouse to enter the terminal window | |
2763 call win_gotoid(prev_win) | |
2764 call feedkeys(MouseLeftClickCode(1, 1), 'x') | |
2765 call feedkeys(MouseLeftReleaseCode(1, 1), 'x') | |
2766 call assert_equal(1, getwininfo(win_getid())[0].terminal) | |
2753 | 2767 |
2754 " Test for <LeftMouse> click/release | 2768 " Test for <LeftMouse> click/release |
2755 call test_setmouse(2, 5) | 2769 call test_setmouse(2, 5) |
2756 call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt') | 2770 call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt') |
2757 call test_setmouse(3, 8) | 2771 call test_setmouse(3, 8) |
2831 let &mouse = save_mouse | 2845 let &mouse = save_mouse |
2832 let &term = save_term | 2846 let &term = save_term |
2833 let &ttymouse = save_ttymouse | 2847 let &ttymouse = save_ttymouse |
2834 let &clipboard = save_clipboard | 2848 let &clipboard = save_clipboard |
2835 set mousetime& | 2849 set mousetime& |
2836 call test_override('no_query_mouse', 0) | |
2837 call delete('Xtest_mouse') | 2850 call delete('Xtest_mouse') |
2838 call delete('Xbuf') | 2851 call delete('Xbuf') |
2839 endfunc | 2852 endfunc |
2840 | 2853 |
2841 " Test for modeless selection in a terminal | 2854 " Test for modeless selection in a terminal |
2846 CheckFeature clipboard_working | 2859 CheckFeature clipboard_working |
2847 | 2860 |
2848 let save_mouse = &mouse | 2861 let save_mouse = &mouse |
2849 let save_term = &term | 2862 let save_term = &term |
2850 let save_ttymouse = &ttymouse | 2863 let save_ttymouse = &ttymouse |
2851 call test_override('no_query_mouse', 1) | |
2852 set mouse=a term=xterm ttymouse=sgr mousetime=200 | 2864 set mouse=a term=xterm ttymouse=sgr mousetime=200 |
2853 set clipboard=autoselectml | 2865 set clipboard=autoselectml |
2854 | 2866 |
2855 let lines =<< trim END | 2867 let lines =<< trim END |
2856 one two three four five | 2868 one two three four five |
2857 red green yellow red blue | 2869 red green yellow red blue |
2858 vim emacs sublime nano | 2870 vim emacs sublime nano |
2859 END | 2871 END |
2860 call writefile(lines, 'Xtest_modeless') | 2872 call writefile(lines, 'Xtest_modeless') |
2861 | 2873 |
2874 " Create a terminal window running Vim for the test with mouse disabled | |
2875 let prev_win = win_getid() | |
2862 let buf = RunVimInTerminal('Xtest_modeless -n', {}) | 2876 let buf = RunVimInTerminal('Xtest_modeless -n', {}) |
2863 call term_sendkeys(buf, ":set nocompatible\<CR>") | 2877 call term_sendkeys(buf, ":set nocompatible\<CR>") |
2864 call term_sendkeys(buf, ":set mouse=\<CR>") | 2878 call term_sendkeys(buf, ":set mouse=\<CR>") |
2865 call term_wait(buf) | 2879 call term_wait(buf) |
2866 redraw! | 2880 redraw! |
2881 | |
2882 " Use the mouse to enter the terminal window | |
2883 call win_gotoid(prev_win) | |
2884 call feedkeys(MouseLeftClickCode(1, 1), 'x') | |
2885 call feedkeys(MouseLeftReleaseCode(1, 1), 'x') | |
2886 call term_wait(buf) | |
2887 call assert_equal(1, getwininfo(win_getid())[0].terminal) | |
2867 | 2888 |
2868 " Test for copying a modeless selection to clipboard | 2889 " Test for copying a modeless selection to clipboard |
2869 let @* = 'clean' | 2890 let @* = 'clean' |
2870 " communicating with X server may take a little time | 2891 " communicating with X server may take a little time |
2871 sleep 100m | 2892 sleep 100m |
2879 call StopVimInTerminal(buf) | 2900 call StopVimInTerminal(buf) |
2880 let &mouse = save_mouse | 2901 let &mouse = save_mouse |
2881 let &term = save_term | 2902 let &term = save_term |
2882 let &ttymouse = save_ttymouse | 2903 let &ttymouse = save_ttymouse |
2883 set mousetime& clipboard& | 2904 set mousetime& clipboard& |
2884 call test_override('no_query_mouse', 0) | |
2885 call delete('Xtest_modeless') | 2905 call delete('Xtest_modeless') |
2906 new | only! | |
2886 endfunc | 2907 endfunc |
2887 | 2908 |
2888 " vim: shiftwidth=2 sts=2 expandtab | 2909 " vim: shiftwidth=2 sts=2 expandtab |