robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #26018 from zeertzjq/vim-9.0.01376fa9f45723

master
2.9 KiB107 linesraw
1" Tests for the changelist functionality
2
3" When splitting a window the changelist position is wrong.
4" Test the changelist position after splitting a window.
5" Test for the bug fixed by 7.4.386
6func Test_changelist()
7  let save_ul = &ul
8  enew!
9  call append('$', ['1', '2'])
10  exe "normal i\<C-G>u"
11  exe "normal Gkylpa\<C-G>u"
12  set ul=100
13  exe "normal Gylpa\<C-G>u"
14  set ul=100
15  normal gg
16  vsplit
17  normal g;
18  call assert_equal([3, 2], [line('.'), col('.')])
19  normal g;
20  call assert_equal([2, 2], [line('.'), col('.')])
21  call assert_fails('normal g;', 'E662:')
22  new
23  call assert_fails('normal g;', 'E664:')
24  %bwipe!
25  let &ul = save_ul
26endfunc
27
28" Moving a split should not change its changelist index.
29func Test_changelist_index_move_split()
30  exe "norm! iabc\<C-G>u\ndef\<C-G>u\nghi"
31  vsplit
32  normal 99g;
33  call assert_equal(0, getchangelist('%')[1])
34  wincmd L
35  call assert_equal(0, getchangelist('%')[1])
36endfunc
37
38" Tests for the getchangelist() function
39func Test_changelist_index()
40  edit Xgclfile1.txt
41  exe "normal iabc\<C-G>u\ndef\<C-G>u\nghi"
42  call assert_equal(3, getchangelist('%')[1])
43  " Move one step back in the changelist.
44  normal 2g;
45
46  hide edit Xgclfile2.txt
47  exe "normal iabcd\<C-G>u\ndefg\<C-G>u\nghij"
48  call assert_equal(3, getchangelist('%')[1])
49  " Move to the beginning of the changelist.
50  normal 99g;
51
52  " Check the changelist indices.
53  call assert_equal(0, getchangelist('%')[1])
54  call assert_equal(1, getchangelist('#')[1])
55
56  bwipe!
57  call delete('Xgclfile1.txt')
58  call delete('Xgclfile2.txt')
59endfunc
60
61func Test_getchangelist()
62  bwipe!
63  enew
64  call assert_equal([], 10->getchangelist())
65  call assert_equal([[], 0], getchangelist())
66
67  call writefile(['line1', 'line2', 'line3'], 'Xclistfile1.txt')
68  call writefile(['line1', 'line2', 'line3'], 'Xclistfile2.txt')
69
70  edit Xclistfile1.txt
71  let buf_1 = bufnr()
72  exe "normal 1Goline\<C-G>u1.1"
73  exe "normal 3Goline\<C-G>u2.1"
74  exe "normal 5Goline\<C-G>u3.1"
75  normal g;
76  call assert_equal([[
77	      \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
78	      \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
79	      \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
80	      \ getchangelist('%'))
81
82  hide edit Xclistfile2.txt
83  let buf_2 = bufnr()
84  exe "normal 1GOline\<C-G>u1.0"
85  exe "normal 2Goline\<C-G>u2.0"
86  call assert_equal([[
87	      \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
88	      \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
89	      \ getchangelist('%'))
90  hide enew
91
92  call assert_equal([[
93	      \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
94	      \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
95	      \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
96	      \ getchangelist(buf_1))
97  call assert_equal([[
98	      \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
99	      \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
100	      \ getchangelist(buf_2))
101
102  bwipe!
103  call delete('Xclistfile1.txt')
104  call delete('Xclistfile2.txt')
105endfunc
106
107" vim: shiftwidth=2 sts=2 expandtab