blob: 02dbd76194c1743514c748df0a7f45a0e1ff8c51 [file] [log] [blame]
Bram Moolenaar4f505882018-02-10 21:06:32 +01001" Tests for the jumplist functionality
2
3" Tests for the getjumplist() function
4func Test_getjumplist()
5 if !has("jumplist")
6 return
7 endif
8
9 %bwipe
10 clearjumps
11 call assert_equal([[], 0], getjumplist())
12 call assert_equal([[], 0], getjumplist(1))
13 call assert_equal([[], 0], getjumplist(1, 1))
14
15 call assert_equal([], getjumplist(100))
16 call assert_equal([], getjumplist(1, 100))
17
18 let lines = []
19 for i in range(1, 100)
20 call add(lines, "Line " . i)
21 endfor
22 call writefile(lines, "Xtest")
23
24 " Jump around and create a jump list
25 edit Xtest
26 let bnr = bufnr('%')
27 normal 50%
28 normal G
29 normal gg
30
31 call assert_equal([[
32 \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
Bram Moolenaar4f505882018-02-10 21:06:32 +010033 \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0},
34 \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 4],
35 \ getjumplist())
36
37 " Traverse the jump list and verify the results
38 5
39 exe "normal \<C-O>"
40 call assert_equal(2, getjumplist(1)[1])
41 exe "normal 2\<C-O>"
42 call assert_equal(0, getjumplist(1, 1)[1])
43 exe "normal 3\<C-I>"
44 call assert_equal(3, getjumplist()[1])
45 exe "normal \<C-O>"
46 normal 20%
47 call assert_equal([[
48 \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
49 \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0},
Bram Moolenaar4f505882018-02-10 21:06:32 +010050 \ {'lnum': 5, 'bufnr': bnr, 'col': 0, 'coladd': 0},
51 \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 5],
52 \ getjumplist())
53
54 let l = getjumplist()
55 call test_garbagecollect_now()
Bram Moolenaara7e18d22018-02-11 14:29:49 +010056 call assert_equal(4, l[1])
Bram Moolenaar4f505882018-02-10 21:06:32 +010057 clearjumps
58 call test_garbagecollect_now()
Bram Moolenaara7e18d22018-02-11 14:29:49 +010059 call assert_equal(4, l[1])
Bram Moolenaar4f505882018-02-10 21:06:32 +010060
61 call delete("Xtest")
62endfunc