blob: 7079d21aa43aa1d207fb5f812ed3875d9ecbcb09 [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},
33 \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
34 \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0},
35 \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 4],
36 \ getjumplist())
37
38 " Traverse the jump list and verify the results
39 5
40 exe "normal \<C-O>"
41 call assert_equal(2, getjumplist(1)[1])
42 exe "normal 2\<C-O>"
43 call assert_equal(0, getjumplist(1, 1)[1])
44 exe "normal 3\<C-I>"
45 call assert_equal(3, getjumplist()[1])
46 exe "normal \<C-O>"
47 normal 20%
48 call assert_equal([[
49 \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
50 \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0},
51 \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0},
52 \ {'lnum': 5, 'bufnr': bnr, 'col': 0, 'coladd': 0},
53 \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 5],
54 \ getjumplist())
55
56 let l = getjumplist()
57 call test_garbagecollect_now()
58 call assert_equal(5, l[1])
59 clearjumps
60 call test_garbagecollect_now()
61 call assert_equal(5, l[1])
62
63 call delete("Xtest")
64endfunc