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 |
| 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:') |
| 23 | endfunc |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 24 | |
| 25 | func Test_buffers_lastused() |
| 26 | call test_settime(localtime() - 2000) " middle |
| 27 | edit bufa |
| 28 | enew |
| 29 | call test_settime(localtime() - 10) " newest |
| 30 | edit bufb |
| 31 | enew |
| 32 | call test_settime(1550010000) " oldest |
| 33 | edit bufc |
| 34 | enew |
| 35 | call test_settime(0) |
| 36 | enew |
| 37 | |
| 38 | let ls = split(execute('buffers t', 'silent!'), '\n') |
| 39 | let bufs = ls->map({i,v->split(v, '"\s*')[1:2]}) |
| 40 | call assert_equal(['bufb', 'bufa', 'bufc'], bufs[1:]->map({i,v->v[0]})) |
| 41 | call assert_match('1[0-3] seconds ago', bufs[1][1]) |
| 42 | call assert_match('\d\d:\d\d:\d\d', bufs[2][1]) |
| 43 | call assert_match('2019/02/1\d \d\d:\d\d:00', bufs[3][1]) |
| 44 | |
| 45 | bwipeout bufa |
| 46 | bwipeout bufb |
| 47 | bwipeout bufc |
| 48 | endfunc |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 49 | |
| 50 | " Test for the :copy command |
| 51 | func Test_copy() |
| 52 | new |
| 53 | |
| 54 | call setline(1, ['L1', 'L2', 'L3', 'L4']) |
| 55 | " copy lines in a range to inside the range |
| 56 | 1,3copy 2 |
| 57 | call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7)) |
| 58 | |
| 59 | close! |
| 60 | endfunc |
| 61 | |
| 62 | " Test for the :file command |
| 63 | func Test_file_cmd() |
| 64 | call assert_fails('3file', 'E474:') |
| 65 | call assert_fails('0,0file', 'E474:') |
| 66 | call assert_fails('0file abc', 'E474:') |
| 67 | endfunc |
| 68 | |
| 69 | " Test for the :drop command |
| 70 | func Test_drop_cmd() |
| 71 | call writefile(['L1', 'L2'], 'Xfile') |
| 72 | enew | only |
| 73 | drop Xfile |
| 74 | call assert_equal('L2', getline(2)) |
| 75 | " Test for switching to an existing window |
| 76 | below new |
| 77 | drop Xfile |
| 78 | call assert_equal(1, winnr()) |
| 79 | " Test for splitting the current window |
| 80 | enew | only |
| 81 | set modified |
| 82 | drop Xfile |
| 83 | call assert_equal(2, winnr('$')) |
| 84 | " Check for setting the argument list |
| 85 | call assert_equal(['Xfile'], argv()) |
| 86 | enew | only! |
| 87 | call delete('Xfile') |
| 88 | endfunc |
| 89 | |
| 90 | " Test for the :append command |
| 91 | func Test_append_cmd() |
| 92 | new |
| 93 | call setline(1, [' L1']) |
| 94 | call feedkeys(":append\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 95 | call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) |
| 96 | %delete _ |
| 97 | " append after a specific line |
| 98 | call setline(1, [' L1', ' L2', ' L3']) |
| 99 | call feedkeys(":2append\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 100 | call assert_equal([' L1', ' L2', ' L4', ' L5', ' L3'], getline(1, '$')) |
| 101 | %delete _ |
| 102 | " append with toggling 'autoindent' |
| 103 | call setline(1, [' L1']) |
| 104 | call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 105 | call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) |
| 106 | call assert_false(&autoindent) |
| 107 | %delete _ |
| 108 | " append with 'autoindent' set and toggling 'autoindent' |
| 109 | set autoindent |
| 110 | call setline(1, [' L1']) |
| 111 | call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 112 | call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) |
| 113 | call assert_true(&autoindent) |
| 114 | set autoindent& |
| 115 | close! |
| 116 | endfunc |
| 117 | |
| 118 | " Test for the :insert command |
| 119 | func Test_insert_cmd() |
| 120 | new |
| 121 | call setline(1, [' L1']) |
| 122 | call feedkeys(":insert\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 123 | call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) |
| 124 | %delete _ |
| 125 | " insert before a specific line |
| 126 | call setline(1, [' L1', ' L2', ' L3']) |
| 127 | call feedkeys(":2insert\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 128 | call assert_equal([' L1', ' L4', ' L5', ' L2', ' L3'], getline(1, '$')) |
| 129 | %delete _ |
| 130 | " insert with toggling 'autoindent' |
| 131 | call setline(1, [' L1']) |
| 132 | call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 133 | call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) |
| 134 | call assert_false(&autoindent) |
| 135 | %delete _ |
| 136 | " insert with 'autoindent' set and toggling 'autoindent' |
| 137 | set autoindent |
| 138 | call setline(1, [' L1']) |
| 139 | call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') |
| 140 | call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) |
| 141 | call assert_true(&autoindent) |
| 142 | set autoindent& |
| 143 | close! |
| 144 | endfunc |
| 145 | |
| 146 | " Test for the :change command |
| 147 | func Test_change_cmd() |
| 148 | new |
| 149 | call setline(1, [' L1', 'L2', 'L3']) |
| 150 | call feedkeys(":change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 151 | call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) |
| 152 | %delete _ |
| 153 | " change a specific line |
| 154 | call setline(1, [' L1', ' L2', ' L3']) |
| 155 | call feedkeys(":2change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 156 | call assert_equal([' L1', ' L4', ' L5', ' L3'], getline(1, '$')) |
| 157 | %delete _ |
| 158 | " change with toggling 'autoindent' |
| 159 | call setline(1, [' L1', 'L2', 'L3']) |
| 160 | call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 161 | call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) |
| 162 | call assert_false(&autoindent) |
| 163 | %delete _ |
| 164 | " change with 'autoindent' set and toggling 'autoindent' |
| 165 | set autoindent |
| 166 | call setline(1, [' L1', 'L2', 'L3']) |
| 167 | call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') |
| 168 | call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) |
| 169 | call assert_true(&autoindent) |
| 170 | set autoindent& |
| 171 | close! |
| 172 | endfunc |
| 173 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 174 | " Test for the :language command |
| 175 | func Test_language_cmd() |
| 176 | CheckFeature multi_lang |
| 177 | |
| 178 | call assert_fails('language ctype non_existing_lang', 'E197:') |
| 179 | call assert_fails('language time non_existing_lang', 'E197:') |
| 180 | endfunc |
| 181 | |
| 182 | " Test for the :confirm command dialog |
| 183 | func Test_confirm_cmd() |
| 184 | CheckNotGui |
| 185 | CheckRunVimInTerminal |
| 186 | |
| 187 | call writefile(['foo1'], 'foo') |
| 188 | call writefile(['bar1'], 'bar') |
| 189 | |
| 190 | " Test for saving all the modified buffers |
| 191 | let buf = RunVimInTerminal('', {'rows': 20}) |
| 192 | call term_sendkeys(buf, ":set nomore\n") |
| 193 | call term_sendkeys(buf, ":new foo\n") |
| 194 | call term_sendkeys(buf, ":call setline(1, 'foo2')\n") |
| 195 | call term_sendkeys(buf, ":new bar\n") |
| 196 | call term_sendkeys(buf, ":call setline(1, 'bar2')\n") |
| 197 | call term_sendkeys(buf, ":wincmd b\n") |
| 198 | call term_sendkeys(buf, ":confirm qall\n") |
| 199 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 200 | call term_sendkeys(buf, "A") |
| 201 | call StopVimInTerminal(buf) |
| 202 | |
| 203 | call assert_equal(['foo2'], readfile('foo')) |
| 204 | call assert_equal(['bar2'], readfile('bar')) |
| 205 | |
| 206 | " Test for discarding all the changes to modified buffers |
| 207 | let buf = RunVimInTerminal('', {'rows': 20}) |
| 208 | call term_sendkeys(buf, ":set nomore\n") |
| 209 | call term_sendkeys(buf, ":new foo\n") |
| 210 | call term_sendkeys(buf, ":call setline(1, 'foo3')\n") |
| 211 | call term_sendkeys(buf, ":new bar\n") |
| 212 | call term_sendkeys(buf, ":call setline(1, 'bar3')\n") |
| 213 | call term_sendkeys(buf, ":wincmd b\n") |
| 214 | call term_sendkeys(buf, ":confirm qall\n") |
| 215 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 216 | call term_sendkeys(buf, "D") |
| 217 | call StopVimInTerminal(buf) |
| 218 | |
| 219 | call assert_equal(['foo2'], readfile('foo')) |
| 220 | call assert_equal(['bar2'], readfile('bar')) |
| 221 | |
| 222 | " Test for saving and discarding changes to some buffers |
| 223 | let buf = RunVimInTerminal('', {'rows': 20}) |
| 224 | call term_sendkeys(buf, ":set nomore\n") |
| 225 | call term_sendkeys(buf, ":new foo\n") |
| 226 | call term_sendkeys(buf, ":call setline(1, 'foo4')\n") |
| 227 | call term_sendkeys(buf, ":new bar\n") |
| 228 | call term_sendkeys(buf, ":call setline(1, 'bar4')\n") |
| 229 | call term_sendkeys(buf, ":wincmd b\n") |
| 230 | call term_sendkeys(buf, ":confirm qall\n") |
| 231 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 232 | call term_sendkeys(buf, "N") |
| 233 | call WaitForAssert({-> assert_match('\[Y\]es, (N)o, (C)ancel: ', term_getline(buf, 20))}, 1000) |
| 234 | call term_sendkeys(buf, "Y") |
| 235 | call StopVimInTerminal(buf) |
| 236 | |
| 237 | call assert_equal(['foo4'], readfile('foo')) |
| 238 | call assert_equal(['bar2'], readfile('bar')) |
| 239 | |
| 240 | call delete('foo') |
| 241 | call delete('bar') |
| 242 | endfunc |
| 243 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 244 | " vim: shiftwidth=2 sts=2 expandtab |