Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 1 | " Tests for the terminal window. |
| 2 | |
| 3 | if !exists('*term_start') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | source shared.vim |
| 8 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 9 | func Run_shell_in_terminal() |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 10 | 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 Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 23 | return buf |
| 24 | endfunc |
| 25 | |
| 26 | func Test_terminal_basic() |
| 27 | let buf = Run_shell_in_terminal() |
| 28 | |
| 29 | exe buf . 'bwipe' |
| 30 | unlet g:job |
| 31 | endfunc |
| 32 | |
| 33 | func 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 Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 42 | exe buf . 'bwipe' |
| 43 | unlet g:job |
| 44 | endfunc |
| 45 | |
| 46 | func Check_123(buf) |
Bram Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 47 | let l = term_scrape(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 48 | 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 Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 59 | let l = term_getline(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 60 | call assert_equal('123', l) |
| 61 | endfunc |
| 62 | |
| 63 | func 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 Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 76 | " Nothing happens with invalid buffer number |
| 77 | call term_wait(1234) |
| 78 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 79 | 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 Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 89 | call delete('Xtext') |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 90 | endfunc |