blob: f42996821865a6952fc41aa9c0df4a21090feedd [file] [log] [blame]
Bram Moolenaar07ad8162018-02-13 13:59:59 +01001" Tests for the changelist functionality
2
3" Tests for the getchangelist() function
LemonBoydb0ea7f2022-04-10 17:59:26 +01004func Test_changelist_index()
5 edit Xfile1.txt
6 exe "normal iabc\<C-G>u\ndef\<C-G>u\nghi"
7 call assert_equal(3, getchangelist('%')[1])
8 " Move one step back in the changelist.
9 normal 2g;
10
11 hide edit Xfile2.txt
12 exe "normal iabcd\<C-G>u\ndefg\<C-G>u\nghij"
13 call assert_equal(3, getchangelist('%')[1])
14 " Move to the beginning of the changelist.
15 normal 99g;
16
17 " Check the changelist indices.
18 call assert_equal(0, getchangelist('%')[1])
19 call assert_equal(1, getchangelist('#')[1])
20
21 bwipe!
22 call delete('Xfile1.txt')
23 call delete('Xfile2.txt')
24endfunc
25
Bram Moolenaar07ad8162018-02-13 13:59:59 +010026func Test_getchangelist()
Bram Moolenaar07ad8162018-02-13 13:59:59 +010027 bwipe!
28 enew
Bram Moolenaar4c313b12019-08-24 22:58:31 +020029 call assert_equal([], 10->getchangelist())
30 call assert_equal([[], 0], getchangelist())
Bram Moolenaar07ad8162018-02-13 13:59:59 +010031
32 call writefile(['line1', 'line2', 'line3'], 'Xfile1.txt')
33 call writefile(['line1', 'line2', 'line3'], 'Xfile2.txt')
34
35 edit Xfile1.txt
LemonBoydb0ea7f2022-04-10 17:59:26 +010036 let buf_1 = bufnr()
Bram Moolenaar07ad8162018-02-13 13:59:59 +010037 exe "normal 1Goline\<C-G>u1.1"
38 exe "normal 3Goline\<C-G>u2.1"
39 exe "normal 5Goline\<C-G>u3.1"
40 normal g;
41 call assert_equal([[
42 \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
43 \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
44 \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
Bram Moolenaar341a64c2018-02-13 19:21:17 +010045 \ getchangelist('%'))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010046
47 hide edit Xfile2.txt
LemonBoydb0ea7f2022-04-10 17:59:26 +010048 let buf_2 = bufnr()
Bram Moolenaar07ad8162018-02-13 13:59:59 +010049 exe "normal 1GOline\<C-G>u1.0"
50 exe "normal 2Goline\<C-G>u2.0"
51 call assert_equal([[
52 \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
53 \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
Bram Moolenaar341a64c2018-02-13 19:21:17 +010054 \ getchangelist('%'))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010055 hide enew
56
57 call assert_equal([[
58 \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
59 \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
LemonBoydb0ea7f2022-04-10 17:59:26 +010060 \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
61 \ getchangelist(buf_1))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010062 call assert_equal([[
63 \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
LemonBoydb0ea7f2022-04-10 17:59:26 +010064 \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
65 \ getchangelist(buf_2))
Bram Moolenaar07ad8162018-02-13 13:59:59 +010066
67 bwipe!
68 call delete('Xfile1.txt')
69 call delete('Xfile2.txt')
70endfunc
Bram Moolenaar1671f442020-03-10 07:48:13 +010071
72" vim: shiftwidth=2 sts=2 expandtab