Bram Moolenaar | 94f82cb | 2019-07-24 22:30:27 +0200 | [diff] [blame] | 1 | " Tests for various Ex commands. |
| 2 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 3 | source check.vim |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 4 | source shared.vim |
| 5 | source term_util.vim |
Christian Brabandt | 9781788 | 2024-03-20 20:19:47 +0100 | [diff] [blame] | 6 | source screendump.vim |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 7 | |
Bram Moolenaar | 94f82cb | 2019-07-24 22:30:27 +0200 | [diff] [blame] | 8 | func Test_ex_delete() |
| 9 | new |
| 10 | call setline(1, ['a', 'b', 'c']) |
| 11 | 2 |
| 12 | " :dl is :delete with the "l" flag, not :dlist |
| 13 | .dl |
| 14 | call assert_equal(['a', 'c'], getline(1, 2)) |
| 15 | endfunc |
Bram Moolenaar | 0acae7a | 2019-08-06 21:29:29 +0200 | [diff] [blame] | 16 | |
| 17 | func Test_range_error() |
| 18 | call assert_fails(':.echo 1', 'E481:') |
| 19 | call assert_fails(':$echo 1', 'E481:') |
| 20 | call assert_fails(':1,2echo 1', 'E481:') |
| 21 | call assert_fails(':+1echo 1', 'E481:') |
| 22 | call assert_fails(':/1/echo 1', 'E481:') |
| 23 | call assert_fails(':\/echo 1', 'E481:') |
| 24 | normal vv |
| 25 | call assert_fails(":'<,'>echo 1", 'E481:') |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 26 | call assert_fails(":\\xcenter", 'E10:') |
Bram Moolenaar | 0acae7a | 2019-08-06 21:29:29 +0200 | [diff] [blame] | 27 | endfunc |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 28 | |
| 29 | func Test_buffers_lastused() |
| 30 | call test_settime(localtime() - 2000) " middle |
| 31 | edit bufa |
| 32 | enew |
| 33 | call test_settime(localtime() - 10) " newest |
| 34 | edit bufb |
| 35 | enew |
| 36 | call test_settime(1550010000) " oldest |
| 37 | edit bufc |
| 38 | enew |
| 39 | call test_settime(0) |
| 40 | enew |
| 41 | |
| 42 | let ls = split(execute('buffers t', 'silent!'), '\n') |
| 43 | let bufs = ls->map({i,v->split(v, '"\s*')[1:2]}) |
| 44 | call assert_equal(['bufb', 'bufa', 'bufc'], bufs[1:]->map({i,v->v[0]})) |
| 45 | call assert_match('1[0-3] seconds ago', bufs[1][1]) |
| 46 | call assert_match('\d\d:\d\d:\d\d', bufs[2][1]) |
| 47 | call assert_match('2019/02/1\d \d\d:\d\d:00', bufs[3][1]) |
| 48 | |
| 49 | bwipeout bufa |
| 50 | bwipeout bufb |
| 51 | bwipeout bufc |
| 52 | endfunc |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 53 | |
| 54 | " Test for the :copy command |
| 55 | func Test_copy() |
| 56 | new |
| 57 | |
| 58 | call setline(1, ['L1', 'L2', 'L3', 'L4']) |
| 59 | " copy lines in a range to inside the range |
| 60 | 1,3copy 2 |
| 61 | call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7)) |
| 62 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 63 | " Specifying a count before using : to run an ex-command |
| 64 | exe "normal! gg4:yank\<CR>" |
| 65 | call assert_equal("L1\nL2\nL1\nL2\n", @") |
| 66 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 67 | close! |
| 68 | endfunc |
| 69 | |
| 70 | " Test for the :file command |
| 71 | func Test_file_cmd() |
| 72 | call assert_fails('3file', 'E474:') |
| 73 | call assert_fails('0,0file', 'E474:') |
| 74 | call assert_fails('0file abc', 'E474:') |
Yegappan Lakshmanan | 59b2623 | 2021-06-05 20:59:22 +0200 | [diff] [blame] | 75 | if !has('win32') |
| 76 | " Change the name of the buffer to the same name |
| 77 | new Xfile1 |
| 78 | file Xfile1 |
| 79 | call assert_equal('Xfile1', @%) |
| 80 | call assert_equal('Xfile1', @#) |
| 81 | bw! |
| 82 | endif |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 83 | endfunc |
| 84 | |
| 85 | " Test for the :drop command |
| 86 | func Test_drop_cmd() |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 87 | call writefile(['L1', 'L2'], 'Xdropfile', 'D') |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 88 | " Test for reusing the current buffer |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 89 | enew | only |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 90 | let expected_nr = bufnr() |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 91 | drop Xdropfile |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 92 | call assert_equal(expected_nr, bufnr()) |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 93 | call assert_equal('L2', getline(2)) |
| 94 | " Test for switching to an existing window |
| 95 | below new |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 96 | drop Xdropfile |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 97 | call assert_equal(1, winnr()) |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 98 | " Test for splitting the current window (set nohidden) |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 99 | enew | only |
| 100 | set modified |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 101 | drop Xdropfile |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 102 | call assert_equal(2, winnr('$')) |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 103 | " Not splitting the current window even if modified (set hidden) |
| 104 | set hidden |
| 105 | enew | only |
| 106 | set modified |
| 107 | drop Xdropfile |
| 108 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 109 | " Check for setting the argument list |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 110 | call assert_equal(['Xdropfile'], argv()) |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 111 | enew | only! |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 112 | endfunc |
| 113 | |
| 114 | " Test for the :append command |
| 115 | func Test_append_cmd() |
| 116 | new |
| 117 | call setline(1, [' L1']) |
| 118 | call feedkeys(":append\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 119 | call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) |
| 120 | %delete _ |
| 121 | " append after a specific line |
| 122 | call setline(1, [' L1', ' L2', ' L3']) |
| 123 | call feedkeys(":2append\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 124 | call assert_equal([' L1', ' L2', ' L4', ' L5', ' L3'], getline(1, '$')) |
| 125 | %delete _ |
| 126 | " append with toggling 'autoindent' |
| 127 | call setline(1, [' L1']) |
| 128 | call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 129 | call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) |
| 130 | call assert_false(&autoindent) |
| 131 | %delete _ |
| 132 | " append with 'autoindent' set and toggling 'autoindent' |
| 133 | set autoindent |
| 134 | call setline(1, [' L1']) |
| 135 | call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 136 | call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) |
| 137 | call assert_true(&autoindent) |
| 138 | set autoindent& |
| 139 | close! |
| 140 | endfunc |
| 141 | |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 142 | func Test_append_cmd_empty_buf() |
| 143 | CheckRunVimInTerminal |
| 144 | let lines =<< trim END |
| 145 | func Timer(timer) |
| 146 | append |
| 147 | aaaaa |
| 148 | bbbbb |
| 149 | . |
| 150 | endfunc |
| 151 | call timer_start(10, 'Timer') |
| 152 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 153 | call writefile(lines, 'Xtest_append_cmd_empty_buf', 'D') |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 154 | let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6}) |
| 155 | call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) |
| 156 | call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) |
| 157 | |
| 158 | " clean up |
| 159 | call StopVimInTerminal(buf) |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 160 | endfunc |
| 161 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 162 | " Test for the :insert command |
| 163 | func Test_insert_cmd() |
| 164 | new |
| 165 | call setline(1, [' L1']) |
| 166 | call feedkeys(":insert\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 167 | call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) |
| 168 | %delete _ |
| 169 | " insert before a specific line |
| 170 | call setline(1, [' L1', ' L2', ' L3']) |
| 171 | call feedkeys(":2insert\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 172 | call assert_equal([' L1', ' L4', ' L5', ' L2', ' L3'], getline(1, '$')) |
| 173 | %delete _ |
| 174 | " insert with toggling 'autoindent' |
| 175 | call setline(1, [' L1']) |
| 176 | call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 177 | call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) |
| 178 | call assert_false(&autoindent) |
| 179 | %delete _ |
| 180 | " insert with 'autoindent' set and toggling 'autoindent' |
| 181 | set autoindent |
| 182 | call setline(1, [' L1']) |
| 183 | call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 184 | call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) |
| 185 | call assert_true(&autoindent) |
| 186 | set autoindent& |
| 187 | close! |
| 188 | endfunc |
| 189 | |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 190 | func Test_insert_cmd_empty_buf() |
| 191 | CheckRunVimInTerminal |
| 192 | let lines =<< trim END |
| 193 | func Timer(timer) |
| 194 | insert |
| 195 | aaaaa |
| 196 | bbbbb |
| 197 | . |
| 198 | endfunc |
| 199 | call timer_start(10, 'Timer') |
| 200 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 201 | call writefile(lines, 'Xtest_insert_cmd_empty_buf', 'D') |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 202 | let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6}) |
| 203 | call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) |
| 204 | call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) |
| 205 | |
| 206 | " clean up |
| 207 | call StopVimInTerminal(buf) |
zeertzjq | 1fa3de1 | 2021-12-31 12:19:22 +0000 | [diff] [blame] | 208 | endfunc |
| 209 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 210 | " Test for the :change command |
| 211 | func Test_change_cmd() |
| 212 | new |
| 213 | call setline(1, [' L1', 'L2', 'L3']) |
| 214 | call feedkeys(":change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 215 | call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) |
| 216 | %delete _ |
| 217 | " change a specific line |
| 218 | call setline(1, [' L1', ' L2', ' L3']) |
| 219 | call feedkeys(":2change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 220 | call assert_equal([' L1', ' L4', ' L5', ' L3'], getline(1, '$')) |
| 221 | %delete _ |
| 222 | " change with toggling 'autoindent' |
| 223 | call setline(1, [' L1', 'L2', 'L3']) |
| 224 | call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 225 | call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) |
| 226 | call assert_false(&autoindent) |
| 227 | %delete _ |
| 228 | " change with 'autoindent' set and toggling 'autoindent' |
| 229 | set autoindent |
| 230 | call setline(1, [' L1', 'L2', 'L3']) |
| 231 | call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 232 | call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) |
| 233 | call assert_true(&autoindent) |
| 234 | set autoindent& |
| 235 | close! |
| 236 | endfunc |
| 237 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 238 | " Test for the :language command |
| 239 | func Test_language_cmd() |
| 240 | CheckFeature multi_lang |
| 241 | |
| 242 | call assert_fails('language ctype non_existing_lang', 'E197:') |
| 243 | call assert_fails('language time non_existing_lang', 'E197:') |
| 244 | endfunc |
| 245 | |
| 246 | " Test for the :confirm command dialog |
| 247 | func Test_confirm_cmd() |
| 248 | CheckNotGui |
| 249 | CheckRunVimInTerminal |
| 250 | |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 251 | call writefile(['foo1'], 'Xfoo', 'D') |
| 252 | call writefile(['bar1'], 'Xbar', 'D') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 253 | |
| 254 | " Test for saving all the modified buffers |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 255 | let lines =<< trim END |
| 256 | set nomore |
| 257 | new Xfoo |
| 258 | call setline(1, 'foo2') |
| 259 | new Xbar |
| 260 | call setline(1, 'bar2') |
| 261 | wincmd b |
| 262 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 263 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 264 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 265 | call term_sendkeys(buf, ":confirm qall\n") |
| 266 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 267 | call term_sendkeys(buf, "A") |
| 268 | call StopVimInTerminal(buf) |
| 269 | |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 270 | call assert_equal(['foo2'], readfile('Xfoo')) |
| 271 | call assert_equal(['bar2'], readfile('Xbar')) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 272 | |
| 273 | " Test for discarding all the changes to modified buffers |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 274 | let lines =<< trim END |
| 275 | set nomore |
| 276 | new Xfoo |
| 277 | call setline(1, 'foo3') |
| 278 | new Xbar |
| 279 | call setline(1, 'bar3') |
| 280 | wincmd b |
| 281 | END |
| 282 | call writefile(lines, 'Xscript') |
| 283 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 284 | call term_sendkeys(buf, ":confirm qall\n") |
| 285 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 286 | call term_sendkeys(buf, "D") |
| 287 | call StopVimInTerminal(buf) |
| 288 | |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 289 | call assert_equal(['foo2'], readfile('Xfoo')) |
| 290 | call assert_equal(['bar2'], readfile('Xbar')) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 291 | |
| 292 | " Test for saving and discarding changes to some buffers |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 293 | let lines =<< trim END |
| 294 | set nomore |
| 295 | new Xfoo |
| 296 | call setline(1, 'foo4') |
| 297 | new Xbar |
| 298 | call setline(1, 'bar4') |
| 299 | wincmd b |
| 300 | END |
| 301 | call writefile(lines, 'Xscript') |
| 302 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 303 | call term_sendkeys(buf, ":confirm qall\n") |
| 304 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 305 | call term_sendkeys(buf, "N") |
| 306 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 307 | call term_sendkeys(buf, "Y") |
| 308 | call StopVimInTerminal(buf) |
| 309 | |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 310 | call assert_equal(['foo4'], readfile('Xfoo')) |
| 311 | call assert_equal(['bar2'], readfile('Xbar')) |
Bram Moolenaar | 72749f0 | 2020-03-26 20:51:43 +0100 | [diff] [blame] | 312 | endfunc |
| 313 | |
| 314 | func Test_confirm_cmd_cancel() |
Bram Moolenaar | bea9023 | 2020-03-26 22:09:52 +0100 | [diff] [blame] | 315 | CheckNotGui |
| 316 | CheckRunVimInTerminal |
| 317 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 318 | " Test for closing a window with a modified buffer |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 319 | let lines =<< trim END |
| 320 | set nomore |
| 321 | new |
| 322 | call setline(1, 'abc') |
| 323 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 324 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 325 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 326 | call term_sendkeys(buf, ":confirm close\n") |
| 327 | call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', |
| 328 | \ term_getline(buf, 20))}, 1000) |
| 329 | call term_sendkeys(buf, "C") |
Bram Moolenaar | 7b1b36b | 2020-03-28 21:48:55 +0100 | [diff] [blame] | 330 | call WaitForAssert({-> assert_equal('', term_getline(buf, 20))}, 1000) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 331 | call term_sendkeys(buf, ":confirm close\n") |
| 332 | call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', |
| 333 | \ term_getline(buf, 20))}, 1000) |
| 334 | call term_sendkeys(buf, "N") |
Bram Moolenaar | 9207d1f | 2020-03-27 19:41:02 +0100 | [diff] [blame] | 335 | call WaitForAssert({-> assert_match('^ *0,0-1 All$', |
| 336 | \ term_getline(buf, 20))}, 1000) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 337 | call StopVimInTerminal(buf) |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 338 | endfunc |
| 339 | |
| 340 | " The ":confirm" prompt was sometimes used with the terminal in cooked mode. |
| 341 | " This test verifies that a "\<CR>" character is NOT required to respond to a |
| 342 | " prompt from the ":conf q" and ":conf wq" commands. |
| 343 | func Test_confirm_q_wq() |
| 344 | CheckNotGui |
| 345 | CheckRunVimInTerminal |
| 346 | |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 347 | call writefile(['foo'], 'Xfoo', 'D') |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 348 | |
| 349 | let lines =<< trim END |
| 350 | set hidden nomore |
| 351 | call setline(1, 'abc') |
| 352 | edit Xfoo |
| 353 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 354 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 355 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
| 356 | call term_sendkeys(buf, ":confirm q\n") |
| 357 | call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', |
| 358 | \ term_getline(buf, 20))}, 1000) |
| 359 | call term_sendkeys(buf, 'C') |
| 360 | call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', |
| 361 | \ term_getline(buf, 20))}, 1000) |
| 362 | |
| 363 | call term_sendkeys(buf, ":edit Xfoo\n") |
| 364 | call term_sendkeys(buf, ":confirm wq\n") |
| 365 | call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', |
| 366 | \ term_getline(buf, 20))}, 1000) |
| 367 | call term_sendkeys(buf, 'C') |
| 368 | call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', |
| 369 | \ term_getline(buf, 20))}, 1000) |
Bram Moolenaar | 27321db | 2020-07-06 21:24:57 +0200 | [diff] [blame] | 370 | |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 371 | call StopVimInTerminal(buf) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 372 | endfunc |
| 373 | |
Dominique Pelle | 2bf6034 | 2021-05-02 20:16:24 +0200 | [diff] [blame] | 374 | func Test_confirm_write_ro() |
| 375 | CheckNotGui |
| 376 | CheckRunVimInTerminal |
| 377 | |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 378 | call writefile(['foo'], 'Xconfirm_write_ro', 'D') |
Dominique Pelle | 2bf6034 | 2021-05-02 20:16:24 +0200 | [diff] [blame] | 379 | let lines =<< trim END |
| 380 | set nobackup ff=unix cmdheight=2 |
| 381 | edit Xconfirm_write_ro |
| 382 | norm Abar |
| 383 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 384 | call writefile(lines, 'Xscript', 'D') |
Dominique Pelle | 2bf6034 | 2021-05-02 20:16:24 +0200 | [diff] [blame] | 385 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
| 386 | |
| 387 | " Try to write with 'ro' option. |
| 388 | call term_sendkeys(buf, ":set ro | confirm w\n") |
| 389 | call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", |
| 390 | \ term_getline(buf, 18))}, 1000) |
| 391 | call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$', |
| 392 | \ term_getline(buf, 19))}, 1000) |
| 393 | call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) |
| 394 | call term_sendkeys(buf, 'N') |
| 395 | call WaitForAssert({-> assert_match('^ *$', term_getline(buf, 19))}, 1000) |
| 396 | call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000) |
| 397 | call assert_equal(['foo'], readfile('Xconfirm_write_ro')) |
| 398 | |
| 399 | call term_sendkeys(buf, ":confirm w\n") |
| 400 | call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", |
| 401 | \ term_getline(buf, 18))}, 1000) |
| 402 | call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$', |
| 403 | \ term_getline(buf, 19))}, 1000) |
| 404 | call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) |
| 405 | call term_sendkeys(buf, 'Y') |
| 406 | call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 7B written$', |
| 407 | \ term_getline(buf, 19))}, 1000) |
| 408 | call assert_equal(['foobar'], readfile('Xconfirm_write_ro')) |
| 409 | |
| 410 | " Try to write with read-only file permissions. |
| 411 | call setfperm('Xconfirm_write_ro', 'r--r--r--') |
| 412 | call term_sendkeys(buf, ":set noro | undo | confirm w\n") |
| 413 | call WaitForAssert({-> assert_match("^File permissions of \"Xconfirm_write_ro\" are read-only\. *$", |
| 414 | \ term_getline(buf, 17))}, 1000) |
| 415 | call WaitForAssert({-> assert_match('^It may still be possible to write it\. *$', |
| 416 | \ term_getline(buf, 18))}, 1000) |
| 417 | call WaitForAssert({-> assert_match('^Do you wish to try? *$', term_getline(buf, 19))}, 1000) |
| 418 | call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) |
| 419 | call term_sendkeys(buf, 'Y') |
| 420 | call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 4B written$', |
| 421 | \ term_getline(buf, 19))}, 1000) |
| 422 | call assert_equal(['foo'], readfile('Xconfirm_write_ro')) |
| 423 | |
| 424 | call StopVimInTerminal(buf) |
Dominique Pelle | 2bf6034 | 2021-05-02 20:16:24 +0200 | [diff] [blame] | 425 | endfunc |
| 426 | |
Dominique Pelle | bd9e796 | 2021-08-09 21:04:44 +0200 | [diff] [blame] | 427 | func Test_confirm_write_partial_file() |
| 428 | CheckNotGui |
| 429 | CheckRunVimInTerminal |
| 430 | |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 431 | call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial', 'D') |
Dominique Pelle | bd9e796 | 2021-08-09 21:04:44 +0200 | [diff] [blame] | 432 | call writefile(['set nobackup ff=unix cmdheight=2', |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 433 | \ 'edit Xwrite_partial'], 'Xscript', 'D') |
Dominique Pelle | bd9e796 | 2021-08-09 21:04:44 +0200 | [diff] [blame] | 434 | let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) |
| 435 | |
| 436 | call term_sendkeys(buf, ":confirm 2,3w\n") |
| 437 | call WaitForAssert({-> assert_match('^Write partial file? *$', |
| 438 | \ term_getline(buf, 19))}, 1000) |
| 439 | call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', |
| 440 | \ term_getline(buf, 20))}, 1000) |
| 441 | call term_sendkeys(buf, 'N') |
| 442 | call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000) |
| 443 | call assert_equal(['a', 'b', 'c', 'd'], readfile('Xwrite_partial')) |
| 444 | call delete('Xwrite_partial') |
| 445 | |
| 446 | call term_sendkeys(buf, ":confirm 2,3w\n") |
| 447 | call WaitForAssert({-> assert_match('^Write partial file? *$', |
| 448 | \ term_getline(buf, 19))}, 1000) |
| 449 | call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', |
| 450 | \ term_getline(buf, 20))}, 1000) |
| 451 | call term_sendkeys(buf, 'Y') |
| 452 | call WaitForAssert({-> assert_match('^"Xwrite_partial" \[New\] 2L, 4B written *$', |
| 453 | \ term_getline(buf, 19))}, 1000) |
| 454 | call WaitForAssert({-> assert_match('^Press ENTER or type command to continue *$', |
| 455 | \ term_getline(buf, 20))}, 1000) |
| 456 | call assert_equal(['b', 'c'], readfile('Xwrite_partial')) |
| 457 | |
| 458 | call StopVimInTerminal(buf) |
Dominique Pelle | bd9e796 | 2021-08-09 21:04:44 +0200 | [diff] [blame] | 459 | endfunc |
| 460 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 461 | " Test for the :print command |
| 462 | func Test_print_cmd() |
| 463 | call assert_fails('print', 'E749:') |
| 464 | endfunc |
| 465 | |
| 466 | " Test for the :winsize command |
| 467 | func Test_winsize_cmd() |
| 468 | call assert_fails('winsize 1', 'E465:') |
Bram Moolenaar | f5a5116 | 2021-02-06 12:58:18 +0100 | [diff] [blame] | 469 | call assert_fails('winsize 1 x', 'E465:') |
| 470 | call assert_fails('win_getid(1)', 'E475: Invalid argument: _getid(1)') |
| 471 | " Actually changing the window size would be flaky. |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 472 | endfunc |
| 473 | |
| 474 | " Test for the :redir command |
Bram Moolenaar | f9a6550 | 2021-03-05 20:47:44 +0100 | [diff] [blame] | 475 | " NOTE: if you run tests as root this will fail. Don't run tests as root! |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 476 | func Test_redir_cmd() |
| 477 | call assert_fails('redir @@', 'E475:') |
| 478 | call assert_fails('redir abc', 'E475:') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 479 | call assert_fails('redir => 1abc', 'E474:') |
| 480 | call assert_fails('redir => a b', 'E488:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 481 | call assert_fails('redir => abc[1]', 'E121:') |
| 482 | let b = 0zFF |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 483 | call assert_fails('redir =>> b', 'E734:') |
| 484 | unlet b |
| 485 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 486 | if has('unix') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 487 | " Redirecting to a directory name |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 488 | call mkdir('Xredir') |
| 489 | call assert_fails('redir > Xredir', 'E17:') |
| 490 | call delete('Xredir', 'd') |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 491 | endif |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 492 | |
| 493 | " Test for redirecting to a register |
| 494 | redir @q> | echon 'clean ' | redir END |
| 495 | redir @q>> | echon 'water' | redir END |
| 496 | call assert_equal('clean water', @q) |
| 497 | |
| 498 | " Test for redirecting to a variable |
| 499 | redir => color | echon 'blue ' | redir END |
| 500 | redir =>> color | echon 'sky' | redir END |
| 501 | call assert_equal('blue sky', color) |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 502 | endfunc |
| 503 | |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 504 | func Test_redir_cmd_readonly() |
| 505 | CheckNotRoot |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 506 | |
| 507 | " Redirecting to a read-only file |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 508 | call writefile([], 'Xredirfile', 'D') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 509 | call setfperm('Xredirfile', 'r--r--r--') |
| 510 | call assert_fails('redir! > Xredirfile', 'E190:') |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 511 | endfunc |
| 512 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 513 | " Test for the :filetype command |
| 514 | func Test_filetype_cmd() |
| 515 | call assert_fails('filetype abc', 'E475:') |
| 516 | endfunc |
| 517 | |
| 518 | " Test for the :mode command |
| 519 | func Test_mode_cmd() |
| 520 | call assert_fails('mode abc', 'E359:') |
| 521 | endfunc |
| 522 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 523 | " Test for the :sleep command |
| 524 | func Test_sleep_cmd() |
| 525 | call assert_fails('sleep x', 'E475:') |
| 526 | endfunc |
| 527 | |
| 528 | " Test for the :read command |
| 529 | func Test_read_cmd() |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 530 | call writefile(['one'], 'Xcmdfile', 'D') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 531 | new |
| 532 | call assert_fails('read', 'E32:') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 533 | edit Xcmdfile |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 534 | read |
| 535 | call assert_equal(['one', 'one'], getline(1, '$')) |
| 536 | close! |
| 537 | new |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 538 | read Xcmdfile |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 539 | call assert_equal(['', 'one'], getline(1, '$')) |
| 540 | call deletebufline('', 1, '$') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 541 | call feedkeys("Qr Xcmdfile\<CR>visual\<CR>", 'xt') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 542 | call assert_equal(['one'], getline(1, '$')) |
| 543 | close! |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 544 | endfunc |
| 545 | |
| 546 | " Test for running Ex commands when text is locked. |
| 547 | " <C-\>e in the command line is used to lock the text |
| 548 | func Test_run_excmd_with_text_locked() |
| 549 | " :quit |
| 550 | let cmd = ":\<C-\>eexecute('quit')\<CR>\<C-C>" |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 551 | call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 552 | |
| 553 | " :qall |
| 554 | let cmd = ":\<C-\>eexecute('qall')\<CR>\<C-C>" |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 555 | call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 556 | |
| 557 | " :exit |
| 558 | let cmd = ":\<C-\>eexecute('exit')\<CR>\<C-C>" |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 559 | call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 560 | |
| 561 | " :close - should be ignored |
| 562 | new |
| 563 | let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>" |
| 564 | call assert_equal(2, winnr('$')) |
| 565 | close |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 566 | |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 567 | call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E565:') |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 568 | |
| 569 | " :tabfirst |
| 570 | tabnew |
| 571 | call assert_fails("call feedkeys(\":\<C-R>=execute('tabfirst')\<CR>\", 'xt')", 'E565:') |
| 572 | tabclose |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 573 | endfunc |
| 574 | |
| 575 | " Test for the :verbose command |
| 576 | func Test_verbose_cmd() |
Bram Moolenaar | 60895f3 | 2022-04-12 14:23:19 +0100 | [diff] [blame] | 577 | set verbose=3 |
| 578 | call assert_match(' verbose=1\n\s*Last set from ', execute('verbose set vbs'), "\n") |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 579 | call assert_equal([' verbose=0'], split(execute('0verbose set vbs'), "\n")) |
Bram Moolenaar | 60895f3 | 2022-04-12 14:23:19 +0100 | [diff] [blame] | 580 | set verbose=0 |
| 581 | call assert_match(' verbose=4\n\s*Last set from .*\n verbose=0', |
| 582 | \ execute("4verbose set verbose | set verbose")) |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 583 | endfunc |
| 584 | |
| 585 | " Test for the :delete command and the related abbreviated commands |
| 586 | func Test_excmd_delete() |
| 587 | new |
| 588 | call setline(1, ['foo', "\tbar"]) |
| 589 | call assert_equal(['^Ibar$'], split(execute('dl'), "\n")) |
| 590 | call setline(1, ['foo', "\tbar"]) |
| 591 | call assert_equal(['^Ibar$'], split(execute('dell'), "\n")) |
| 592 | call setline(1, ['foo', "\tbar"]) |
| 593 | call assert_equal(['^Ibar$'], split(execute('delel'), "\n")) |
| 594 | call setline(1, ['foo', "\tbar"]) |
| 595 | call assert_equal(['^Ibar$'], split(execute('deletl'), "\n")) |
| 596 | call setline(1, ['foo', "\tbar"]) |
| 597 | call assert_equal(['^Ibar$'], split(execute('deletel'), "\n")) |
| 598 | call setline(1, ['foo', "\tbar"]) |
| 599 | call assert_equal([' bar'], split(execute('dp'), "\n")) |
| 600 | call setline(1, ['foo', "\tbar"]) |
| 601 | call assert_equal([' bar'], split(execute('dep'), "\n")) |
| 602 | call setline(1, ['foo', "\tbar"]) |
| 603 | call assert_equal([' bar'], split(execute('delp'), "\n")) |
| 604 | call setline(1, ['foo', "\tbar"]) |
| 605 | call assert_equal([' bar'], split(execute('delep'), "\n")) |
| 606 | call setline(1, ['foo', "\tbar"]) |
| 607 | call assert_equal([' bar'], split(execute('deletp'), "\n")) |
| 608 | call setline(1, ['foo', "\tbar"]) |
| 609 | call assert_equal([' bar'], split(execute('deletep'), "\n")) |
| 610 | close! |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 611 | endfunc |
| 612 | |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 613 | " Test for commands that are blocked in a sandbox |
| 614 | func Sandbox_tests() |
| 615 | call assert_fails("call histadd(':', 'ls')", 'E48:') |
| 616 | call assert_fails("call mkdir('Xdir')", 'E48:') |
| 617 | call assert_fails("call rename('a', 'b')", 'E48:') |
| 618 | call assert_fails("call setbufvar(1, 'myvar', 1)", 'E48:') |
| 619 | call assert_fails("call settabvar(1, 'myvar', 1)", 'E48:') |
| 620 | call assert_fails("call settabwinvar(1, 1, 'myvar', 1)", 'E48:') |
| 621 | call assert_fails("call setwinvar(1, 'myvar', 1)", 'E48:') |
| 622 | call assert_fails("call timer_start(100, '')", 'E48:') |
| 623 | if has('channel') |
| 624 | call assert_fails("call prompt_setcallback(1, '')", 'E48:') |
| 625 | call assert_fails("call prompt_setinterrupt(1, '')", 'E48:') |
| 626 | call assert_fails("call prompt_setprompt(1, '')", 'E48:') |
| 627 | endif |
| 628 | call assert_fails("let $TESTVAR=1", 'E48:') |
| 629 | call assert_fails("call feedkeys('ivim')", 'E48:') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 630 | call assert_fails("source! Xsomefile", 'E48:') |
| 631 | call assert_fails("call delete('Xthatfile')", 'E48:') |
| 632 | call assert_fails("call writefile([], 'Xanotherfile')", 'E48:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 633 | call assert_fails('!ls', 'E48:') |
| 634 | call assert_fails('shell', 'E48:') |
| 635 | call assert_fails('stop', 'E48:') |
| 636 | call assert_fails('exe "normal \<C-Z>"', 'E48:') |
| 637 | set insertmode |
| 638 | call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E48:') |
| 639 | set insertmode& |
| 640 | call assert_fails('suspend', 'E48:') |
| 641 | call assert_fails('call system("ls")', 'E48:') |
| 642 | call assert_fails('call systemlist("ls")', 'E48:') |
| 643 | if has('clientserver') |
| 644 | call assert_fails('let s=remote_expr("gvim", "2+2")', 'E48:') |
| 645 | if !has('win32') |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 646 | " remote_foreground() doesn't throw an error message on MS-Windows |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 647 | call assert_fails('call remote_foreground("gvim")', 'E48:') |
| 648 | endif |
| 649 | call assert_fails('let s=remote_peek("gvim")', 'E48:') |
| 650 | call assert_fails('let s=remote_read("gvim")', 'E48:') |
| 651 | call assert_fails('let s=remote_send("gvim", "abc")', 'E48:') |
| 652 | call assert_fails('let s=server2client("gvim", "abc")', 'E48:') |
| 653 | endif |
| 654 | if has('terminal') |
| 655 | call assert_fails('terminal', 'E48:') |
| 656 | call assert_fails('call term_start("vim")', 'E48:') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 657 | call assert_fails('call term_dumpwrite(1, "Xdumpfile")', 'E48:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 658 | endif |
| 659 | if has('channel') |
| 660 | call assert_fails("call ch_logfile('chlog')", 'E48:') |
| 661 | call assert_fails("call ch_open('localhost:8765')", 'E48:') |
| 662 | endif |
| 663 | if has('job') |
| 664 | call assert_fails("call job_start('vim')", 'E48:') |
| 665 | endif |
| 666 | if has('unix') && has('libcall') |
| 667 | call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E48:') |
| 668 | endif |
| 669 | if has('unix') |
| 670 | call assert_fails('cd `pwd`', 'E48:') |
| 671 | endif |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 672 | " some options cannot be changed in a sandbox |
| 673 | call assert_fails('set exrc', 'E48:') |
| 674 | call assert_fails('set cdpath', 'E48:') |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 675 | if has('xim') && has('gui_gtk') |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 676 | call assert_fails('set imstyle', 'E48:') |
| 677 | endif |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 678 | endfunc |
| 679 | |
| 680 | func Test_sandbox() |
| 681 | sandbox call Sandbox_tests() |
| 682 | endfunc |
| 683 | |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 684 | func Test_command_not_implemented_E319() |
| 685 | if !has('mzscheme') |
| 686 | call assert_fails('mzscheme', 'E319:') |
| 687 | endif |
| 688 | endfunc |
| 689 | |
kuuote | 08d7b1c | 2021-10-04 22:17:36 +0100 | [diff] [blame] | 690 | func Test_not_break_expression_register() |
| 691 | call setreg('=', '1+1') |
| 692 | if 0 |
| 693 | put =1 |
| 694 | endif |
| 695 | call assert_equal('1+1', getreg('=', 1)) |
| 696 | endfunc |
| 697 | |
Bram Moolenaar | 03725c5 | 2021-11-24 12:17:53 +0000 | [diff] [blame] | 698 | func Test_address_line_overflow() |
| 699 | if v:sizeoflong < 8 |
| 700 | throw 'Skipped: only works with 64 bit long ints' |
| 701 | endif |
| 702 | new |
Bram Moolenaar | 3cf21b3 | 2022-01-11 19:34:16 +0000 | [diff] [blame] | 703 | call setline(1, range(100)) |
Bram Moolenaar | 03725c5 | 2021-11-24 12:17:53 +0000 | [diff] [blame] | 704 | call assert_fails('|.44444444444444444444444', 'E1247:') |
| 705 | call assert_fails('|.9223372036854775806', 'E1247:') |
Bram Moolenaar | 3cf21b3 | 2022-01-11 19:34:16 +0000 | [diff] [blame] | 706 | |
| 707 | $ |
| 708 | yank 77777777777777777777 |
| 709 | call assert_equal("99\n", @") |
| 710 | |
Bram Moolenaar | 03725c5 | 2021-11-24 12:17:53 +0000 | [diff] [blame] | 711 | bwipe! |
| 712 | endfunc |
| 713 | |
Bram Moolenaar | 4d97a56 | 2022-05-28 14:25:35 +0100 | [diff] [blame] | 714 | " This was leaving the cursor in line zero |
| 715 | func Test_using_zero_in_range() |
| 716 | new |
| 717 | norm o00 |
| 718 | silent! 0;s/\%') |
| 719 | bwipe! |
| 720 | endfunc |
| 721 | |
ii14 | 1f0dc5e | 2022-07-26 19:44:56 +0100 | [diff] [blame] | 722 | " Test :write after changing name with :file and loading it with :edit |
| 723 | func Test_write_after_rename() |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 724 | call writefile(['text'], 'Xafterfile', 'D') |
ii14 | 1f0dc5e | 2022-07-26 19:44:56 +0100 | [diff] [blame] | 725 | |
| 726 | enew |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 727 | file Xafterfile |
ii14 | 1f0dc5e | 2022-07-26 19:44:56 +0100 | [diff] [blame] | 728 | call assert_fails('write', 'E13: File exists (add ! to override)') |
| 729 | |
| 730 | " works OK after ":edit" |
| 731 | edit |
| 732 | write |
| 733 | |
ii14 | 1f0dc5e | 2022-07-26 19:44:56 +0100 | [diff] [blame] | 734 | bwipe! |
| 735 | endfunc |
| 736 | |
Christian Brabandt | 060623e | 2023-11-14 21:33:29 +0100 | [diff] [blame] | 737 | " catch address lines overflow |
| 738 | func Test_ex_address_range_overflow() |
| 739 | call assert_fails(':--+foobar', 'E492:') |
| 740 | endfunc |
Bram Moolenaar | 03725c5 | 2021-11-24 12:17:53 +0000 | [diff] [blame] | 741 | |
Christian Brabandt | 9781788 | 2024-03-20 20:19:47 +0100 | [diff] [blame] | 742 | func Test_drop_modified_file() |
| 743 | CheckScreendump |
| 744 | let lines =<< trim END |
| 745 | call setline(1, 'The quick brown fox jumped over the lazy dogs') |
| 746 | END |
| 747 | call writefile([''], 'Xdrop_modified.txt', 'D') |
| 748 | call writefile(lines, 'Xtest_drop_modified', 'D') |
| 749 | let buf = RunVimInTerminal('-S Xtest_drop_modified Xdrop_modified.txt', {'rows': 10,'columns': 40}) |
| 750 | call term_sendkeys(buf, ":drop Xdrop_modified.txt\<CR>") |
| 751 | call VerifyScreenDump(buf, 'Test_drop_modified_1', {}) |
| 752 | |
| 753 | " clean up |
| 754 | call StopVimInTerminal(buf) |
| 755 | endfunc |
| 756 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 757 | " vim: shiftwidth=2 sts=2 expandtab |