blob: 24fe69be0c5d380a19fde903b0881d6acf18c727 [file] [log] [blame]
Bram Moolenaar429ab172019-01-11 15:54:45 +01001" Tests for 'conceal'.
Bram Moolenaar429ab172019-01-11 15:54:45 +01002
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003source check.vim
4CheckFeature conceal
Bram Moolenaar429ab172019-01-11 15:54:45 +01005
6source screendump.vim
Bram Moolenaarb9081882022-07-09 04:56:24 +01007source view_util.vim
Bram Moolenaar429ab172019-01-11 15:54:45 +01008
9func Test_conceal_two_windows()
zeertzjq20691912022-01-23 12:42:55 +000010 CheckScreendump
11
Bram Moolenaarc79745a2019-05-20 22:12:34 +020012 let code =<< trim [CODE]
13 let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
14 call setline(1, lines)
15 syntax match test /|hidden|/ conceal
16 set conceallevel=2
17 set concealcursor=
18 exe "normal /here\r"
19 new
20 call setline(1, lines)
21 call setline(4, "Second window")
22 syntax match test /|hidden|/ conceal
23 set conceallevel=2
24 set concealcursor=nc
25 exe "normal /here\r"
26 [CODE]
27
28 call writefile(code, 'XTest_conceal')
Bram Moolenaar429ab172019-01-11 15:54:45 +010029 " Check that cursor line is concealed
30 let buf = RunVimInTerminal('-S XTest_conceal', {})
31 call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {})
32
33 " Check that with concealed text vertical cursor movement is correct.
34 call term_sendkeys(buf, "k")
35 call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {})
36
37 " Check that with cursor line is not concealed
38 call term_sendkeys(buf, "j")
39 call term_sendkeys(buf, ":set concealcursor=\r")
40 call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {})
41
42 " Check that with cursor line is not concealed when moving cursor down
43 call term_sendkeys(buf, "j")
44 call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {})
45
46 " Check that with cursor line is not concealed when switching windows
47 call term_sendkeys(buf, "\<C-W>\<C-W>")
48 call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {})
49
50 " Check that with cursor line is only concealed in Normal mode
51 call term_sendkeys(buf, ":set concealcursor=n\r")
52 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {})
53 call term_sendkeys(buf, "a")
54 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {})
55 call term_sendkeys(buf, "\<Esc>/e")
56 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {})
57 call term_sendkeys(buf, "\<Esc>v")
58 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {})
59 call term_sendkeys(buf, "\<Esc>")
60
61 " Check that with cursor line is only concealed in Insert mode
62 call term_sendkeys(buf, ":set concealcursor=i\r")
63 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {})
Bram Moolenaar644b49f2021-09-16 22:32:15 +020064 call term_sendkeys(buf, "14|a")
Bram Moolenaar429ab172019-01-11 15:54:45 +010065 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {})
Bram Moolenaar644b49f2021-09-16 22:32:15 +020066 call term_sendkeys(buf, "\<Esc>")
67 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07in', {})
68 call term_sendkeys(buf, "/e")
Bram Moolenaar429ab172019-01-11 15:54:45 +010069 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {})
70 call term_sendkeys(buf, "\<Esc>v")
71 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {})
72 call term_sendkeys(buf, "\<Esc>")
73
74 " Check that with cursor line is only concealed in Command mode
75 call term_sendkeys(buf, ":set concealcursor=c\r")
76 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {})
77 call term_sendkeys(buf, "a")
78 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {})
79 call term_sendkeys(buf, "\<Esc>/e")
80 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {})
81 call term_sendkeys(buf, "\<Esc>v")
82 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {})
83 call term_sendkeys(buf, "\<Esc>")
84
85 " Check that with cursor line is only concealed in Visual mode
86 call term_sendkeys(buf, ":set concealcursor=v\r")
87 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {})
88 call term_sendkeys(buf, "a")
89 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {})
90 call term_sendkeys(buf, "\<Esc>/e")
91 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {})
92 call term_sendkeys(buf, "\<Esc>v")
93 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {})
94 call term_sendkeys(buf, "\<Esc>")
95
Bram Moolenaar465e8b52019-01-11 20:42:28 +010096 " Check moving the cursor while in insert mode.
97 call term_sendkeys(buf, ":set concealcursor=\r")
98 call term_sendkeys(buf, "a")
99 call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {})
100 call term_sendkeys(buf, "\<Down>")
101 call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {})
102 call term_sendkeys(buf, "\<Esc>")
103
104 " Check the "o" command
105 call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {})
106 call term_sendkeys(buf, "o")
107 call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {})
108 call term_sendkeys(buf, "\<Esc>")
109
Bram Moolenaar429ab172019-01-11 15:54:45 +0100110 " clean up
111 call StopVimInTerminal(buf)
112 call delete('XTest_conceal')
113endfunc
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100114
115func Test_conceal_with_cursorline()
zeertzjq20691912022-01-23 12:42:55 +0000116 CheckScreendump
117
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100118 " Opens a help window, where 'conceal' is set, switches to the other window
119 " where 'cursorline' needs to be updated when the cursor moves.
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200120 let code =<< trim [CODE]
121 set cursorline
122 normal othis is a test
123 new
124 call setline(1, ["one", "two", "three", "four", "five"])
125 set ft=help
126 normal M
127 [CODE]
128
129 call writefile(code, 'XTest_conceal_cul')
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100130 let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
131 call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
132
133 call term_sendkeys(buf, ":wincmd w\r")
134 call VerifyScreenDump(buf, 'Test_conceal_cul_02', {})
135
136 call term_sendkeys(buf, "k")
137 call VerifyScreenDump(buf, 'Test_conceal_cul_03', {})
138
139 " clean up
140 call StopVimInTerminal(buf)
141 call delete('XTest_conceal_cul')
142endfunc
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200143
144func Test_conceal_resize_term()
zeertzjq20691912022-01-23 12:42:55 +0000145 CheckScreendump
146
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200147 let code =<< trim [CODE]
148 call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
149 setl cocu=n cole=3
150 syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
151 normal fb
152 [CODE]
153 call writefile(code, 'XTest_conceal_resize')
154 let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
155 call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
156
157 call win_execute(buf->win_findbuf()[0], 'wincmd +')
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200158 call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
159
160 " clean up
161 call StopVimInTerminal(buf)
162 call delete('XTest_conceal_resize')
163endfunc
Bram Moolenaar213ed002019-12-11 20:12:26 +0100164
165" Tests for correct display (cursor column position) with +conceal and
166" tabulators. Need to run this test in a separate Vim instance. Otherwise the
167" screen is not updated (lazy redraw) and the cursor position is wrong.
168func Test_conceal_cursor_pos()
169 let code =<< trim [CODE]
170 :let l = ['start:', '.concealed. text', "|concealed|\ttext"]
171 :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
172 :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
173 :call append(0, l)
174 :call cursor(1, 1)
175 :" Conceal settings.
176 :set conceallevel=2
177 :set concealcursor=nc
178 :syntax match test /|/ conceal
179 :" Save current cursor position. Only works in <expr> mode, can't be used
180 :" with :normal because it moves the cursor to the command line. Thanks
181 :" to ZyX <zyx.vim@gmail.com> for the idea to use an <expr> mapping.
182 :let curpos = []
183 :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n"
184 :normal ztj
185 GGk
186 :" We should end up in the same column when running these commands on the
187 :" two lines.
188 :normal ft
189 GGk
190 :normal $
191 GGk
192 :normal 0j
193 GGk
194 :normal ft
195 GGk
196 :normal $
197 GGk
198 :normal 0j0j
199 GGk
200 :" Same for next test block.
201 :normal ft
202 GGk
203 :normal $
204 GGk
205 :normal 0j
206 GGk
207 :normal ft
208 GGk
209 :normal $
210 GGk
211 :normal 0j0j
212 GGk
213 :" And check W with multiple tabs and conceals in a line.
214 :normal W
215 GGk
216 :normal W
217 GGk
218 :normal W
219 GGk
220 :normal $
221 GGk
222 :normal 0j
223 GGk
224 :normal W
225 GGk
226 :normal W
227 GGk
228 :normal W
229 GGk
230 :normal $
231 GGk
232 :set lbr
233 :normal $
234 GGk
235 :set list listchars=tab:>-
236 :normal 0
237 GGk
238 :normal W
239 GGk
240 :normal W
241 GGk
242 :normal W
243 GGk
244 :normal $
245 GGk
246 :call writefile(curpos, 'Xconceal_curpos.out')
247 :q!
248
249 [CODE]
250 call writefile(code, 'XTest_conceal_curpos')
251
252 if RunVim([], [], '-s XTest_conceal_curpos')
253 call assert_equal([
254 \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25',
255 \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25',
256 \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1',
257 \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out'))
258 endif
259
260 call delete('Xconceal_curpos.out')
261 call delete('XTest_conceal_curpos')
262endfunc
263
Bram Moolenaarfc838d62020-06-25 22:23:48 +0200264func Test_conceal_eol()
265 new!
266 setlocal concealcursor=n conceallevel=1
267 call setline(1, ["x", ""])
268 call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1})
269 redraw!
270
271 call assert_notequal(screenchar(1, 1), screenchar(2, 2))
272 call assert_equal(screenattr(1, 1), screenattr(1, 2))
273 call assert_equal(screenattr(1, 2), screenattr(2, 2))
274 call assert_equal(screenattr(2, 1), screenattr(2, 2))
275
276 set list
277 redraw!
278
279 call assert_equal(screenattr(1, 1), screenattr(2, 2))
280 call assert_notequal(screenattr(1, 1), screenattr(1, 2))
281 call assert_notequal(screenattr(1, 2), screenattr(2, 1))
282
283 set nolist
284endfunc
285
Bram Moolenaarb9081882022-07-09 04:56:24 +0100286func Test_conceal_mouse_click()
287 enew!
288 set mouse=a
289 setlocal conceallevel=2 concealcursor=nc
290 syn match Concealed "this" conceal
291 hi link Concealed Search
292 call setline(1, 'conceal this click here')
293 redraw
294 call assert_equal(['conceal click here '], ScreenLines(1, 20))
295
296 " click on 'h' of "here" puts cursor there
297 call test_setmouse(1, 16)
298 call feedkeys("\<LeftMouse>", "tx")
299 call assert_equal([0, 1, 20, 0, 20], getcurpos())
300
301 bwipe!
302 set mouse&
303endfunc
304
Bram Moolenaar213ed002019-12-11 20:12:26 +0100305" vim: shiftwidth=2 sts=2 expandtab