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