blob: 154aab95000836a92336b1e349c43ab3cb04b83b [file] [log] [blame]
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02001" Tests for the terminal window.
2
3if !exists('*term_start')
4 finish
5endif
6
7source shared.vim
8
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02009func Run_shell_in_terminal()
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020010 let buf = term_start(&shell)
11
12 let termlist = term_list()
13 call assert_equal(1, len(termlist))
14 call assert_equal(buf, termlist[0])
15
16 let g:job = term_getjob(buf)
17 call assert_equal(v:t_job, type(g:job))
18
19 call term_sendkeys(buf, "exit\r")
20 call WaitFor('job_status(g:job) == "dead"')
21 call assert_equal('dead', job_status(g:job))
22
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020023 return buf
24endfunc
25
26func Test_terminal_basic()
27 let buf = Run_shell_in_terminal()
28
29 exe buf . 'bwipe'
30 unlet g:job
31endfunc
32
33func Test_terminal_make_change()
34 let buf = Run_shell_in_terminal()
35 call term_wait(buf)
36
37 setlocal modifiable
38 exe "normal Axxx\<Esc>"
39 call assert_fails(buf . 'bwipe', 'E517')
40 undo
41
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020042 exe buf . 'bwipe'
43 unlet g:job
44endfunc
45
46func Check_123(buf)
Bram Moolenaar9c844842017-08-01 18:41:21 +020047 let l = term_scrape(a:buf, 1)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020048 call assert_true(len(l) > 0)
49 call assert_equal('1', l[0].chars)
50 call assert_equal('2', l[1].chars)
51 call assert_equal('3', l[2].chars)
52 call assert_equal('#00e000', l[0].fg)
53 if &background == 'light'
54 call assert_equal('#ffffff', l[0].bg)
55 else
56 call assert_equal('#000000', l[0].bg)
57 endif
58
Bram Moolenaar9c844842017-08-01 18:41:21 +020059 let l = term_getline(a:buf, 1)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020060 call assert_equal('123', l)
61endfunc
62
63func Test_terminal_scrape()
64 if has('win32')
65 let cmd = 'cmd /c "cls && color 2 && echo 123"'
66 else
67 call writefile(["\<Esc>[32m123"], 'Xtext')
68 let cmd = "cat Xtext"
69 endif
70 let buf = term_start(cmd)
71
72 let termlist = term_list()
73 call assert_equal(1, len(termlist))
74 call assert_equal(buf, termlist[0])
75
Bram Moolenaarf144a3f2017-07-30 18:02:12 +020076 " Nothing happens with invalid buffer number
77 call term_wait(1234)
78
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020079 call term_wait(buf)
80 call Check_123(buf)
81
82 " Must still work after the job ended.
83 let g:job = term_getjob(buf)
84 call WaitFor('job_status(g:job) == "dead"')
85 call term_wait(buf)
86 call Check_123(buf)
87
88 exe buf . 'bwipe'
Bram Moolenaarf144a3f2017-07-30 18:02:12 +020089 call delete('Xtext')
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020090endfunc