blob: b05246e0646fde425e57d59a9a84483ea22769af [file] [log] [blame]
Bram Moolenaar19a16692016-09-01 22:19:47 +02001
2" Test that a deleted mark is restored after delete-undo-redo-undo.
3function! 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!
14endfunction
15
16" Test that CTRL-A and CTRL-X updates last changed mark '[, '].
17function! 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!
26endfunction
Bram Moolenaarf13e00b2017-01-28 18:23:54 +010027
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
Bram Moolenaar9b69f222017-10-08 21:53:15 +020071
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
Bram Moolenaar9d5185b2018-07-08 17:57:34 +020083 let a = split(execute('marks'), "\n")
Bram Moolenaar9b69f222017-10-08 21:53:15 +020084 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
Bram Moolenaar9d5185b2018-07-08 17:57:34 +020096 let a = split(execute('marks'), "\n")
Bram Moolenaar9b69f222017-10-08 21:53:15 +020097 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
Bram Moolenaar9d5185b2018-07-08 17:57:34 +0200110 let a = split(execute('marks aBcD'), "\n")
Bram Moolenaar9b69f222017-10-08 21:53:15 +0200111 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
Bram Moolenaar9d5185b2018-07-08 17:57:34 +0200123
124func Test_marks_cmd_multibyte()
125 if !has('multi_byte')
126 return
127 endif
128 new Xone
129 call setline(1, ['ááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááááá'])
130 norm! ma
131
132 let a = split(execute('marks a'), "\n")
133 call assert_equal(2, len(a))
134 let expected = ' a 1 0 '
135 while strwidth(expected) < &columns - 1
136 let expected .= 'á'
137 endwhile
138 call assert_equal(expected, a[1])
139
140 bwipe!
141endfunc