blob: ad11eb721eb1ad5678a51d6e053f6f02dbbbd124 [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 Moolenaar429ab172019-01-11 15:54:45 +01007
8func Test_conceal_two_windows()
zeertzjq20691912022-01-23 12:42:55 +00009 CheckScreendump
10
Bram Moolenaarc79745a2019-05-20 22:12:34 +020011 let code =<< trim [CODE]
12 let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
13 call setline(1, lines)
14 syntax match test /|hidden|/ conceal
15 set conceallevel=2
16 set concealcursor=
17 exe "normal /here\r"
18 new
19 call setline(1, lines)
20 call setline(4, "Second window")
21 syntax match test /|hidden|/ conceal
22 set conceallevel=2
23 set concealcursor=nc
24 exe "normal /here\r"
25 [CODE]
26
27 call writefile(code, 'XTest_conceal')
Bram Moolenaar429ab172019-01-11 15:54:45 +010028 " Check that cursor line is concealed
29 let buf = RunVimInTerminal('-S XTest_conceal', {})
30 call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {})
31
32 " Check that with concealed text vertical cursor movement is correct.
33 call term_sendkeys(buf, "k")
34 call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {})
35
36 " Check that with cursor line is not concealed
37 call term_sendkeys(buf, "j")
38 call term_sendkeys(buf, ":set concealcursor=\r")
39 call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {})
40
41 " Check that with cursor line is not concealed when moving cursor down
42 call term_sendkeys(buf, "j")
43 call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {})
44
45 " Check that with cursor line is not concealed when switching windows
46 call term_sendkeys(buf, "\<C-W>\<C-W>")
47 call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {})
48
49 " Check that with cursor line is only concealed in Normal mode
50 call term_sendkeys(buf, ":set concealcursor=n\r")
51 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {})
52 call term_sendkeys(buf, "a")
53 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {})
54 call term_sendkeys(buf, "\<Esc>/e")
55 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {})
56 call term_sendkeys(buf, "\<Esc>v")
57 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {})
58 call term_sendkeys(buf, "\<Esc>")
59
60 " Check that with cursor line is only concealed in Insert mode
61 call term_sendkeys(buf, ":set concealcursor=i\r")
62 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {})
Bram Moolenaar644b49f2021-09-16 22:32:15 +020063 call term_sendkeys(buf, "14|a")
Bram Moolenaar429ab172019-01-11 15:54:45 +010064 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {})
Bram Moolenaar644b49f2021-09-16 22:32:15 +020065 call term_sendkeys(buf, "\<Esc>")
66 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07in', {})
67 call term_sendkeys(buf, "/e")
Bram Moolenaar429ab172019-01-11 15:54:45 +010068 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {})
69 call term_sendkeys(buf, "\<Esc>v")
70 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {})
71 call term_sendkeys(buf, "\<Esc>")
72
73 " Check that with cursor line is only concealed in Command mode
74 call term_sendkeys(buf, ":set concealcursor=c\r")
75 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {})
76 call term_sendkeys(buf, "a")
77 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {})
78 call term_sendkeys(buf, "\<Esc>/e")
79 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {})
80 call term_sendkeys(buf, "\<Esc>v")
81 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {})
82 call term_sendkeys(buf, "\<Esc>")
83
84 " Check that with cursor line is only concealed in Visual mode
85 call term_sendkeys(buf, ":set concealcursor=v\r")
86 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {})
87 call term_sendkeys(buf, "a")
88 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {})
89 call term_sendkeys(buf, "\<Esc>/e")
90 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {})
91 call term_sendkeys(buf, "\<Esc>v")
92 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {})
93 call term_sendkeys(buf, "\<Esc>")
94
Bram Moolenaar465e8b52019-01-11 20:42:28 +010095 " Check moving the cursor while in insert mode.
96 call term_sendkeys(buf, ":set concealcursor=\r")
97 call term_sendkeys(buf, "a")
98 call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {})
99 call term_sendkeys(buf, "\<Down>")
100 call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {})
101 call term_sendkeys(buf, "\<Esc>")
102
103 " Check the "o" command
104 call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {})
105 call term_sendkeys(buf, "o")
106 call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {})
107 call term_sendkeys(buf, "\<Esc>")
108
Bram Moolenaar429ab172019-01-11 15:54:45 +0100109 " clean up
110 call StopVimInTerminal(buf)
111 call delete('XTest_conceal')
112endfunc
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
128 call writefile(code, 'XTest_conceal_cul')
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)
140 call delete('XTest_conceal_cul')
141endfunc
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200142
143func Test_conceal_resize_term()
zeertzjq20691912022-01-23 12:42:55 +0000144 CheckScreendump
145
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200146 let code =<< trim [CODE]
147 call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
148 setl cocu=n cole=3
149 syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
150 normal fb
151 [CODE]
152 call writefile(code, 'XTest_conceal_resize')
153 let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
154 call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
155
156 call win_execute(buf->win_findbuf()[0], 'wincmd +')
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200157 call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
158
159 " clean up
160 call StopVimInTerminal(buf)
161 call delete('XTest_conceal_resize')
162endfunc
Bram Moolenaar213ed002019-12-11 20:12:26 +0100163
164" Tests for correct display (cursor column position) with +conceal and
165" tabulators. Need to run this test in a separate Vim instance. Otherwise the
166" screen is not updated (lazy redraw) and the cursor position is wrong.
167func Test_conceal_cursor_pos()
168 let code =<< trim [CODE]
169 :let l = ['start:', '.concealed. text', "|concealed|\ttext"]
170 :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
171 :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
172 :call append(0, l)
173 :call cursor(1, 1)
174 :" Conceal settings.
175 :set conceallevel=2
176 :set concealcursor=nc
177 :syntax match test /|/ conceal
178 :" Save current cursor position. Only works in <expr> mode, can't be used
179 :" with :normal because it moves the cursor to the command line. Thanks
180 :" to ZyX <zyx.vim@gmail.com> for the idea to use an <expr> mapping.
181 :let curpos = []
182 :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n"
183 :normal ztj
184 GGk
185 :" We should end up in the same column when running these commands on the
186 :" two lines.
187 :normal ft
188 GGk
189 :normal $
190 GGk
191 :normal 0j
192 GGk
193 :normal ft
194 GGk
195 :normal $
196 GGk
197 :normal 0j0j
198 GGk
199 :" Same for next test block.
200 :normal ft
201 GGk
202 :normal $
203 GGk
204 :normal 0j
205 GGk
206 :normal ft
207 GGk
208 :normal $
209 GGk
210 :normal 0j0j
211 GGk
212 :" And check W with multiple tabs and conceals in a line.
213 :normal W
214 GGk
215 :normal W
216 GGk
217 :normal W
218 GGk
219 :normal $
220 GGk
221 :normal 0j
222 GGk
223 :normal W
224 GGk
225 :normal W
226 GGk
227 :normal W
228 GGk
229 :normal $
230 GGk
231 :set lbr
232 :normal $
233 GGk
234 :set list listchars=tab:>-
235 :normal 0
236 GGk
237 :normal W
238 GGk
239 :normal W
240 GGk
241 :normal W
242 GGk
243 :normal $
244 GGk
245 :call writefile(curpos, 'Xconceal_curpos.out')
246 :q!
247
248 [CODE]
249 call writefile(code, 'XTest_conceal_curpos')
250
251 if RunVim([], [], '-s XTest_conceal_curpos')
252 call assert_equal([
253 \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25',
254 \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25',
255 \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1',
256 \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out'))
257 endif
258
259 call delete('Xconceal_curpos.out')
260 call delete('XTest_conceal_curpos')
261endfunc
262
Bram Moolenaarfc838d62020-06-25 22:23:48 +0200263func Test_conceal_eol()
264 new!
265 setlocal concealcursor=n conceallevel=1
266 call setline(1, ["x", ""])
267 call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1})
268 redraw!
269
270 call assert_notequal(screenchar(1, 1), screenchar(2, 2))
271 call assert_equal(screenattr(1, 1), screenattr(1, 2))
272 call assert_equal(screenattr(1, 2), screenattr(2, 2))
273 call assert_equal(screenattr(2, 1), screenattr(2, 2))
274
275 set list
276 redraw!
277
278 call assert_equal(screenattr(1, 1), screenattr(2, 2))
279 call assert_notequal(screenattr(1, 1), screenattr(1, 2))
280 call assert_notequal(screenattr(1, 2), screenattr(2, 1))
281
282 set nolist
283endfunc
284
Bram Moolenaar213ed002019-12-11 20:12:26 +0100285" vim: shiftwidth=2 sts=2 expandtab