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