blob: 7934e60846639a579a788eb2f7b00cb4d2403f85 [file] [log] [blame]
Bram Moolenaar79815f12016-07-09 17:07:29 +02001" test execute()
2
Bram Moolenaar345f28d2019-10-08 22:20:35 +02003source view_util.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01004source check.vim
Bram Moolenaar345f28d2019-10-08 22:20:35 +02005
Bram Moolenaar79815f12016-07-09 17:07:29 +02006func NestedEval()
7 let nested = execute('echo "nested\nlines"')
8 echo 'got: "' . nested . '"'
9endfunc
10
11func NestedRedir()
12 redir => var
13 echo 'broken'
14 redir END
15endfunc
16
17func 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:')
33 call assert_fails('call execute(3.4)', 'E806:')
34 call assert_fails('call execute("call NestedRedir()")', 'E930:')
35
36 call assert_equal("\nsomething", execute('echo "something"', ''))
37 call assert_equal("\nsomething", execute('echo "something"', 'silent'))
38 call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
39 call assert_equal("", execute('burp', 'silent!'))
40 call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
41
42 call assert_equal("", execute(test_null_string()))
43endfunc
44
45func 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([]))
53 call assert_equal("", execute(test_null_list()))
54endfunc
Bram Moolenaar10ccaa12018-12-07 16:38:23 +010055
56func Test_execute_does_not_change_col()
57 echo ''
58 echon 'abcd'
59 let x = execute('silent echo 234343')
60 echon 'xyz'
61 let text = ''
62 for col in range(1, 7)
63 let text .= nr2char(screenchar(&lines, col))
64 endfor
65 call assert_equal('abcdxyz', text)
66endfunc
Bram Moolenaar446e7a32018-12-08 13:57:42 +010067
68func Test_execute_not_silent()
69 echo ''
70 echon 'abcd'
71 let x = execute('echon 234', '')
72 echo 'xyz'
73 let text1 = ''
74 for col in range(1, 8)
75 let text1 .= nr2char(screenchar(&lines - 1, col))
76 endfor
77 call assert_equal('abcd234 ', text1)
78 let text2 = ''
79 for col in range(1, 4)
80 let text2 .= nr2char(screenchar(&lines, col))
81 endfor
82 call assert_equal('xyz ', text2)
83endfunc
Bram Moolenaar868b7b62019-05-29 21:44:40 +020084
85func Test_win_execute()
86 let thiswin = win_getid()
87 new
88 let otherwin = win_getid()
89 call setline(1, 'the new window')
90 call win_gotoid(thiswin)
91 let line = win_execute(otherwin, 'echo getline(1)')
92 call assert_match('the new window', line)
93
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +010094 if has('popupwin')
Bram Moolenaar868b7b62019-05-29 21:44:40 +020095 let popupwin = popup_create('the popup win', {'line': 2, 'col': 3})
96 redraw
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020097 let line = 'echo getline(1)'->win_execute(popupwin)
Bram Moolenaar868b7b62019-05-29 21:44:40 +020098 call assert_match('the popup win', line)
99
Bram Moolenaar868b7b62019-05-29 21:44:40 +0200100 call popup_close(popupwin)
101 endif
102
103 call win_gotoid(otherwin)
104 bwipe!
105endfunc
Bram Moolenaar820680b2019-08-09 14:56:22 +0200106
Bram Moolenaar345f28d2019-10-08 22:20:35 +0200107func Test_win_execute_update_ruler()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100108 CheckFeature quickfix
109
Bram Moolenaar345f28d2019-10-08 22:20:35 +0200110 enew
111 call setline(1, range(500))
112 20
113 split
114 let winid = win_getid()
115 set ruler
116 wincmd w
117 let height = winheight(winid)
118 redraw
119 call assert_match('20,1', Screenline(height + 1))
120 let line = win_execute(winid, 'call cursor(100, 1)')
121 redraw
122 call assert_match('100,1', Screenline(height + 1))
123
124 bwipe!
125endfunc
126
Bram Moolenaar820680b2019-08-09 14:56:22 +0200127func Test_win_execute_other_tab()
128 let thiswin = win_getid()
129 tabnew
130 call win_execute(thiswin, 'let xyz = 1')
131 call assert_equal(1, xyz)
132 tabclose
133 unlet xyz
134endfunc