blob: 385d42b5448e457e9ac56cab67ba6399e0c158f3 [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
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010028 call writefile(code, 'XTest_conceal', 'D')
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)
Bram Moolenaar429ab172019-01-11 15:54:45 +0100112endfunc
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100113
114func Test_conceal_with_cursorline()
zeertzjq20691912022-01-23 12:42:55 +0000115 CheckScreendump
116
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100117 " Opens a help window, where 'conceal' is set, switches to the other window
118 " where 'cursorline' needs to be updated when the cursor moves.
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200119 let code =<< trim [CODE]
120 set cursorline
121 normal othis is a test
122 new
123 call setline(1, ["one", "two", "three", "four", "five"])
124 set ft=help
125 normal M
126 [CODE]
127
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100128 call writefile(code, 'XTest_conceal_cul', 'D')
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100129 let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
130 call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
131
132 call term_sendkeys(buf, ":wincmd w\r")
133 call VerifyScreenDump(buf, 'Test_conceal_cul_02', {})
134
135 call term_sendkeys(buf, "k")
136 call VerifyScreenDump(buf, 'Test_conceal_cul_03', {})
137
138 " clean up
139 call StopVimInTerminal(buf)
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100140endfunc
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200141
142func Test_conceal_resize_term()
zeertzjq20691912022-01-23 12:42:55 +0000143 CheckScreendump
144
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200145 let code =<< trim [CODE]
146 call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
147 setl cocu=n cole=3
148 syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
149 normal fb
150 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100151 call writefile(code, 'XTest_conceal_resize', 'D')
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200152 let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
153 call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
154
155 call win_execute(buf->win_findbuf()[0], 'wincmd +')
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200156 call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
157
158 " clean up
159 call StopVimInTerminal(buf)
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200160endfunc
Bram Moolenaar213ed002019-12-11 20:12:26 +0100161
Bram Moolenaar75008662022-10-04 22:40:56 +0100162func Test_conceal_linebreak()
163 CheckScreendump
164
165 let code =<< trim [CODE]
166 vim9script
167 &wrap = true
168 &conceallevel = 2
169 &concealcursor = 'nc'
170 &linebreak = true
171 &showbreak = '+ '
172 var line: string = 'a`a`a`a`'
173 .. 'a'->repeat(&columns - 15)
174 .. ' b`b`'
175 .. 'b'->repeat(&columns - 10)
176 .. ' cccccc'
177 ['x'->repeat(&columns), '', line]->setline(1)
178 syntax region CodeSpan matchgroup=Delimiter start=/\z(`\+\)/ end=/\z1/ concealends
179 [CODE]
180 call writefile(code, 'XTest_conceal_linebreak', 'D')
181 let buf = RunVimInTerminal('-S XTest_conceal_linebreak', {'rows': 8})
182 call VerifyScreenDump(buf, 'Test_conceal_linebreak_1', {})
183
184 " clean up
185 call StopVimInTerminal(buf)
186endfunc
187
Bram Moolenaar213ed002019-12-11 20:12:26 +0100188" Tests for correct display (cursor column position) with +conceal and
189" tabulators. Need to run this test in a separate Vim instance. Otherwise the
190" screen is not updated (lazy redraw) and the cursor position is wrong.
191func Test_conceal_cursor_pos()
192 let code =<< trim [CODE]
193 :let l = ['start:', '.concealed. text', "|concealed|\ttext"]
194 :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
195 :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
196 :call append(0, l)
197 :call cursor(1, 1)
198 :" Conceal settings.
199 :set conceallevel=2
200 :set concealcursor=nc
201 :syntax match test /|/ conceal
202 :" Save current cursor position. Only works in <expr> mode, can't be used
203 :" with :normal because it moves the cursor to the command line. Thanks
204 :" to ZyX <zyx.vim@gmail.com> for the idea to use an <expr> mapping.
205 :let curpos = []
206 :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n"
207 :normal ztj
208 GGk
209 :" We should end up in the same column when running these commands on the
210 :" two lines.
211 :normal ft
212 GGk
213 :normal $
214 GGk
215 :normal 0j
216 GGk
217 :normal ft
218 GGk
219 :normal $
220 GGk
221 :normal 0j0j
222 GGk
223 :" Same for next test block.
224 :normal ft
225 GGk
226 :normal $
227 GGk
228 :normal 0j
229 GGk
230 :normal ft
231 GGk
232 :normal $
233 GGk
234 :normal 0j0j
235 GGk
236 :" And check W with multiple tabs and conceals in a line.
237 :normal W
238 GGk
239 :normal W
240 GGk
241 :normal W
242 GGk
243 :normal $
244 GGk
245 :normal 0j
246 GGk
247 :normal W
248 GGk
249 :normal W
250 GGk
251 :normal W
252 GGk
253 :normal $
254 GGk
255 :set lbr
256 :normal $
257 GGk
258 :set list listchars=tab:>-
259 :normal 0
260 GGk
261 :normal W
262 GGk
263 :normal W
264 GGk
265 :normal W
266 GGk
267 :normal $
268 GGk
269 :call writefile(curpos, 'Xconceal_curpos.out')
270 :q!
271
272 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100273 call writefile(code, 'XTest_conceal_curpos', 'D')
Bram Moolenaar213ed002019-12-11 20:12:26 +0100274
275 if RunVim([], [], '-s XTest_conceal_curpos')
276 call assert_equal([
277 \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25',
278 \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25',
279 \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1',
280 \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out'))
281 endif
282
283 call delete('Xconceal_curpos.out')
Bram Moolenaar213ed002019-12-11 20:12:26 +0100284endfunc
285
Bram Moolenaarfc838d62020-06-25 22:23:48 +0200286func Test_conceal_eol()
287 new!
288 setlocal concealcursor=n conceallevel=1
289 call setline(1, ["x", ""])
290 call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1})
291 redraw!
292
293 call assert_notequal(screenchar(1, 1), screenchar(2, 2))
294 call assert_equal(screenattr(1, 1), screenattr(1, 2))
295 call assert_equal(screenattr(1, 2), screenattr(2, 2))
296 call assert_equal(screenattr(2, 1), screenattr(2, 2))
297
298 set list
299 redraw!
300
301 call assert_equal(screenattr(1, 1), screenattr(2, 2))
302 call assert_notequal(screenattr(1, 1), screenattr(1, 2))
303 call assert_notequal(screenattr(1, 2), screenattr(2, 1))
304
305 set nolist
306endfunc
307
Bram Moolenaarb9081882022-07-09 04:56:24 +0100308func Test_conceal_mouse_click()
309 enew!
310 set mouse=a
311 setlocal conceallevel=2 concealcursor=nc
312 syn match Concealed "this" conceal
313 hi link Concealed Search
314 call setline(1, 'conceal this click here')
315 redraw
316 call assert_equal(['conceal click here '], ScreenLines(1, 20))
317
318 " click on 'h' of "here" puts cursor there
319 call test_setmouse(1, 16)
320 call feedkeys("\<LeftMouse>", "tx")
321 call assert_equal([0, 1, 20, 0, 20], getcurpos())
322
323 bwipe!
324 set mouse&
325endfunc
326
Bram Moolenaar213ed002019-12-11 20:12:26 +0100327" vim: shiftwidth=2 sts=2 expandtab