Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 1 | " test execute() |
| 2 | |
| 3 | func NestedEval() |
| 4 | let nested = execute('echo "nested\nlines"') |
| 5 | echo 'got: "' . nested . '"' |
| 6 | endfunc |
| 7 | |
| 8 | func NestedRedir() |
| 9 | redir => var |
| 10 | echo 'broken' |
| 11 | redir END |
| 12 | endfunc |
| 13 | |
| 14 | func Test_execute_string() |
| 15 | call assert_equal("\nnocompatible", execute('set compatible?')) |
| 16 | call assert_equal("\nsomething\nnice", execute('echo "something\nnice"')) |
| 17 | call assert_equal("noendofline", execute('echon "noendofline"')) |
| 18 | call assert_equal("", execute(123)) |
| 19 | |
| 20 | call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()')) |
| 21 | redir => redired |
| 22 | echo 'this' |
| 23 | let evaled = execute('echo "that"') |
| 24 | echo 'theend' |
| 25 | redir END |
| 26 | call assert_equal("\nthis\ntheend", redired) |
| 27 | call assert_equal("\nthat", evaled) |
| 28 | |
| 29 | call assert_fails('call execute("doesnotexist")', 'E492:') |
| 30 | call assert_fails('call execute(3.4)', 'E806:') |
| 31 | call assert_fails('call execute("call NestedRedir()")', 'E930:') |
| 32 | |
| 33 | call assert_equal("\nsomething", execute('echo "something"', '')) |
| 34 | call assert_equal("\nsomething", execute('echo "something"', 'silent')) |
| 35 | call assert_equal("\nsomething", execute('echo "something"', 'silent!')) |
| 36 | call assert_equal("", execute('burp', 'silent!')) |
| 37 | call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:') |
| 38 | |
| 39 | call assert_equal("", execute(test_null_string())) |
| 40 | endfunc |
| 41 | |
| 42 | func Test_execute_list() |
| 43 | call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"'])) |
| 44 | let l = ['for n in range(0, 3)', |
| 45 | \ 'echo n', |
| 46 | \ 'endfor'] |
| 47 | call assert_equal("\n0\n1\n2\n3", execute(l)) |
| 48 | |
| 49 | call assert_equal("", execute([])) |
| 50 | call assert_equal("", execute(test_null_list())) |
| 51 | endfunc |
Bram Moolenaar | 10ccaa1 | 2018-12-07 16:38:23 +0100 | [diff] [blame] | 52 | |
| 53 | func Test_execute_does_not_change_col() |
| 54 | echo '' |
| 55 | echon 'abcd' |
| 56 | let x = execute('silent echo 234343') |
| 57 | echon 'xyz' |
| 58 | let text = '' |
| 59 | for col in range(1, 7) |
| 60 | let text .= nr2char(screenchar(&lines, col)) |
| 61 | endfor |
| 62 | call assert_equal('abcdxyz', text) |
| 63 | endfunc |
Bram Moolenaar | 446e7a3 | 2018-12-08 13:57:42 +0100 | [diff] [blame] | 64 | |
| 65 | func Test_execute_not_silent() |
| 66 | echo '' |
| 67 | echon 'abcd' |
| 68 | let x = execute('echon 234', '') |
| 69 | echo 'xyz' |
| 70 | let text1 = '' |
| 71 | for col in range(1, 8) |
| 72 | let text1 .= nr2char(screenchar(&lines - 1, col)) |
| 73 | endfor |
| 74 | call assert_equal('abcd234 ', text1) |
| 75 | let text2 = '' |
| 76 | for col in range(1, 4) |
| 77 | let text2 .= nr2char(screenchar(&lines, col)) |
| 78 | endfor |
| 79 | call assert_equal('xyz ', text2) |
| 80 | endfunc |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 81 | |
| 82 | func Test_win_execute() |
| 83 | let thiswin = win_getid() |
| 84 | new |
| 85 | let otherwin = win_getid() |
| 86 | call setline(1, 'the new window') |
| 87 | call win_gotoid(thiswin) |
| 88 | let line = win_execute(otherwin, 'echo getline(1)') |
| 89 | call assert_match('the new window', line) |
| 90 | |
| 91 | if has('textprop') |
| 92 | let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) |
| 93 | redraw |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame^] | 94 | let line = 'echo getline(1)'->win_execute(popupwin) |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 95 | call assert_match('the popup win', line) |
| 96 | |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 97 | call popup_close(popupwin) |
| 98 | endif |
| 99 | |
| 100 | call win_gotoid(otherwin) |
| 101 | bwipe! |
| 102 | endfunc |
Bram Moolenaar | 820680b | 2019-08-09 14:56:22 +0200 | [diff] [blame] | 103 | |
| 104 | func Test_win_execute_other_tab() |
| 105 | let thiswin = win_getid() |
| 106 | tabnew |
| 107 | call win_execute(thiswin, 'let xyz = 1') |
| 108 | call assert_equal(1, xyz) |
| 109 | tabclose |
| 110 | unlet xyz |
| 111 | endfunc |