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 | |
Bram Moolenaar | 660b85e | 2017-09-30 14:26:58 +0200 | [diff] [blame] | 3 | source shared.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() |
| 6 | new |
| 7 | let b = bufnr('%') |
| 8 | hide |
| 9 | call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 10 | call assert_equal(['foo'], getbufline(b, 1)) |
| 11 | call assert_equal(['bar'], getbufline(b, 2)) |
| 12 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 13 | exe "bd!" b |
| 14 | call assert_equal([], getbufline(b, 1, 2)) |
| 15 | |
| 16 | split Xtest |
| 17 | call setline(1, ['a', 'b', 'c']) |
| 18 | let b = bufnr('%') |
| 19 | wincmd w |
| 20 | call assert_equal(1, setbufline(b, 5, ['x'])) |
| 21 | call assert_equal(1, setbufline(1234, 1, ['x'])) |
| 22 | call assert_equal(0, setbufline(b, 4, ['d', 'e'])) |
| 23 | call assert_equal(['c'], getbufline(b, 3)) |
| 24 | call assert_equal(['d'], getbufline(b, 4)) |
| 25 | call assert_equal(['e'], getbufline(b, 5)) |
| 26 | call assert_equal([], getbufline(b, 6)) |
| 27 | exe "bwipe! " . b |
| 28 | endfunc |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 29 | |
Bram Moolenaar | 0c4dc88 | 2017-11-06 21:32:54 +0100 | [diff] [blame] | 30 | func Test_setbufline_getbufline_fold() |
| 31 | split Xtest |
| 32 | setlocal foldmethod=expr foldexpr=0 |
| 33 | let b = bufnr('%') |
| 34 | new |
| 35 | call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 36 | call assert_equal(['foo'], getbufline(b, 1)) |
| 37 | call assert_equal(['bar'], getbufline(b, 2)) |
| 38 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 39 | exe "bwipe!" b |
| 40 | bwipe! |
| 41 | endfunc |
| 42 | |
| 43 | func Test_setbufline_getbufline_fold_tab() |
| 44 | split Xtest |
| 45 | setlocal foldmethod=expr foldexpr=0 |
| 46 | let b = bufnr('%') |
| 47 | tab new |
| 48 | call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 49 | call assert_equal(['foo'], getbufline(b, 1)) |
| 50 | call assert_equal(['bar'], getbufline(b, 2)) |
| 51 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 52 | exe "bwipe!" b |
| 53 | bwipe! |
| 54 | endfunc |
| 55 | |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 56 | func Test_setline_startup() |
| 57 | let cmd = GetVimCommand('Xscript') |
| 58 | if cmd == '' |
| 59 | return |
| 60 | endif |
Bram Moolenaar | 11aa62f | 2017-09-04 22:56:01 +0200 | [diff] [blame] | 61 | call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 62 | call system(cmd) |
| 63 | call assert_equal(['Hello'], readfile('Xtest')) |
| 64 | |
| 65 | call delete('Xscript') |
| 66 | call delete('Xtest') |
| 67 | endfunc |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 68 | |
| 69 | func Test_appendbufline() |
| 70 | new |
| 71 | let b = bufnr('%') |
| 72 | hide |
| 73 | call assert_equal(0, appendbufline(b, 0, ['foo', 'bar'])) |
| 74 | call assert_equal(['foo'], getbufline(b, 1)) |
| 75 | call assert_equal(['bar'], getbufline(b, 2)) |
| 76 | call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 77 | exe "bd!" b |
| 78 | call assert_equal([], getbufline(b, 1, 2)) |
| 79 | |
| 80 | split Xtest |
| 81 | call setline(1, ['a', 'b', 'c']) |
| 82 | let b = bufnr('%') |
| 83 | wincmd w |
| 84 | call assert_equal(1, appendbufline(b, 4, ['x'])) |
| 85 | call assert_equal(1, appendbufline(1234, 1, ['x'])) |
| 86 | call assert_equal(0, appendbufline(b, 3, ['d', 'e'])) |
| 87 | call assert_equal(['c'], getbufline(b, 3)) |
| 88 | call assert_equal(['d'], getbufline(b, 4)) |
| 89 | call assert_equal(['e'], getbufline(b, 5)) |
| 90 | call assert_equal([], getbufline(b, 6)) |
| 91 | exe "bwipe! " . b |
| 92 | endfunc |
Bram Moolenaar | d79a262 | 2018-06-07 18:17:46 +0200 | [diff] [blame] | 93 | |
| 94 | func Test_deletebufline() |
| 95 | new |
| 96 | let b = bufnr('%') |
| 97 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 98 | hide |
| 99 | call assert_equal(0, deletebufline(b, 2)) |
| 100 | call assert_equal(['aaa', 'ccc'], getbufline(b, 1, 2)) |
| 101 | call assert_equal(0, deletebufline(b, 2, 8)) |
| 102 | call assert_equal(['aaa'], getbufline(b, 1, 2)) |
| 103 | exe "bd!" b |
| 104 | call assert_equal(1, deletebufline(b, 1)) |
| 105 | |
| 106 | split Xtest |
| 107 | call setline(1, ['a', 'b', 'c']) |
| 108 | let b = bufnr('%') |
| 109 | wincmd w |
| 110 | call assert_equal(1, deletebufline(b, 4)) |
| 111 | call assert_equal(0, deletebufline(b, 1)) |
| 112 | call assert_equal(['b', 'c'], getbufline(b, 1, 2)) |
| 113 | exe "bwipe! " . b |
| 114 | endfunc |