comparison src/testdir/test_terminal.vim @ 18033:049a7481d737 v8.1.2012

patch 8.1.2012: more functions can be used as methods Commit: https://github.com/vim/vim/commit/7ee80f766130f22598c928415c92ec612a8f18cf Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 8 20:55:06 2019 +0200 patch 8.1.2012: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make terminal functions usable as a method. Fix term_getattr().
author Bram Moolenaar <Bram@vim.org>
date Sun, 08 Sep 2019 21:00:03 +0200
parents 9fac6d0de69a
children 6a7b778119f1
comparison
equal deleted inserted replaced
18032:403b2abc9147 18033:049a7481d737
23 call assert_equal(buf, termlist[0]) 23 call assert_equal(buf, termlist[0])
24 24
25 let g:job = term_getjob(buf) 25 let g:job = term_getjob(buf)
26 call assert_equal(v:t_job, type(g:job)) 26 call assert_equal(v:t_job, type(g:job))
27 27
28 let string = string({'job': term_getjob(buf)}) 28 let string = string({'job': buf->term_getjob()})
29 call assert_match("{'job': 'process \\d\\+ run'}", string) 29 call assert_match("{'job': 'process \\d\\+ run'}", string)
30 30
31 return buf 31 return buf
32 endfunc 32 endfunc
33 33
40 call assert_match('^/dev/', term_gettty('')) 40 call assert_match('^/dev/', term_gettty(''))
41 else 41 else
42 " ConPTY works on anonymous pipe. 42 " ConPTY works on anonymous pipe.
43 if !has('conpty') 43 if !has('conpty')
44 call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out) 44 call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out)
45 call assert_match('^\\\\.\\pipe\\', term_gettty('')) 45 call assert_match('^\\\\.\\pipe\\', ''->term_gettty())
46 endif 46 endif
47 endif 47 endif
48 call assert_equal('t', mode()) 48 call assert_equal('t', mode())
49 call assert_equal('yes', b:done) 49 call assert_equal('yes', b:done)
50 call assert_match('%aR[^\n]*running]', execute('ls')) 50 call assert_match('%aR[^\n]*running]', execute('ls'))
89 " Wait for the shell to display a prompt 89 " Wait for the shell to display a prompt
90 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) 90 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
91 91
92 call feedkeys("echo \<C-W>\"\" \<C-W>\"=37 + 5\<CR>\<CR>", 'xt') 92 call feedkeys("echo \<C-W>\"\" \<C-W>\"=37 + 5\<CR>\<CR>", 'xt')
93 call WaitForAssert({-> assert_match("echo text to paste 42$", getline(1))}) 93 call WaitForAssert({-> assert_match("echo text to paste 42$", getline(1))})
94 call WaitForAssert({-> assert_equal('text to paste 42', getline(2))}) 94 call WaitForAssert({-> assert_equal('text to paste 42', 2->getline())})
95 95
96 exe buf . 'bwipe!' 96 exe buf . 'bwipe!'
97 unlet g:job 97 unlet g:job
98 endfunc 98 endfunc
99 99
174 func Check_123(buf) 174 func Check_123(buf)
175 let l = term_scrape(a:buf, 0) 175 let l = term_scrape(a:buf, 0)
176 call assert_true(len(l) == 0) 176 call assert_true(len(l) == 0)
177 let l = term_scrape(a:buf, 999) 177 let l = term_scrape(a:buf, 999)
178 call assert_true(len(l) == 0) 178 call assert_true(len(l) == 0)
179 let l = term_scrape(a:buf, 1) 179 let l = a:buf->term_scrape(1)
180 call assert_true(len(l) > 0) 180 call assert_true(len(l) > 0)
181 call assert_equal('1', l[0].chars) 181 call assert_equal('1', l[0].chars)
182 call assert_equal('2', l[1].chars) 182 call assert_equal('2', l[1].chars)
183 call assert_equal('3', l[2].chars) 183 call assert_equal('3', l[2].chars)
184 call assert_equal('#00e000', l[0].fg) 184 call assert_equal('#00e000', l[0].fg)
185 call assert_equal(0, term_getattr(l[0].attr, 'bold'))
186 call assert_equal(0, l[0].attr->term_getattr('italic'))
185 if has('win32') 187 if has('win32')
186 " On Windows 'background' always defaults to dark, even though the terminal 188 " On Windows 'background' always defaults to dark, even though the terminal
187 " may use a light background. Therefore accept both white and black. 189 " may use a light background. Therefore accept both white and black.
188 call assert_match('#ffffff\|#000000', l[0].bg) 190 call assert_match('#ffffff\|#000000', l[0].bg)
189 else 191 else
236 if has('win32') 238 if has('win32')
237 " Run cmd with UTF-8 codepage to make the type command print the expected 239 " Run cmd with UTF-8 codepage to make the type command print the expected
238 " multibyte characters. 240 " multibyte characters.
239 let buf = term_start("cmd /K chcp 65001") 241 let buf = term_start("cmd /K chcp 65001")
240 call term_sendkeys(buf, "type Xtext\<CR>") 242 call term_sendkeys(buf, "type Xtext\<CR>")
241 call term_sendkeys(buf, "exit\<CR>") 243 eval buf->term_sendkeys("exit\<CR>")
242 let line = 4 244 let line = 4
243 else 245 else
244 let buf = term_start("cat Xtext") 246 let buf = term_start("cat Xtext")
245 let line = 1 247 let line = 1
246 endif 248 endif
281 if has('win32') 283 if has('win32')
282 " TODO: this should not be needed 284 " TODO: this should not be needed
283 sleep 100m 285 sleep 100m
284 endif 286 endif
285 287
286 let scrolled = term_getscrolled(buf) 288 let scrolled = buf->term_getscrolled()
289 call assert_equal(scrolled, term_getscrolled(buf))
287 call assert_equal('1', getline(1)) 290 call assert_equal('1', getline(1))
288 call assert_equal('1', term_getline(buf, 1 - scrolled)) 291 call assert_equal('1', term_getline(buf, 1 - scrolled))
289 call assert_equal('49', getline(49)) 292 call assert_equal('49', getline(49))
290 call assert_equal('49', term_getline(buf, 49 - scrolled)) 293 call assert_equal('49', term_getline(buf, 49 - scrolled))
291 call assert_equal('200', getline(200)) 294 call assert_equal('200', getline(200))
381 bwipe! 384 bwipe!
382 call assert_equal(6, size[0]) 385 call assert_equal(6, size[0])
383 386
384 vsplit 387 vsplit
385 exe 'terminal ++rows=5 ++cols=33 ' . cmd 388 exe 'terminal ++rows=5 ++cols=33 ' . cmd
386 call assert_equal([5, 33], term_getsize('')) 389 call assert_equal([5, 33], ''->term_getsize())
387 390
388 call term_setsize('', 6, 0) 391 call term_setsize('', 6, 0)
389 call assert_equal([6, 33], term_getsize('')) 392 call assert_equal([6, 33], term_getsize(''))
390 393
391 call term_setsize('', 0, 35) 394 eval ''->term_setsize(0, 35)
392 call assert_equal([6, 35], term_getsize('')) 395 call assert_equal([6, 35], term_getsize(''))
393 396
394 call term_setsize('', 7, 30) 397 call term_setsize('', 7, 30)
395 call assert_equal([7, 30], term_getsize('')) 398 call assert_equal([7, 30], term_getsize(''))
396 399
405 exe 'vertical terminal ++cols=20 ' . cmd 408 exe 'vertical terminal ++cols=20 ' . cmd
406 let size = term_getsize('') 409 let size = term_getsize('')
407 bwipe! 410 bwipe!
408 call assert_equal(20, size[1]) 411 call assert_equal(20, size[1])
409 412
410 call term_start(cmd, {'vertical': 1, 'term_cols': 26}) 413 eval cmd->term_start({'vertical': 1, 'term_cols': 26})
411 let size = term_getsize('') 414 let size = term_getsize('')
412 bwipe! 415 bwipe!
413 call assert_equal(26, size[1]) 416 call assert_equal(26, size[1])
414 417
415 split 418 split
616 if has('win32') 619 if has('win32')
617 call term_sendkeys(buf, "echo %TESTENV%\r") 620 call term_sendkeys(buf, "echo %TESTENV%\r")
618 else 621 else
619 call term_sendkeys(buf, "echo $TESTENV\r") 622 call term_sendkeys(buf, "echo $TESTENV\r")
620 endif 623 endif
621 call term_wait(buf) 624 eval buf->term_wait()
622 call StopShellInTerminal(buf) 625 call StopShellInTerminal(buf)
623 call WaitForAssert({-> assert_equal('correct', getline(2))}) 626 call WaitForAssert({-> assert_equal('correct', getline(2))})
624 627
625 exe buf . 'bwipe' 628 exe buf . 'bwipe'
626 endfunc 629 endfunc
1004 endfunc 1007 endfunc
1005 1008
1006 " Run Vim, start a terminal in that Vim, set the kill argument with 1009 " Run Vim, start a terminal in that Vim, set the kill argument with
1007 " term_setkill(), check that :qall works. 1010 " term_setkill(), check that :qall works.
1008 func Test_terminal_qall_kill_func() 1011 func Test_terminal_qall_kill_func()
1009 call Run_terminal_qall_kill('term', 'call term_setkill(buf, "kill")') 1012 call Run_terminal_qall_kill('term', 'eval buf->term_setkill("kill")')
1010 endfunc 1013 endfunc
1011 1014
1012 " Run Vim, start a terminal in that Vim without the kill argument, 1015 " Run Vim, start a terminal in that Vim without the kill argument,
1013 " check that :qall does not exit, :qall! does. 1016 " check that :qall does not exit, :qall! does.
1014 func Test_terminal_qall_exit() 1017 func Test_terminal_qall_exit()
1105 1108
1106 let text = " a\u0300 e\u0302 o\u0308" 1109 let text = " a\u0300 e\u0302 o\u0308"
1107 call writefile([text], 'Xcomposing') 1110 call writefile([text], 'Xcomposing')
1108 let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {}) 1111 let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {})
1109 call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) 1112 call WaitForAssert({-> assert_match(text, term_getline(buf, 1))})
1110 call term_dumpwrite(buf, 'Xdump') 1113 eval 'Xdump'->term_dumpwrite(buf)
1111 let dumpline = readfile('Xdump')[0] 1114 let dumpline = readfile('Xdump')[0]
1112 call assert_match('|à| |ê| |ö', dumpline) 1115 call assert_match('|à| |ê| |ö', dumpline)
1113 1116
1114 call StopVimInTerminal(buf) 1117 call StopVimInTerminal(buf)
1115 call delete('Xcomposing') 1118 call delete('Xcomposing')
1125 call assert_equal(2, winnr('$')) 1128 call assert_equal(2, winnr('$'))
1126 call assert_equal(20, line('$')) 1129 call assert_equal(20, line('$'))
1127 call Check_dump01(0) 1130 call Check_dump01(0)
1128 1131
1129 " Load another dump in the same window 1132 " Load another dump in the same window
1130 let buf2 = term_dumpload('dumps/Test_diff_01.dump', {'bufnr': buf}) 1133 let buf2 = 'dumps/Test_diff_01.dump'->term_dumpload({'bufnr': buf})
1131 call assert_equal(buf, buf2) 1134 call assert_equal(buf, buf2)
1132 call assert_notequal('one two three four five', trim(getline(1))) 1135 call assert_notequal('one two three four five', trim(getline(1)))
1133 1136
1134 " Load the first dump again in the same window 1137 " Load the first dump again in the same window
1135 let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf}) 1138 let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf})
1146 quit 1149 quit
1147 endfunc 1150 endfunc
1148 1151
1149 func Test_terminal_dumpdiff() 1152 func Test_terminal_dumpdiff()
1150 call assert_equal(1, winnr('$')) 1153 call assert_equal(1, winnr('$'))
1151 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump') 1154 eval 'dumps/Test_popup_command_01.dump'->term_dumpdiff('dumps/Test_popup_command_02.dump')
1152 call assert_equal(2, winnr('$')) 1155 call assert_equal(2, winnr('$'))
1153 call assert_equal(62, line('$')) 1156 call assert_equal(62, line('$'))
1154 call Check_dump01(0) 1157 call Check_dump01(0)
1155 call Check_dump01(42) 1158 call Check_dump01(42)
1156 call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) 1159 call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29])
1488 let g:terminal_ansi_colors = reverse(copy(s:test_colors)) 1491 let g:terminal_ansi_colors = reverse(copy(s:test_colors))
1489 let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) 1492 let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors})
1490 call assert_equal(s:test_colors, term_getansicolors(buf)) 1493 call assert_equal(s:test_colors, term_getansicolors(buf))
1491 1494
1492 call term_setansicolors(buf, g:terminal_ansi_colors) 1495 call term_setansicolors(buf, g:terminal_ansi_colors)
1493 call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) 1496 call assert_equal(g:terminal_ansi_colors, buf->term_getansicolors())
1494 1497
1495 let colors = [ 1498 let colors = [
1496 \ 'ivory', 'AliceBlue', 1499 \ 'ivory', 'AliceBlue',
1497 \ 'grey67', 'dark goldenrod', 1500 \ 'grey67', 'dark goldenrod',
1498 \ 'SteelBlue3', 'PaleVioletRed4', 1501 \ 'SteelBlue3', 'PaleVioletRed4',
1500 \ 'RosyBrown3', 'OrangeRed2', 1503 \ 'RosyBrown3', 'OrangeRed2',
1501 \ 'white smoke', 'navy blue', 1504 \ 'white smoke', 'navy blue',
1502 \ 'grey47', 'gray97', 1505 \ 'grey47', 'gray97',
1503 \ 'MistyRose2', 'DodgerBlue4', 1506 \ 'MistyRose2', 'DodgerBlue4',
1504 \] 1507 \]
1505 call term_setansicolors(buf, colors) 1508 eval buf->term_setansicolors(colors)
1506 1509
1507 let colors[4] = 'Invalid' 1510 let colors[4] = 'Invalid'
1508 call assert_fails('call term_setansicolors(buf, colors)', 'E474:') 1511 call assert_fails('call term_setansicolors(buf, colors)', 'E474:')
1509 1512
1510 call StopShellInTerminal(buf) 1513 call StopShellInTerminal(buf)
1854 exe 'sbuf ' . bnr 1857 exe 'sbuf ' . bnr
1855 call assert_equal('terminal', &buftype) 1858 call assert_equal('terminal', &buftype)
1856 call term_sendkeys(bnr, "asdf\<CR>") 1859 call term_sendkeys(bnr, "asdf\<CR>")
1857 call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))}) 1860 call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))})
1858 call term_sendkeys(bnr, "\<C-D>") 1861 call term_sendkeys(bnr, "\<C-D>")
1859 call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) 1862 call WaitForAssert({-> assert_equal('finished', bnr->term_getstatus())})
1860 bwipe! 1863 bwipe!
1861 endfunc 1864 endfunc
1862 1865
1863 func Test_terminal_switch_mode() 1866 func Test_terminal_switch_mode()
1864 term 1867 term
1942 call term_sendkeys(buf, "echo -e '\\033[?25l'\r") 1945 call term_sendkeys(buf, "echo -e '\\033[?25l'\r")
1943 call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)}) 1946 call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)})
1944 1947
1945 " Show the cursor. 1948 " Show the cursor.
1946 call term_sendkeys(buf, "echo -e '\\033[?25h'\r") 1949 call term_sendkeys(buf, "echo -e '\\033[?25h'\r")
1947 call WaitForAssert({-> assert_equal(1, term_getcursor(buf)[2].visible)}) 1950 call WaitForAssert({-> assert_equal(1, buf->term_getcursor()[2].visible)})
1948 1951
1949 " Change color of cursor. 1952 " Change color of cursor.
1950 call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)}) 1953 call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)})
1951 call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r") 1954 call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r")
1952 call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)}) 1955 call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)})
1987 endfunc 1990 endfunc
1988 1991
1989 func Test_term_gettitle() 1992 func Test_term_gettitle()
1990 " term_gettitle() returns an empty string for a non-terminal buffer 1993 " term_gettitle() returns an empty string for a non-terminal buffer
1991 " and for a non-existing buffer. 1994 " and for a non-existing buffer.
1992 call assert_equal('', term_gettitle(bufnr('%'))) 1995 call assert_equal('', bufnr('%')->term_gettitle())
1993 call assert_equal('', term_gettitle(bufnr('$') + 1)) 1996 call assert_equal('', term_gettitle(bufnr('$') + 1))
1994 1997
1995 if !has('title') || &title == 0 || empty(&t_ts) 1998 if !has('title') || &title == 0 || empty(&t_ts)
1996 throw "Skipped: can't get/set title" 1999 throw "Skipped: can't get/set title"
1997 endif 2000 endif
2081 call delete('XTest_getwinpos') 2084 call delete('XTest_getwinpos')
2082 exe buf . 'bwipe!' 2085 exe buf . 'bwipe!'
2083 set splitright& 2086 set splitright&
2084 only! 2087 only!
2085 endfunc 2088 endfunc
2089
2090 func Test_terminal_altscreen()
2091 CheckUnix
2092
2093 let buf = term_start(&shell, {})
2094
2095 call term_sendkeys(buf, 'echo "\e[?1047h"' .. "\r")
2096 call term_wait(buf)
2097 call assert_equal(1, term_getaltscreen(buf))
2098 call term_sendkeys(buf, 'echo "\e[?1047l"' .. "\r")
2099 call term_wait(buf)
2100 call assert_equal(0, buf->term_getaltscreen())
2101
2102 call term_sendkeys(buf, "exit\r")
2103 exe buf . "bwipe!"
2104 endfunc