blob: c0a46dc6b7e86a12546452cbe43fe11d8491a533 [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
162" Tests for correct display (cursor column position) with +conceal and
163" tabulators. Need to run this test in a separate Vim instance. Otherwise the
164" screen is not updated (lazy redraw) and the cursor position is wrong.
165func Test_conceal_cursor_pos()
166 let code =<< trim [CODE]
167 :let l = ['start:', '.concealed. text', "|concealed|\ttext"]
168 :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
169 :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
170 :call append(0, l)
171 :call cursor(1, 1)
172 :" Conceal settings.
173 :set conceallevel=2
174 :set concealcursor=nc
175 :syntax match test /|/ conceal
176 :" Save current cursor position. Only works in <expr> mode, can't be used
177 :" with :normal because it moves the cursor to the command line. Thanks
178 :" to ZyX <zyx.vim@gmail.com> for the idea to use an <expr> mapping.
179 :let curpos = []
180 :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n"
181 :normal ztj
182 GGk
183 :" We should end up in the same column when running these commands on the
184 :" two lines.
185 :normal ft
186 GGk
187 :normal $
188 GGk
189 :normal 0j
190 GGk
191 :normal ft
192 GGk
193 :normal $
194 GGk
195 :normal 0j0j
196 GGk
197 :" Same for next test block.
198 :normal ft
199 GGk
200 :normal $
201 GGk
202 :normal 0j
203 GGk
204 :normal ft
205 GGk
206 :normal $
207 GGk
208 :normal 0j0j
209 GGk
210 :" And check W with multiple tabs and conceals in a line.
211 :normal W
212 GGk
213 :normal W
214 GGk
215 :normal W
216 GGk
217 :normal $
218 GGk
219 :normal 0j
220 GGk
221 :normal W
222 GGk
223 :normal W
224 GGk
225 :normal W
226 GGk
227 :normal $
228 GGk
229 :set lbr
230 :normal $
231 GGk
232 :set list listchars=tab:>-
233 :normal 0
234 GGk
235 :normal W
236 GGk
237 :normal W
238 GGk
239 :normal W
240 GGk
241 :normal $
242 GGk
243 :call writefile(curpos, 'Xconceal_curpos.out')
244 :q!
245
246 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100247 call writefile(code, 'XTest_conceal_curpos', 'D')
Bram Moolenaar213ed002019-12-11 20:12:26 +0100248
249 if RunVim([], [], '-s XTest_conceal_curpos')
250 call assert_equal([
251 \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25',
252 \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25',
253 \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1',
254 \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out'))
255 endif
256
257 call delete('Xconceal_curpos.out')
Bram Moolenaar213ed002019-12-11 20:12:26 +0100258endfunc
259
Bram Moolenaarfc838d62020-06-25 22:23:48 +0200260func Test_conceal_eol()
261 new!
262 setlocal concealcursor=n conceallevel=1
263 call setline(1, ["x", ""])
264 call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1})
265 redraw!
266
267 call assert_notequal(screenchar(1, 1), screenchar(2, 2))
268 call assert_equal(screenattr(1, 1), screenattr(1, 2))
269 call assert_equal(screenattr(1, 2), screenattr(2, 2))
270 call assert_equal(screenattr(2, 1), screenattr(2, 2))
271
272 set list
273 redraw!
274
275 call assert_equal(screenattr(1, 1), screenattr(2, 2))
276 call assert_notequal(screenattr(1, 1), screenattr(1, 2))
277 call assert_notequal(screenattr(1, 2), screenattr(2, 1))
278
279 set nolist
280endfunc
281
Bram Moolenaarb9081882022-07-09 04:56:24 +0100282func Test_conceal_mouse_click()
283 enew!
284 set mouse=a
285 setlocal conceallevel=2 concealcursor=nc
286 syn match Concealed "this" conceal
287 hi link Concealed Search
288 call setline(1, 'conceal this click here')
289 redraw
290 call assert_equal(['conceal click here '], ScreenLines(1, 20))
291
292 " click on 'h' of "here" puts cursor there
293 call test_setmouse(1, 16)
294 call feedkeys("\<LeftMouse>", "tx")
295 call assert_equal([0, 1, 20, 0, 20], getcurpos())
296
297 bwipe!
298 set mouse&
299endfunc
300
Bram Moolenaar213ed002019-12-11 20:12:26 +0100301" vim: shiftwidth=2 sts=2 expandtab