Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 1 | " Tests for setbufline(), getbufline(), appendbufline(), deletebufline() |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 2 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | source util/screendump.vim |
Bram Moolenaar | 11aa62f | 2017-09-04 22:56:01 +0200 | [diff] [blame] | 4 | |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 5 | func Test_setbufline_getbufline() |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 6 | " similar to Test_set_get_bufline() |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 7 | new |
| 8 | let b = bufnr('%') |
| 9 | hide |
| 10 | call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 11 | call assert_equal(['foo'], getbufline(b, 1)) |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 12 | call assert_equal('foo', getbufoneline(b, 1)) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 13 | call assert_equal(['bar'], getbufline(b, '$')) |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 14 | call assert_equal('bar', getbufoneline(b, '$')) |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 15 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 16 | exe "bd!" b |
| 17 | call assert_equal([], getbufline(b, 1, 2)) |
| 18 | |
| 19 | split Xtest |
| 20 | call setline(1, ['a', 'b', 'c']) |
| 21 | let b = bufnr('%') |
| 22 | wincmd w |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 23 | |
| 24 | call assert_equal(1, setbufline(b, 5, 'x')) |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 25 | call assert_equal(1, setbufline(b, 5, ['x'])) |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 26 | call assert_equal(0, setbufline(b, 5, [])) |
| 27 | call assert_equal(0, setbufline(b, 5, test_null_list())) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 28 | |
| 29 | call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 30 | call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 31 | call assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) |
| 32 | call assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1)) |
| 33 | |
| 34 | call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) |
| 35 | |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 36 | call assert_equal(0, setbufline(b, 4, ['d', 'e'])) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 37 | call assert_equal(['c'], b->getbufline(3)) |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 38 | call assert_equal('c', b->getbufoneline(3)) |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 39 | call assert_equal(['d'], getbufline(b, 4)) |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 40 | call assert_equal('d', getbufoneline(b, 4)) |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 41 | call assert_equal(['e'], getbufline(b, 5)) |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 42 | call assert_equal('e', getbufoneline(b, 5)) |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 43 | call assert_equal([], getbufline(b, 6)) |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 44 | call assert_equal([], getbufline(b, 2, 1)) |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 45 | |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 46 | if has('job') |
| 47 | call setbufline(b, 2, [function('eval'), #{key: 123}, test_null_job()]) |
| 48 | call assert_equal(["function('eval')", |
| 49 | \ "{'key': 123}", |
| 50 | \ "no process"], |
| 51 | \ getbufline(b, 2, 4)) |
| 52 | endif |
Bram Moolenaar | b31cf2b | 2017-09-02 19:45:19 +0200 | [diff] [blame] | 53 | exe "bwipe! " . b |
| 54 | endfunc |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 55 | |
Bram Moolenaar | 0c4dc88 | 2017-11-06 21:32:54 +0100 | [diff] [blame] | 56 | func Test_setbufline_getbufline_fold() |
| 57 | split Xtest |
| 58 | setlocal foldmethod=expr foldexpr=0 |
| 59 | let b = bufnr('%') |
| 60 | new |
| 61 | call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 62 | call assert_equal(['foo'], getbufline(b, 1)) |
| 63 | call assert_equal(['bar'], getbufline(b, 2)) |
| 64 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 65 | exe "bwipe!" b |
| 66 | bwipe! |
| 67 | endfunc |
| 68 | |
| 69 | func Test_setbufline_getbufline_fold_tab() |
| 70 | split Xtest |
| 71 | setlocal foldmethod=expr foldexpr=0 |
| 72 | let b = bufnr('%') |
| 73 | tab new |
| 74 | call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 75 | call assert_equal(['foo'], getbufline(b, 1)) |
| 76 | call assert_equal(['bar'], getbufline(b, 2)) |
| 77 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 78 | exe "bwipe!" b |
| 79 | bwipe! |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 82 | func Test_setline_startup() |
| 83 | let cmd = GetVimCommand('Xscript') |
| 84 | if cmd == '' |
| 85 | return |
| 86 | endif |
Bram Moolenaar | 3411265 | 2022-09-05 21:40:44 +0100 | [diff] [blame] | 87 | call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript', 'D') |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 88 | call system(cmd) |
K.Takata | 0500e87 | 2022-09-08 12:28:02 +0100 | [diff] [blame] | 89 | sleep 50m |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 90 | call assert_equal(['Hello'], readfile('Xtest')) |
| 91 | |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 92 | call assert_equal(0, setline(1, [])) |
| 93 | call assert_equal(0, setline(1, test_null_list())) |
| 94 | call assert_equal(0, setline(5, [])) |
| 95 | call assert_equal(0, setline(6, test_null_list())) |
| 96 | |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 97 | call delete('Xtest') |
| 98 | endfunc |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 99 | |
| 100 | func Test_appendbufline() |
| 101 | new |
| 102 | let b = bufnr('%') |
| 103 | hide |
zeertzjq | 228e422 | 2022-11-20 11:13:17 +0000 | [diff] [blame] | 104 | |
| 105 | new |
| 106 | call setline(1, ['line1', 'line2', 'line3']) |
| 107 | normal! 2gggg |
| 108 | call assert_equal(2, line("''")) |
| 109 | |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 110 | call assert_equal(0, appendbufline(b, 0, ['foo', 'bar'])) |
| 111 | call assert_equal(['foo'], getbufline(b, 1)) |
| 112 | call assert_equal(['bar'], getbufline(b, 2)) |
| 113 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
zeertzjq | 228e422 | 2022-11-20 11:13:17 +0000 | [diff] [blame] | 114 | call assert_equal(0, appendbufline(b, 0, 'baz')) |
| 115 | call assert_equal(['baz', 'foo', 'bar'], getbufline(b, 1, 3)) |
| 116 | |
| 117 | " appendbufline() in a hidden buffer shouldn't move marks in current window. |
| 118 | call assert_equal(2, line("''")) |
| 119 | bwipe! |
| 120 | |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 121 | exe "bd!" b |
zeertzjq | 228e422 | 2022-11-20 11:13:17 +0000 | [diff] [blame] | 122 | call assert_equal([], getbufline(b, 1, 3)) |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 123 | |
| 124 | split Xtest |
| 125 | call setline(1, ['a', 'b', 'c']) |
| 126 | let b = bufnr('%') |
| 127 | wincmd w |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 128 | |
| 129 | call assert_equal(1, appendbufline(b, -1, 'x')) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 130 | call assert_equal(1, appendbufline(b, -1, ['x'])) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 131 | call assert_equal(1, appendbufline(b, -1, [])) |
| 132 | call assert_equal(1, appendbufline(b, -1, test_null_list())) |
| 133 | |
| 134 | call assert_equal(1, appendbufline(b, 4, 'x')) |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 135 | call assert_equal(1, appendbufline(b, 4, ['x'])) |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 136 | call assert_equal(0, appendbufline(b, 4, [])) |
| 137 | call assert_equal(0, appendbufline(b, 4, test_null_list())) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 138 | |
| 139 | call assert_equal(1, appendbufline(1234, 1, 'x')) |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 140 | call assert_equal(1, appendbufline(1234, 1, ['x'])) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 141 | call assert_equal(1, appendbufline(1234, 1, [])) |
| 142 | call assert_equal(1, appendbufline(1234, 1, test_null_list())) |
| 143 | |
| 144 | call assert_equal(0, appendbufline(b, 1, [])) |
| 145 | call assert_equal(0, appendbufline(b, 1, test_null_list())) |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 146 | call assert_equal(0, appendbufline(b, 3, [])) |
| 147 | call assert_equal(0, appendbufline(b, 3, test_null_list())) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 148 | |
| 149 | call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) |
| 150 | |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 151 | call assert_equal(0, appendbufline(b, 3, ['d', 'e'])) |
| 152 | call assert_equal(['c'], getbufline(b, 3)) |
| 153 | call assert_equal(['d'], getbufline(b, 4)) |
| 154 | call assert_equal(['e'], getbufline(b, 5)) |
| 155 | call assert_equal([], getbufline(b, 6)) |
| 156 | exe "bwipe! " . b |
| 157 | endfunc |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 158 | |
Bram Moolenaar | 9cea87c | 2018-09-21 16:59:45 +0200 | [diff] [blame] | 159 | func Test_appendbufline_no_E315() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 160 | let after =<< trim [CODE] |
| 161 | set stl=%f ls=2 |
| 162 | new |
| 163 | let buf = bufnr("%") |
| 164 | quit |
| 165 | vsp |
| 166 | exec "buffer" buf |
| 167 | wincmd w |
| 168 | call appendbufline(buf, 0, "abc") |
| 169 | redraw |
| 170 | while getbufline(buf, 1)[0] =~ "^\\s*$" |
| 171 | sleep 10m |
| 172 | endwhile |
| 173 | au VimLeavePre * call writefile([v:errmsg], "Xerror") |
| 174 | au VimLeavePre * call writefile(["done"], "Xdone") |
| 175 | qall! |
| 176 | [CODE] |
| 177 | |
Bram Moolenaar | 9cea87c | 2018-09-21 16:59:45 +0200 | [diff] [blame] | 178 | if !RunVim([], after, '--clean') |
| 179 | return |
| 180 | endif |
| 181 | call assert_notmatch("^E315:", readfile("Xerror")[0]) |
| 182 | call assert_equal("done", readfile("Xdone")[0]) |
| 183 | call delete("Xerror") |
| 184 | call delete("Xdone") |
| 185 | endfunc |
| 186 | |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 187 | func Test_deletebufline() |
| 188 | new |
| 189 | let b = bufnr('%') |
| 190 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 191 | hide |
zeertzjq | 228e422 | 2022-11-20 11:13:17 +0000 | [diff] [blame] | 192 | |
| 193 | new |
| 194 | call setline(1, ['line1', 'line2', 'line3']) |
| 195 | normal! 2gggg |
| 196 | call assert_equal(2, line("''")) |
| 197 | |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 198 | call assert_equal(0, deletebufline(b, 2)) |
| 199 | call assert_equal(['aaa', 'ccc'], getbufline(b, 1, 2)) |
| 200 | call assert_equal(0, deletebufline(b, 2, 8)) |
| 201 | call assert_equal(['aaa'], getbufline(b, 1, 2)) |
zeertzjq | 228e422 | 2022-11-20 11:13:17 +0000 | [diff] [blame] | 202 | |
| 203 | " deletebufline() in a hidden buffer shouldn't move marks in current window. |
| 204 | call assert_equal(2, line("''")) |
| 205 | bwipe! |
| 206 | |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 207 | exe "bd!" b |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 208 | call assert_equal(1, b->deletebufline(1)) |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 209 | |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 210 | call assert_equal(1, deletebufline(-1, 1)) |
| 211 | |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 212 | split Xtest |
| 213 | call setline(1, ['a', 'b', 'c']) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 214 | call cursor(line('$'), 1) |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 215 | let b = bufnr('%') |
| 216 | wincmd w |
| 217 | call assert_equal(1, deletebufline(b, 4)) |
| 218 | call assert_equal(0, deletebufline(b, 1)) |
| 219 | call assert_equal(['b', 'c'], getbufline(b, 1, 2)) |
| 220 | exe "bwipe! " . b |
Bram Moolenaar | 963ffa0 | 2021-02-09 20:02:55 +0100 | [diff] [blame] | 221 | |
| 222 | edit XbufOne |
| 223 | let one = bufnr() |
| 224 | call setline(1, ['a', 'b', 'c']) |
| 225 | setlocal nomodifiable |
| 226 | split XbufTwo |
| 227 | let two = bufnr() |
| 228 | call assert_fails('call deletebufline(one, 1)', 'E21:') |
| 229 | call assert_equal(two, bufnr()) |
| 230 | bwipe! XbufTwo |
| 231 | bwipe! XbufOne |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 232 | endfunc |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 233 | |
| 234 | func Test_appendbufline_redraw() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 235 | CheckScreendump |
| 236 | |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 237 | let lines =<< trim END |
| 238 | new foo |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 239 | let winnr = 'foo'->bufwinnr() |
| 240 | let buf = bufnr('foo') |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 241 | wincmd p |
| 242 | call appendbufline(buf, '$', range(1,200)) |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 243 | exe winnr .. 'wincmd w' |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 244 | norm! G |
| 245 | wincmd p |
| 246 | call deletebufline(buf, 1, '$') |
| 247 | call appendbufline(buf, '$', 'Hello Vim world...') |
| 248 | END |
Bram Moolenaar | 3411265 | 2022-09-05 21:40:44 +0100 | [diff] [blame] | 249 | call writefile(lines, 'XscriptMatchCommon', 'D') |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 250 | let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10}) |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 251 | call VerifyScreenDump(buf, 'Test_appendbufline_1', {}) |
| 252 | |
| 253 | call StopVimInTerminal(buf) |
Bram Moolenaar | 2984666 | 2019-07-27 17:39:15 +0200 | [diff] [blame] | 254 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 255 | |
Bram Moolenaar | 0ad00a7 | 2022-05-22 11:59:25 +0100 | [diff] [blame] | 256 | func Test_setbufline_select_mode() |
| 257 | new |
| 258 | call setline(1, ['foo', 'bar']) |
| 259 | call feedkeys("j^v2l\<C-G>", 'nx') |
| 260 | |
| 261 | let bufnr = bufadd('Xdummy') |
| 262 | call bufload(bufnr) |
| 263 | call setbufline(bufnr, 1, ['abc']) |
| 264 | |
| 265 | call feedkeys("x", 'nx') |
| 266 | call assert_equal(['foo', 'x'], getline(1, 2)) |
| 267 | |
| 268 | exe "bwipe! " .. bufnr |
| 269 | bwipe! |
| 270 | endfunc |
| 271 | |
LemonBoy | 9b2edfd | 2022-05-22 15:35:53 +0100 | [diff] [blame] | 272 | func Test_deletebufline_select_mode() |
| 273 | new |
| 274 | call setline(1, ['foo', 'bar']) |
| 275 | call feedkeys("j^v2l\<C-G>", 'nx') |
| 276 | |
| 277 | let bufnr = bufadd('Xdummy') |
| 278 | call bufload(bufnr) |
| 279 | call setbufline(bufnr, 1, ['abc', 'def']) |
| 280 | call deletebufline(bufnr, 1) |
| 281 | |
| 282 | call feedkeys("x", 'nx') |
| 283 | call assert_equal(['foo', 'x'], getline(1, 2)) |
| 284 | |
| 285 | exe "bwipe! " .. bufnr |
| 286 | bwipe! |
| 287 | endfunc |
| 288 | |
Bram Moolenaar | 3da8597 | 2022-11-27 19:45:49 +0000 | [diff] [blame] | 289 | func Test_deletebufline_popup_window() |
| 290 | let popupID = popup_create('foo', {}) |
| 291 | let bufnr = winbufnr(popupID) |
| 292 | |
| 293 | " Check that deletebufline() brings us back to the same window. |
| 294 | new |
| 295 | let winid_before = win_getid() |
| 296 | call deletebufline(bufnr, 1, '$') |
| 297 | call assert_equal(winid_before, win_getid()) |
| 298 | bwipe |
| 299 | |
| 300 | call popup_close(popupID) |
| 301 | endfunc |
| 302 | |
zeertzjq | 93f72cc | 2022-08-26 15:34:52 +0100 | [diff] [blame] | 303 | func Test_setbufline_startup_nofile() |
| 304 | let before =<< trim [CODE] |
| 305 | set shortmess+=F |
| 306 | file Xresult |
| 307 | set buftype=nofile |
| 308 | call setbufline('', 1, 'success') |
| 309 | [CODE] |
| 310 | let after =<< trim [CODE] |
| 311 | set buftype= |
| 312 | write |
| 313 | quit |
| 314 | [CODE] |
| 315 | |
| 316 | if !RunVim(before, after, '--clean') |
| 317 | return |
| 318 | endif |
| 319 | call assert_equal(['success'], readfile('Xresult')) |
| 320 | call delete('Xresult') |
| 321 | endfunc |
| 322 | |
zeertzjq | 7af3ee2 | 2022-11-06 22:26:05 +0000 | [diff] [blame] | 323 | " Test that setbufline(), appendbufline() and deletebufline() should fail and |
| 324 | " return 1 when "textlock" is active. |
| 325 | func Test_change_bufline_with_textlock() |
| 326 | new |
| 327 | inoremap <buffer> <expr> <F2> setbufline('', 1, '') |
| 328 | call assert_fails("normal a\<F2>", 'E565:') |
| 329 | call assert_equal('1', getline(1)) |
| 330 | inoremap <buffer> <expr> <F2> appendbufline('', 1, '') |
| 331 | call assert_fails("normal a\<F2>", 'E565:') |
| 332 | call assert_equal('11', getline(1)) |
| 333 | inoremap <buffer> <expr> <F2> deletebufline('', 1) |
| 334 | call assert_fails("normal a\<F2>", 'E565:') |
| 335 | call assert_equal('111', getline(1)) |
| 336 | bwipe! |
| 337 | endfunc |
| 338 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 339 | " vim: shiftwidth=2 sts=2 expandtab |