xref: /vim-8.2.3635/src/testdir/test_marks.vim (revision 01a6c216)
1
2" Test that a deleted mark is restored after delete-undo-redo-undo.
3func Test_Restore_DelMark()
4  enew!
5  call append(0, ["	textline A", "	textline B", "	textline C"])
6  normal! 2gg
7  set nocp viminfo+=nviminfo
8  exe "normal! i\<C-G>u\<Esc>"
9  exe "normal! maddu\<C-R>u"
10  let pos = getpos("'a")
11  call assert_equal(2, pos[1])
12  call assert_equal(1, pos[2])
13  enew!
14endfunc
15
16" Test that CTRL-A and CTRL-X updates last changed mark '[, '].
17func Test_Incr_Marks()
18  enew!
19  call append(0, ["123 123 123", "123 123 123", "123 123 123"])
20  normal! gg
21  execute "normal! \<C-A>`[v`]rAjwvjw\<C-X>`[v`]rX"
22  call assert_equal("AAA 123 123", getline(1))
23  call assert_equal("123 XXXXXXX", getline(2))
24  call assert_equal("XXX 123 123", getline(3))
25  enew!
26endfunc
27
28func Test_setpos()
29  new one
30  let onebuf = bufnr('%')
31  let onewin = win_getid()
32  call setline(1, ['aaa', 'bbb', 'ccc'])
33  new two
34  let twobuf = bufnr('%')
35  let twowin = win_getid()
36  call setline(1, ['aaa', 'bbb', 'ccc'])
37
38  " for the cursor the buffer number is ignored
39  call setpos(".", [0, 2, 1, 0])
40  call assert_equal([0, 2, 1, 0], getpos("."))
41  call setpos(".", [onebuf, 3, 3, 0])
42  call assert_equal([0, 3, 3, 0], getpos("."))
43
44  call setpos("''", [0, 1, 3, 0])
45  call assert_equal([0, 1, 3, 0], getpos("''"))
46  call setpos("''", [onebuf, 2, 2, 0])
47  call assert_equal([0, 2, 2, 0], getpos("''"))
48
49  " buffer-local marks
50  for mark in ["'a", "'\"", "'[", "']", "'<", "'>"]
51    call win_gotoid(twowin)
52    call setpos(mark, [0, 2, 1, 0])
53    call assert_equal([0, 2, 1, 0], getpos(mark), "for mark " . mark)
54    call setpos(mark, [onebuf, 1, 3, 0])
55    call win_gotoid(onewin)
56    call assert_equal([0, 1, 3, 0], getpos(mark), "for mark " . mark)
57  endfor
58
59  " global marks
60  call win_gotoid(twowin)
61  call setpos("'N", [0, 2, 1, 0])
62  call assert_equal([twobuf, 2, 1, 0], getpos("'N"))
63  call setpos("'N", [onebuf, 1, 3, 0])
64  call assert_equal([onebuf, 1, 3, 0], getpos("'N"))
65
66  call win_gotoid(onewin)
67  bwipe!
68  call win_gotoid(twowin)
69  bwipe!
70endfunc
71
72func Test_marks_cmd()
73  new Xone
74  call setline(1, ['aaa', 'bbb'])
75  norm! maG$mB
76  w!
77  new Xtwo
78  call setline(1, ['ccc', 'ddd'])
79  norm! $mcGmD
80  w!
81
82  b Xone
83  let a = split(execute('marks'), "\n")
84  call assert_equal(9, len(a))
85  call assert_equal('mark line  col file/text', a[0])
86  call assert_equal(" '      2    0 bbb", a[1])
87  call assert_equal(' a      1    0 aaa', a[2])
88  call assert_equal(' B      2    2 bbb', a[3])
89  call assert_equal(' D      2    0 Xtwo', a[4])
90  call assert_equal(' "      1    0 aaa', a[5])
91  call assert_equal(' [      1    0 aaa', a[6])
92  call assert_equal(' ]      2    0 bbb', a[7])
93  call assert_equal(' .      2    0 bbb', a[8])
94
95  b Xtwo
96  let a = split(execute('marks'), "\n")
97  call assert_equal(9, len(a))
98  call assert_equal('mark line  col file/text', a[0])
99  call assert_equal(" '      1    0 ccc", a[1])
100  call assert_equal(' c      1    2 ccc', a[2])
101  call assert_equal(' B      2    2 Xone', a[3])
102  call assert_equal(' D      2    0 ddd', a[4])
103  call assert_equal(' "      2    0 ddd', a[5])
104  call assert_equal(' [      1    0 ccc', a[6])
105  call assert_equal(' ]      2    0 ddd', a[7])
106  call assert_equal(' .      2    0 ddd', a[8])
107
108  b Xone
109  delmarks aB
110  let a = split(execute('marks aBcD'), "\n")
111  call assert_equal(2, len(a))
112  call assert_equal('mark line  col file/text', a[0])
113  call assert_equal(' D      2    0 Xtwo', a[1])
114
115  b Xtwo
116  delmarks cD
117  call assert_fails('marks aBcD', 'E283:')
118
119  call delete('Xone')
120  call delete('Xtwo')
121  %bwipe
122endfunc
123
124func Test_marks_cmd_multibyte()
125  new Xone
126  call setline(1, [repeat('á', &columns)])
127  norm! ma
128
129  let a = split(execute('marks a'), "\n")
130  call assert_equal(2, len(a))
131  let expected = ' a      1    0 ' . repeat('á', &columns - 16)
132  call assert_equal(expected, a[1])
133
134  bwipe!
135endfunc
136