blob: 2fe6739ed3df8fa0705f7d524f18b7f52d3e35b4 [file] [log] [blame]
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02001" Tests for setbufline() and getbufline()
2
3func Test_setbufline_getbufline()
4 new
5 let b = bufnr('%')
6 hide
7 call assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
8 call assert_equal(['foo'], getbufline(b, 1))
9 call assert_equal(['bar'], getbufline(b, 2))
10 call assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
11 exe "bd!" b
12 call assert_equal([], getbufline(b, 1, 2))
13
14 split Xtest
15 call setline(1, ['a', 'b', 'c'])
16 let b = bufnr('%')
17 wincmd w
18 call assert_equal(1, setbufline(b, 5, ['x']))
19 call assert_equal(1, setbufline(1234, 1, ['x']))
20 call assert_equal(0, setbufline(b, 4, ['d', 'e']))
21 call assert_equal(['c'], getbufline(b, 3))
22 call assert_equal(['d'], getbufline(b, 4))
23 call assert_equal(['e'], getbufline(b, 5))
24 call assert_equal([], getbufline(b, 6))
25 exe "bwipe! " . b
26endfunc
Bram Moolenaar9d954202017-09-04 20:34:19 +020027
28func Test_setline_startup()
29 let cmd = GetVimCommand('Xscript')
30 if cmd == ''
31 return
32 endif
33 call writefile(['call setline(1, "Hello")', 'w Xtest', 'q!'], 'Xscript')
34 call system(cmd)
35 call assert_equal(['Hello'], readfile('Xtest'))
36
37 call delete('Xscript')
38 call delete('Xtest')
39endfunc