1" Tests for setbufline(), getbufline(), appendbufline(), deletebufline() 2 3source shared.vim 4 5func 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 28endfunc 29 30func 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! 41endfunc 42 43func 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! 54endfunc 55 56func Test_setline_startup() 57 let cmd = GetVimCommand('Xscript') 58 if cmd == '' 59 return 60 endif 61 call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') 62 call system(cmd) 63 call assert_equal(['Hello'], readfile('Xtest')) 64 65 call delete('Xscript') 66 call delete('Xtest') 67endfunc 68 69func 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 92endfunc 93 94func 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 114endfunc 115