blob: c9d8ea4ea17f28e5aa33395a8379105b19257661 [file] [log] [blame]
Bram Moolenaar07ad8162018-02-13 13:59:59 +01001" Tests for the changelist functionality
2
zeertzjqe6f13b42022-05-28 10:49:44 +01003" 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
Bram Moolenaar07ad8162018-02-13 13:59:59 +010038" Tests for the getchangelist() function
LemonBoydb0ea7f2022-04-10 17:59:26 +010039func Test_changelist_index()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +010040 edit Xgclfile1.txt
LemonBoydb0ea7f2022-04-10 17:59:26 +010041 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
Bram Moolenaar61abe7d2022-08-30 21:46:08 +010046 hide edit Xgclfile2.txt
LemonBoydb0ea7f2022-04-10 17:59:26 +010047 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!
Bram Moolenaar61abe7d2022-08-30 21:46:08 +010057 call delete('Xgclfile1.txt')
58 call delete('Xgclfile2.txt')
LemonBoydb0ea7f2022-04-10 17:59:26 +010059endfunc
60
Bram Moolenaar07ad8162018-02-13 13:59:59 +010061func Test_getchangelist()
Bram Moolenaar07ad8162018-02-13 13:59:59 +010062 bwipe!
63 enew
Bram Moolenaar4c313b12019-08-24 22:58:31 +020064 call assert_equal([], 10->getchangelist())
65 call assert_equal([[], 0], getchangelist())
Bram Moolenaar07ad8162018-02-13 13:59:59 +010066
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010067 call writefile(['line1', 'line2', 'line3'], 'Xclistfile1.txt', 'D')
68 call writefile(['line1', 'line2', 'line3'], 'Xclistfile2.txt', 'D')
Bram Moolenaar07ad8162018-02-13 13:59:59 +010069
Bram Moolenaar61abe7d2022-08-30 21:46:08 +010070 edit Xclistfile1.txt
LemonBoydb0ea7f2022-04-10 17:59:26 +010071 let buf_1 = bufnr()
Bram Moolenaar07ad8162018-02-13 13:59:59 +010072 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],
Bram Moolenaar341a64c2018-02-13 19:21:17 +010080 \ getchangelist('%'))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010081
Bram Moolenaar61abe7d2022-08-30 21:46:08 +010082 hide edit Xclistfile2.txt
LemonBoydb0ea7f2022-04-10 17:59:26 +010083 let buf_2 = bufnr()
Bram Moolenaar07ad8162018-02-13 13:59:59 +010084 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],
Bram Moolenaar341a64c2018-02-13 19:21:17 +010089 \ getchangelist('%'))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010090 hide enew
91
92 call assert_equal([[
93 \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
94 \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
LemonBoydb0ea7f2022-04-10 17:59:26 +010095 \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
96 \ getchangelist(buf_1))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010097 call assert_equal([[
98 \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
LemonBoydb0ea7f2022-04-10 17:59:26 +010099 \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
100 \ getchangelist(buf_2))
Bram Moolenaar07ad8162018-02-13 13:59:59 +0100101
102 bwipe!
Bram Moolenaar07ad8162018-02-13 13:59:59 +0100103endfunc
Bram Moolenaar1671f442020-03-10 07:48:13 +0100104
105" vim: shiftwidth=2 sts=2 expandtab