xref: /vim-8.2.3635/src/testdir/test_bufline.vim (revision 51ad4eaa)
1" Tests for setbufline() and getbufline()
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