Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 1 | " test execute() |
| 2 | |
Bram Moolenaar | 345f28d | 2019-10-08 22:20:35 +0200 | [diff] [blame] | 3 | source view_util.vim |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | 345f28d | 2019-10-08 22:20:35 +0200 | [diff] [blame] | 5 | |
Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 6 | func NestedEval() |
| 7 | let nested = execute('echo "nested\nlines"') |
| 8 | echo 'got: "' . nested . '"' |
| 9 | endfunc |
| 10 | |
| 11 | func NestedRedir() |
| 12 | redir => var |
| 13 | echo 'broken' |
| 14 | redir END |
| 15 | endfunc |
| 16 | |
| 17 | func Test_execute_string() |
| 18 | call assert_equal("\nnocompatible", execute('set compatible?')) |
| 19 | call assert_equal("\nsomething\nnice", execute('echo "something\nnice"')) |
| 20 | call assert_equal("noendofline", execute('echon "noendofline"')) |
| 21 | call assert_equal("", execute(123)) |
| 22 | |
| 23 | call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()')) |
| 24 | redir => redired |
| 25 | echo 'this' |
| 26 | let evaled = execute('echo "that"') |
| 27 | echo 'theend' |
| 28 | redir END |
| 29 | call assert_equal("\nthis\ntheend", redired) |
| 30 | call assert_equal("\nthat", evaled) |
| 31 | |
| 32 | call assert_fails('call execute("doesnotexist")', 'E492:') |
Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 33 | call assert_fails('call execute("call NestedRedir()")', 'E930:') |
| 34 | |
| 35 | call assert_equal("\nsomething", execute('echo "something"', '')) |
| 36 | call assert_equal("\nsomething", execute('echo "something"', 'silent')) |
| 37 | call assert_equal("\nsomething", execute('echo "something"', 'silent!')) |
| 38 | call assert_equal("", execute('burp', 'silent!')) |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 39 | if has('float') |
| 40 | call assert_fails('call execute(3.4)', 'E806:') |
| 41 | call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:') |
| 42 | endif |
Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 43 | endfunc |
| 44 | |
| 45 | func Test_execute_list() |
| 46 | call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"'])) |
| 47 | let l = ['for n in range(0, 3)', |
| 48 | \ 'echo n', |
| 49 | \ 'endfor'] |
| 50 | call assert_equal("\n0\n1\n2\n3", execute(l)) |
| 51 | |
| 52 | call assert_equal("", execute([])) |
Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 53 | endfunc |
Bram Moolenaar | 10ccaa1 | 2018-12-07 16:38:23 +0100 | [diff] [blame] | 54 | |
| 55 | func Test_execute_does_not_change_col() |
| 56 | echo '' |
| 57 | echon 'abcd' |
| 58 | let x = execute('silent echo 234343') |
| 59 | echon 'xyz' |
| 60 | let text = '' |
| 61 | for col in range(1, 7) |
| 62 | let text .= nr2char(screenchar(&lines, col)) |
| 63 | endfor |
| 64 | call assert_equal('abcdxyz', text) |
| 65 | endfunc |
Bram Moolenaar | 446e7a3 | 2018-12-08 13:57:42 +0100 | [diff] [blame] | 66 | |
| 67 | func Test_execute_not_silent() |
| 68 | echo '' |
| 69 | echon 'abcd' |
| 70 | let x = execute('echon 234', '') |
| 71 | echo 'xyz' |
| 72 | let text1 = '' |
| 73 | for col in range(1, 8) |
| 74 | let text1 .= nr2char(screenchar(&lines - 1, col)) |
| 75 | endfor |
| 76 | call assert_equal('abcd234 ', text1) |
| 77 | let text2 = '' |
| 78 | for col in range(1, 4) |
| 79 | let text2 .= nr2char(screenchar(&lines, col)) |
| 80 | endfor |
| 81 | call assert_equal('xyz ', text2) |
| 82 | endfunc |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 83 | |
| 84 | func Test_win_execute() |
| 85 | let thiswin = win_getid() |
| 86 | new |
| 87 | let otherwin = win_getid() |
| 88 | call setline(1, 'the new window') |
| 89 | call win_gotoid(thiswin) |
| 90 | let line = win_execute(otherwin, 'echo getline(1)') |
| 91 | call assert_match('the new window', line) |
Bram Moolenaar | 37487e1 | 2021-01-12 22:08:53 +0100 | [diff] [blame] | 92 | let line = win_execute(134343, 'echo getline(1)') |
| 93 | call assert_equal('', line) |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 94 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 95 | if has('popupwin') |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 96 | let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) |
| 97 | redraw |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 98 | let line = 'echo getline(1)'->win_execute(popupwin) |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 99 | call assert_match('the popup win', line) |
| 100 | |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 101 | call popup_close(popupwin) |
| 102 | endif |
| 103 | |
| 104 | call win_gotoid(otherwin) |
| 105 | bwipe! |
| 106 | endfunc |
Bram Moolenaar | 820680b | 2019-08-09 14:56:22 +0200 | [diff] [blame] | 107 | |
Bram Moolenaar | 345f28d | 2019-10-08 22:20:35 +0200 | [diff] [blame] | 108 | func Test_win_execute_update_ruler() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 109 | CheckFeature quickfix |
| 110 | |
Bram Moolenaar | 345f28d | 2019-10-08 22:20:35 +0200 | [diff] [blame] | 111 | enew |
| 112 | call setline(1, range(500)) |
| 113 | 20 |
| 114 | split |
| 115 | let winid = win_getid() |
| 116 | set ruler |
| 117 | wincmd w |
| 118 | let height = winheight(winid) |
| 119 | redraw |
| 120 | call assert_match('20,1', Screenline(height + 1)) |
| 121 | let line = win_execute(winid, 'call cursor(100, 1)') |
| 122 | redraw |
| 123 | call assert_match('100,1', Screenline(height + 1)) |
| 124 | |
| 125 | bwipe! |
| 126 | endfunc |
| 127 | |
Bram Moolenaar | 820680b | 2019-08-09 14:56:22 +0200 | [diff] [blame] | 128 | func Test_win_execute_other_tab() |
| 129 | let thiswin = win_getid() |
| 130 | tabnew |
| 131 | call win_execute(thiswin, 'let xyz = 1') |
| 132 | call assert_equal(1, xyz) |
| 133 | tabclose |
| 134 | unlet xyz |
| 135 | endfunc |
Bram Moolenaar | e2a8f07 | 2020-01-08 19:32:18 +0100 | [diff] [blame] | 136 | |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 137 | func Test_execute_func_with_null() |
Bram Moolenaar | e2a8f07 | 2020-01-08 19:32:18 +0100 | [diff] [blame] | 138 | call assert_equal("", execute(test_null_string())) |
| 139 | call assert_equal("", execute(test_null_list())) |
| 140 | call assert_fails('call execute(test_null_dict())', 'E731:') |
| 141 | call assert_fails('call execute(test_null_blob())', 'E976:') |
| 142 | call assert_fails('call execute(test_null_partial())','E729:') |
| 143 | if has('job') |
| 144 | call assert_fails('call execute(test_null_job())', 'E908:') |
| 145 | call assert_fails('call execute(test_null_channel())', 'E908:') |
| 146 | endif |
| 147 | endfunc |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 148 | |
| 149 | " vim: shiftwidth=2 sts=2 expandtab |