Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1 | " Tests for Vim buffer |
| 2 | |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 5 | " Test for the :bunload command with an offset |
| 6 | func Test_bunload_with_offset() |
| 7 | %bwipe! |
| 8 | call writefile(['B1'], 'b1') |
| 9 | call writefile(['B2'], 'b2') |
| 10 | call writefile(['B3'], 'b3') |
| 11 | call writefile(['B4'], 'b4') |
| 12 | |
| 13 | " Load four buffers. Unload the second and third buffers and then |
| 14 | " execute .+3bunload to unload the last buffer. |
| 15 | edit b1 |
| 16 | new b2 |
| 17 | new b3 |
| 18 | new b4 |
| 19 | |
| 20 | bunload b2 |
| 21 | bunload b3 |
| 22 | exe bufwinnr('b1') . 'wincmd w' |
| 23 | .+3bunload |
| 24 | call assert_equal(0, getbufinfo('b4')[0].loaded) |
| 25 | call assert_equal('b1', |
| 26 | \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) |
| 27 | |
| 28 | " Load four buffers. Unload the third and fourth buffers. Execute .+3bunload |
| 29 | " and check whether the second buffer is unloaded. |
| 30 | ball |
| 31 | bunload b3 |
| 32 | bunload b4 |
| 33 | exe bufwinnr('b1') . 'wincmd w' |
| 34 | .+3bunload |
| 35 | call assert_equal(0, getbufinfo('b2')[0].loaded) |
| 36 | call assert_equal('b1', |
| 37 | \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) |
| 38 | |
| 39 | " Load four buffers. Unload the second and third buffers and from the last |
| 40 | " buffer execute .-3bunload to unload the first buffer. |
| 41 | ball |
| 42 | bunload b2 |
| 43 | bunload b3 |
| 44 | exe bufwinnr('b4') . 'wincmd w' |
| 45 | .-3bunload |
| 46 | call assert_equal(0, getbufinfo('b1')[0].loaded) |
| 47 | call assert_equal('b4', |
| 48 | \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) |
| 49 | |
| 50 | " Load four buffers. Unload the first and second buffers. Execute .-3bunload |
| 51 | " from the last buffer and check whether the third buffer is unloaded. |
| 52 | ball |
| 53 | bunload b1 |
| 54 | bunload b2 |
| 55 | exe bufwinnr('b4') . 'wincmd w' |
| 56 | .-3bunload |
| 57 | call assert_equal(0, getbufinfo('b3')[0].loaded) |
| 58 | call assert_equal('b4', |
| 59 | \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) |
| 60 | |
| 61 | %bwipe! |
| 62 | call delete('b1') |
| 63 | call delete('b2') |
| 64 | call delete('b3') |
| 65 | call delete('b4') |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 66 | |
| 67 | call assert_fails('1,4bunload', 'E16:') |
| 68 | call assert_fails(',100bunload', 'E16:') |
| 69 | |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 70 | call assert_fails('$bunload', 'E90:') |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 71 | endfunc |
| 72 | |
| 73 | " Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified |
| 74 | " commands |
| 75 | func Test_buflist_browse() |
| 76 | %bwipe! |
| 77 | call assert_fails('buffer 1000', 'E86:') |
| 78 | |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 79 | call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1') |
| 80 | call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2') |
| 81 | call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3') |
| 82 | edit Xbrowse1 |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 83 | let b1 = bufnr() |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 84 | edit Xbrowse2 |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 85 | let b2 = bufnr() |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 86 | edit +/baz4 Xbrowse3 |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 87 | let b3 = bufnr() |
| 88 | |
| 89 | call assert_fails('buffer ' .. b1 .. ' abc', 'E488:') |
| 90 | call assert_equal(b3, bufnr()) |
| 91 | call assert_equal(4, line('.')) |
| 92 | exe 'buffer +/bar2 ' .. b2 |
| 93 | call assert_equal(b2, bufnr()) |
| 94 | call assert_equal(2, line('.')) |
| 95 | exe 'buffer +/bar1' |
| 96 | call assert_equal(b2, bufnr()) |
| 97 | call assert_equal(1, line('.')) |
| 98 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 99 | brewind + |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 100 | call assert_equal(b1, bufnr()) |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 101 | call assert_equal(4, line('.')) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 102 | |
| 103 | blast +/baz2 |
| 104 | call assert_equal(b3, bufnr()) |
| 105 | call assert_equal(2, line('.')) |
| 106 | |
| 107 | bprevious +/bar4 |
| 108 | call assert_equal(b2, bufnr()) |
| 109 | call assert_equal(4, line('.')) |
| 110 | |
| 111 | bnext +/baz3 |
| 112 | call assert_equal(b3, bufnr()) |
| 113 | call assert_equal(3, line('.')) |
| 114 | |
| 115 | call assert_fails('bmodified', 'E84:') |
| 116 | call setbufvar(b2, '&modified', 1) |
| 117 | exe 'bmodified +/bar3' |
| 118 | call assert_equal(b2, bufnr()) |
| 119 | call assert_equal(3, line('.')) |
| 120 | |
| 121 | " With no listed buffers in the list, :bnext and :bprev should fail |
| 122 | %bwipe! |
| 123 | set nobuflisted |
| 124 | call assert_fails('bnext', 'E85:') |
| 125 | call assert_fails('bprev', 'E85:') |
| 126 | set buflisted |
| 127 | |
| 128 | call assert_fails('sandbox bnext', 'E48:') |
| 129 | |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 130 | call delete('Xbrowse1') |
| 131 | call delete('Xbrowse2') |
| 132 | call delete('Xbrowse3') |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 133 | %bwipe! |
| 134 | endfunc |
| 135 | |
| 136 | " Test for :bdelete |
| 137 | func Test_bdelete_cmd() |
| 138 | %bwipe! |
| 139 | call assert_fails('bdelete 5', 'E516:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 140 | call assert_fails('1,1bdelete 1 2', 'E488:') |
Bram Moolenaar | 531be47 | 2020-09-23 22:38:05 +0200 | [diff] [blame] | 141 | call assert_fails('bdelete \)', 'E55:') |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 142 | |
| 143 | " Deleting a unlisted and unloaded buffer |
| 144 | edit Xfile1 |
| 145 | let bnr = bufnr() |
| 146 | set nobuflisted |
| 147 | enew |
| 148 | call assert_fails('bdelete ' .. bnr, 'E516:') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 149 | |
| 150 | " Deleting more than one buffer |
| 151 | new Xbuf1 |
| 152 | new Xbuf2 |
| 153 | exe 'bdel ' .. bufnr('Xbuf2') .. ' ' .. bufnr('Xbuf1') |
| 154 | call assert_equal(1, winnr('$')) |
| 155 | call assert_equal(0, getbufinfo('Xbuf1')[0].loaded) |
| 156 | call assert_equal(0, getbufinfo('Xbuf2')[0].loaded) |
| 157 | |
| 158 | " Deleting more than one buffer and an invalid buffer |
| 159 | new Xbuf1 |
| 160 | new Xbuf2 |
| 161 | let cmd = "exe 'bdel ' .. bufnr('Xbuf2') .. ' xxx ' .. bufnr('Xbuf1')" |
| 162 | call assert_fails(cmd, 'E94:') |
| 163 | call assert_equal(2, winnr('$')) |
| 164 | call assert_equal(1, getbufinfo('Xbuf1')[0].loaded) |
| 165 | call assert_equal(0, getbufinfo('Xbuf2')[0].loaded) |
| 166 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 167 | %bwipe! |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 168 | endfunc |
| 169 | |
Bram Moolenaar | 067297e | 2020-04-13 19:55:50 +0200 | [diff] [blame] | 170 | func Test_buffer_error() |
| 171 | new foo1 |
| 172 | new foo2 |
| 173 | |
| 174 | call assert_fails('buffer foo', 'E93:') |
| 175 | call assert_fails('buffer bar', 'E94:') |
| 176 | call assert_fails('buffer 0', 'E939:') |
| 177 | |
| 178 | %bwipe |
| 179 | endfunc |
| 180 | |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 181 | " Test for the status messages displayed when unloading, deleting or wiping |
| 182 | " out buffers |
| 183 | func Test_buffer_statusmsg() |
| 184 | CheckEnglish |
| 185 | set report=1 |
| 186 | new Xbuf1 |
| 187 | new Xbuf2 |
| 188 | let bnr = bufnr() |
| 189 | exe "normal 2\<C-G>" |
| 190 | call assert_match('buf ' .. bnr .. ':', v:statusmsg) |
| 191 | bunload Xbuf1 Xbuf2 |
| 192 | call assert_equal('2 buffers unloaded', v:statusmsg) |
| 193 | bdel Xbuf1 Xbuf2 |
| 194 | call assert_equal('2 buffers deleted', v:statusmsg) |
| 195 | bwipe Xbuf1 Xbuf2 |
| 196 | call assert_equal('2 buffers wiped out', v:statusmsg) |
| 197 | set report& |
| 198 | endfunc |
| 199 | |
| 200 | " Test for quitting the 'swapfile exists' dialog with the split buffer |
| 201 | " command. |
| 202 | func Test_buffer_sbuf_cleanup() |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 203 | call writefile([], 'XsplitCleanup') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 204 | " first open the file in a buffer |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 205 | new XsplitCleanup |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 206 | let bnr = bufnr() |
| 207 | close |
| 208 | " create the swap file |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 209 | call writefile([], '.XsplitCleanup.swp') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 210 | " Remove the catch-all that runtest.vim adds |
| 211 | au! SwapExists |
| 212 | augroup BufTest |
| 213 | au! |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 214 | autocmd SwapExists XsplitCleanup let v:swapchoice='q' |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 215 | augroup END |
| 216 | exe 'sbuf ' . bnr |
| 217 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 218 | call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 219 | |
| 220 | " test for :sball |
| 221 | sball |
| 222 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 223 | call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 224 | |
| 225 | %bw! |
| 226 | set shortmess+=F |
| 227 | let v:statusmsg = '' |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 228 | edit XsplitCleanup |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 229 | call assert_equal('', v:statusmsg) |
| 230 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 231 | call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 232 | set shortmess& |
| 233 | |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 234 | call delete('XsplitCleanup') |
| 235 | call delete('.XsplitCleanup.swp') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 236 | augroup BufTest |
| 237 | au! |
| 238 | augroup END |
| 239 | augroup! BufTest |
| 240 | endfunc |
| 241 | |
| 242 | " Test for deleting a modified buffer with :confirm |
| 243 | func Test_bdel_with_confirm() |
| 244 | CheckUnix |
| 245 | CheckNotGui |
| 246 | CheckFeature dialog_con |
| 247 | new |
| 248 | call setline(1, 'test') |
| 249 | call assert_fails('bdel', 'E89:') |
| 250 | call feedkeys('c', 'L') |
| 251 | confirm bdel |
| 252 | call assert_equal(2, winnr('$')) |
| 253 | call assert_equal(1, &modified) |
| 254 | call feedkeys('n', 'L') |
| 255 | confirm bdel |
| 256 | call assert_equal(1, winnr('$')) |
| 257 | endfunc |
| 258 | |
| 259 | " Test for editing another buffer from a modified buffer with :confirm |
| 260 | func Test_goto_buf_with_confirm() |
| 261 | CheckUnix |
| 262 | CheckNotGui |
| 263 | CheckFeature dialog_con |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 264 | new XgotoConf |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 265 | enew |
| 266 | call setline(1, 'test') |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 267 | call assert_fails('b XgotoConf', 'E37:') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 268 | call feedkeys('c', 'L') |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 269 | call assert_fails('confirm b XgotoConf', 'E37:') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 270 | call assert_equal(1, &modified) |
| 271 | call assert_equal('', @%) |
| 272 | call feedkeys('y', 'L') |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 273 | call assert_fails('confirm b XgotoConf', ['', 'E37:']) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 274 | call assert_equal(1, &modified) |
| 275 | call assert_equal('', @%) |
| 276 | call feedkeys('n', 'L') |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 277 | confirm b XgotoConf |
| 278 | call assert_equal('XgotoConf', @%) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 279 | close! |
| 280 | endfunc |
| 281 | |
| 282 | " Test for splitting buffer with 'switchbuf' |
| 283 | func Test_buffer_switchbuf() |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 284 | new Xswitchbuf |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 285 | wincmd w |
| 286 | set switchbuf=useopen |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 287 | sbuf Xswitchbuf |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 288 | call assert_equal(1, winnr()) |
| 289 | call assert_equal(2, winnr('$')) |
| 290 | set switchbuf=usetab |
| 291 | tabnew |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 292 | sbuf Xswitchbuf |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 293 | call assert_equal(1, tabpagenr()) |
| 294 | call assert_equal(2, tabpagenr('$')) |
| 295 | set switchbuf& |
| 296 | %bw |
| 297 | endfunc |
| 298 | |
| 299 | " Test for BufAdd autocommand wiping out the buffer |
| 300 | func Test_bufadd_autocmd_bwipe() |
| 301 | %bw! |
| 302 | augroup BufAdd_Wipe |
| 303 | au! |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 304 | autocmd BufAdd Xbwipe %bw! |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 305 | augroup END |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 306 | edit Xbwipe |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 307 | call assert_equal('', @%) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 308 | call assert_equal(0, bufexists('Xbwipe')) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 309 | augroup BufAdd_Wipe |
| 310 | au! |
| 311 | augroup END |
| 312 | augroup! BufAdd_Wipe |
| 313 | endfunc |
| 314 | |
| 315 | " Test for trying to load a buffer with text locked |
| 316 | " <C-\>e in the command line is used to lock the text |
| 317 | func Test_load_buf_with_text_locked() |
| 318 | new Xfile1 |
| 319 | edit Xfile2 |
| 320 | let cmd = ":\<C-\>eexecute(\"normal \<C-O>\")\<CR>\<C-C>" |
| 321 | call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') |
| 322 | %bw! |
| 323 | endfunc |
| 324 | |
| 325 | " Test for using CTRL-^ to edit the alternative file keeping the cursor |
| 326 | " position with 'nostartofline'. Also test using the 'buf' command. |
| 327 | func Test_buffer_edit_altfile() |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 328 | call writefile(repeat(['one two'], 50), 'Xaltfile1') |
| 329 | call writefile(repeat(['five six'], 50), 'Xaltfile2') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 330 | set nosol |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 331 | edit Xaltfile1 |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 332 | call cursor(25, 5) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 333 | edit Xaltfile2 |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 334 | call cursor(30, 4) |
| 335 | exe "normal \<C-^>" |
| 336 | call assert_equal([0, 25, 5, 0], getpos('.')) |
| 337 | exe "normal \<C-^>" |
| 338 | call assert_equal([0, 30, 4, 0], getpos('.')) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 339 | buf Xaltfile1 |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 340 | call assert_equal([0, 25, 5, 0], getpos('.')) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 341 | buf Xaltfile2 |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 342 | call assert_equal([0, 30, 4, 0], getpos('.')) |
| 343 | set sol& |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 344 | call delete('Xaltfile1') |
| 345 | call delete('Xaltfile2') |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 346 | endfunc |
| 347 | |
| 348 | " Test for running the :sball command with a maximum window count and a |
| 349 | " modified buffer |
| 350 | func Test_sball_with_count() |
| 351 | %bw! |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 352 | edit Xcountfile1 |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 353 | call setline(1, ['abc']) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 354 | new Xcountfile2 |
| 355 | new Xcountfile3 |
| 356 | new Xcountfile4 |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 357 | 2sball |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 358 | call assert_equal(bufnr('Xcountfile4'), winbufnr(1)) |
| 359 | call assert_equal(bufnr('Xcountfile1'), winbufnr(2)) |
| 360 | call assert_equal(0, getbufinfo('Xcountfile2')[0].loaded) |
| 361 | call assert_equal(0, getbufinfo('Xcountfile3')[0].loaded) |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 362 | %bw! |
| 363 | endfunc |
| 364 | |
Bram Moolenaar | e974fa7 | 2020-10-25 15:02:51 +0100 | [diff] [blame] | 365 | func Test_badd_options() |
| 366 | new SomeNewBuffer |
Bram Moolenaar | 37e4e03 | 2020-10-25 16:18:26 +0100 | [diff] [blame] | 367 | setlocal numberwidth=3 |
Bram Moolenaar | e974fa7 | 2020-10-25 15:02:51 +0100 | [diff] [blame] | 368 | wincmd p |
Bram Moolenaar | 89b693e | 2020-10-25 17:09:50 +0100 | [diff] [blame] | 369 | badd +1 SomeNewBuffer |
Bram Moolenaar | e974fa7 | 2020-10-25 15:02:51 +0100 | [diff] [blame] | 370 | new SomeNewBuffer |
Bram Moolenaar | 37e4e03 | 2020-10-25 16:18:26 +0100 | [diff] [blame] | 371 | call assert_equal(3, &numberwidth) |
Bram Moolenaar | e974fa7 | 2020-10-25 15:02:51 +0100 | [diff] [blame] | 372 | close |
| 373 | close |
| 374 | bwipe! SomeNewBuffer |
| 375 | endfunc |
| 376 | |
Bram Moolenaar | 59d8e56 | 2020-11-07 18:41:10 +0100 | [diff] [blame] | 377 | func Test_balt() |
| 378 | new SomeNewBuffer |
| 379 | balt +3 OtherBuffer |
| 380 | e # |
| 381 | call assert_equal('OtherBuffer', bufname()) |
| 382 | endfunc |
| 383 | |
Tsuyoshi CHO | 7b7a118 | 2021-07-11 21:51:17 +0200 | [diff] [blame] | 384 | " Test for buffer match URL(scheme) check |
| 385 | " scheme is alpha and inner hyphen only. |
| 386 | func Test_buffer_scheme() |
| 387 | CheckMSWindows |
| 388 | |
| 389 | set noshellslash |
| 390 | %bwipe! |
| 391 | let bufnames = [ |
Bram Moolenaar | f8bc0ce | 2021-12-02 12:30:22 +0000 | [diff] [blame] | 392 | \ #{id: 'ssb0', name: 'test://xyz/foo/ssb0' , match: 1}, |
| 393 | \ #{id: 'ssb1', name: 'test+abc://xyz/foo/ssb1', match: 0}, |
| 394 | \ #{id: 'ssb2', name: 'test_abc://xyz/foo/ssb2', match: 0}, |
| 395 | \ #{id: 'ssb3', name: 'test-abc://xyz/foo/ssb3', match: 1}, |
| 396 | \ #{id: 'ssb4', name: '-test://xyz/foo/ssb4' , match: 0}, |
| 397 | \ #{id: 'ssb5', name: 'test-://xyz/foo/ssb5' , match: 0}, |
Tsuyoshi CHO | 7b7a118 | 2021-07-11 21:51:17 +0200 | [diff] [blame] | 398 | \] |
| 399 | for buf in bufnames |
| 400 | new `=buf.name` |
| 401 | if buf.match |
| 402 | call assert_equal(buf.name, getbufinfo(buf.id)[0].name) |
| 403 | else |
| 404 | " slashes will have become backslashes |
| 405 | call assert_notequal(buf.name, getbufinfo(buf.id)[0].name) |
| 406 | endif |
| 407 | bwipe |
| 408 | endfor |
| 409 | |
| 410 | set shellslash& |
| 411 | endfunc |
| 412 | |
Bram Moolenaar | 8e4b76d | 2022-05-07 11:28:06 +0100 | [diff] [blame] | 413 | " this was using a NULL pointer after failing to use the pattern |
| 414 | func Test_buf_pattern_invalid() |
| 415 | vsplit 0000000 |
| 416 | silent! buf [0--]\&\zs*\zs*e |
| 417 | bwipe! |
Bram Moolenaar | a59f2df | 2022-05-11 11:42:28 +0100 | [diff] [blame] | 418 | |
| 419 | vsplit 00000000000000000000000000 |
| 420 | silent! buf [0--]\&\zs*\zs*e |
| 421 | bwipe! |
Bram Moolenaar | b62dc5e | 2022-05-15 14:50:12 +0100 | [diff] [blame] | 422 | |
| 423 | " similar case with different code path |
| 424 | split 0 |
| 425 | edit ΓΏ |
| 426 | silent! buf [0--]\&\zs*\zs*0 |
| 427 | bwipe! |
Bram Moolenaar | 8e4b76d | 2022-05-07 11:28:06 +0100 | [diff] [blame] | 428 | endfunc |
| 429 | |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 430 | " Test for the 'maxmem' and 'maxmemtot' options |
| 431 | func Test_buffer_maxmem() |
| 432 | " use 1KB per buffer and 2KB for all the buffers |
| 433 | set maxmem=1 maxmemtot=2 |
| 434 | new |
| 435 | let v:errmsg = '' |
| 436 | " try opening some files |
| 437 | edit test_arglist.vim |
| 438 | call assert_equal('test_arglist.vim', bufname()) |
| 439 | edit test_eval_stuff.vim |
| 440 | call assert_equal('test_eval_stuff.vim', bufname()) |
| 441 | b test_arglist.vim |
| 442 | call assert_equal('test_arglist.vim', bufname()) |
| 443 | b test_eval_stuff.vim |
| 444 | call assert_equal('test_eval_stuff.vim', bufname()) |
| 445 | close |
| 446 | call assert_equal('', v:errmsg) |
| 447 | set maxmem& maxmemtot& |
| 448 | endfunc |
| 449 | |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 450 | " Test for buffer allocation failure |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 451 | func Test_buflist_alloc_failure() |
| 452 | %bw! |
| 453 | |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 454 | edit XallocFail1 |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 455 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 456 | call assert_fails('edit XallocFail2', 'E342:') |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 457 | |
| 458 | " test for bufadd() |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 459 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 460 | call assert_fails('call bufadd("Xbuffer")', 'E342:') |
| 461 | |
| 462 | " test for setting the arglist |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 463 | edit XallocFail2 |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 464 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 465 | call assert_fails('next XallocFail3', 'E342:') |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 466 | |
| 467 | " test for setting the alternate buffer name when writing a file |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 468 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 469 | call assert_fails('write Xother', 'E342:') |
| 470 | call delete('Xother') |
| 471 | |
| 472 | " test for creating a buffer using bufnr() |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 473 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 474 | call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:') |
| 475 | |
| 476 | " test for renaming buffer using :file |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 477 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 478 | call assert_fails('file Xnewfile', 'E342:') |
| 479 | |
| 480 | " test for creating a buffer for a popup window |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 481 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 482 | call assert_fails('call popup_create("mypop", {})', 'E342:') |
| 483 | |
| 484 | if has('terminal') |
| 485 | " test for creating a buffer for a terminal window |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 486 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 487 | call assert_fails('call term_start(&shell)', 'E342:') |
| 488 | %bw! |
| 489 | endif |
| 490 | |
| 491 | " test for loading a new buffer after wiping out all the buffers |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 492 | edit XallocFail4 |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 493 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 494 | call assert_fails('%bw!', 'E342:') |
| 495 | |
| 496 | " test for :checktime loading the buffer |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 497 | call writefile(['one'], 'XallocFail5') |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 498 | if has('unix') |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 499 | edit XallocFail5 |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 500 | " sleep for some time to make sure the timestamp is different |
| 501 | sleep 200m |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 502 | call writefile(['two'], 'XallocFail5') |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 503 | set autoread |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 504 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 505 | call assert_fails('checktime', 'E342:') |
| 506 | set autoread& |
| 507 | bw! |
| 508 | endif |
| 509 | |
| 510 | " test for :vimgrep loading a dummy buffer |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 511 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 512 | call assert_fails('vimgrep two XallocFail5', 'E342:') |
| 513 | call delete('XallocFail5') |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 514 | |
| 515 | " test for quickfix command loading a buffer |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 516 | call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) |
Bram Moolenaar | e7cda97 | 2022-08-29 11:02:59 +0100 | [diff] [blame] | 517 | call assert_fails('cexpr "XallocFail6:10:Line10"', 'E342:') |
Yegappan Lakshmanan | 0dac1ab | 2022-04-02 21:46:19 +0100 | [diff] [blame] | 518 | endfunc |
| 519 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 520 | " vim: shiftwidth=2 sts=2 expandtab |