xref: /vim-8.2.3635/src/testdir/test_conceal.vim (revision 81ea1dfb)
1" Tests for 'conceal'.
2
3source check.vim
4CheckFeature conceal
5
6source screendump.vim
7CheckScreendump
8
9func Test_conceal_two_windows()
10  let code =<< trim [CODE]
11    let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
12    call setline(1, lines)
13    syntax match test /|hidden|/ conceal
14    set conceallevel=2
15    set concealcursor=
16    exe "normal /here\r"
17    new
18    call setline(1, lines)
19    call setline(4, "Second window")
20    syntax match test /|hidden|/ conceal
21    set conceallevel=2
22    set concealcursor=nc
23    exe "normal /here\r"
24  [CODE]
25
26  call writefile(code, 'XTest_conceal')
27  " Check that cursor line is concealed
28  let buf = RunVimInTerminal('-S XTest_conceal', {})
29  call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {})
30
31  " Check that with concealed text vertical cursor movement is correct.
32  call term_sendkeys(buf, "k")
33  call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {})
34
35  " Check that with cursor line is not concealed
36  call term_sendkeys(buf, "j")
37  call term_sendkeys(buf, ":set concealcursor=\r")
38  call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {})
39
40  " Check that with cursor line is not concealed when moving cursor down
41  call term_sendkeys(buf, "j")
42  call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {})
43
44  " Check that with cursor line is not concealed when switching windows
45  call term_sendkeys(buf, "\<C-W>\<C-W>")
46  call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {})
47
48  " Check that with cursor line is only concealed in Normal mode
49  call term_sendkeys(buf, ":set concealcursor=n\r")
50  call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {})
51  call term_sendkeys(buf, "a")
52  call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {})
53  call term_sendkeys(buf, "\<Esc>/e")
54  call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {})
55  call term_sendkeys(buf, "\<Esc>v")
56  call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {})
57  call term_sendkeys(buf, "\<Esc>")
58
59  " Check that with cursor line is only concealed in Insert mode
60  call term_sendkeys(buf, ":set concealcursor=i\r")
61  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {})
62  call term_sendkeys(buf, "a")
63  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {})
64  call term_sendkeys(buf, "\<Esc>/e")
65  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {})
66  call term_sendkeys(buf, "\<Esc>v")
67  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {})
68  call term_sendkeys(buf, "\<Esc>")
69
70  " Check that with cursor line is only concealed in Command mode
71  call term_sendkeys(buf, ":set concealcursor=c\r")
72  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {})
73  call term_sendkeys(buf, "a")
74  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {})
75  call term_sendkeys(buf, "\<Esc>/e")
76  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {})
77  call term_sendkeys(buf, "\<Esc>v")
78  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {})
79  call term_sendkeys(buf, "\<Esc>")
80
81  " Check that with cursor line is only concealed in Visual mode
82  call term_sendkeys(buf, ":set concealcursor=v\r")
83  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {})
84  call term_sendkeys(buf, "a")
85  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {})
86  call term_sendkeys(buf, "\<Esc>/e")
87  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {})
88  call term_sendkeys(buf, "\<Esc>v")
89  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {})
90  call term_sendkeys(buf, "\<Esc>")
91
92  " Check moving the cursor while in insert mode.
93  call term_sendkeys(buf, ":set concealcursor=\r")
94  call term_sendkeys(buf, "a")
95  call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {})
96  call term_sendkeys(buf, "\<Down>")
97  call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {})
98  call term_sendkeys(buf, "\<Esc>")
99
100  " Check the "o" command
101  call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {})
102  call term_sendkeys(buf, "o")
103  call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {})
104  call term_sendkeys(buf, "\<Esc>")
105
106  " clean up
107  call StopVimInTerminal(buf)
108  call delete('XTest_conceal')
109endfunc
110
111func Test_conceal_with_cursorline()
112  " Opens a help window, where 'conceal' is set, switches to the other window
113  " where 'cursorline' needs to be updated when the cursor moves.
114  let code =<< trim [CODE]
115    set cursorline
116    normal othis is a test
117    new
118    call setline(1, ["one", "two", "three", "four", "five"])
119    set ft=help
120    normal M
121  [CODE]
122
123  call writefile(code, 'XTest_conceal_cul')
124  let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
125  call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
126
127  call term_sendkeys(buf, ":wincmd w\r")
128  call VerifyScreenDump(buf, 'Test_conceal_cul_02', {})
129
130  call term_sendkeys(buf, "k")
131  call VerifyScreenDump(buf, 'Test_conceal_cul_03', {})
132
133  " clean up
134  call StopVimInTerminal(buf)
135  call delete('XTest_conceal_cul')
136endfunc
137
138func Test_conceal_resize_term()
139  let code =<< trim [CODE]
140    call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
141    setl cocu=n cole=3
142    syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
143    normal fb
144  [CODE]
145  call writefile(code, 'XTest_conceal_resize')
146  let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
147  call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
148
149  call win_execute(buf->win_findbuf()[0], 'wincmd +')
150  call TermWait(buf)
151  call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
152
153  " clean up
154  call StopVimInTerminal(buf)
155  call delete('XTest_conceal_resize')
156endfunc
157
158" Tests for correct display (cursor column position) with +conceal and
159" tabulators.  Need to run this test in a separate Vim instance. Otherwise the
160" screen is not updated (lazy redraw) and the cursor position is wrong.
161func Test_conceal_cursor_pos()
162  let code =<< trim [CODE]
163    :let l = ['start:', '.concealed.     text', "|concealed|\ttext"]
164    :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
165    :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
166    :call append(0, l)
167    :call cursor(1, 1)
168    :" Conceal settings.
169    :set conceallevel=2
170    :set concealcursor=nc
171    :syntax match test /|/ conceal
172    :" Save current cursor position. Only works in <expr> mode, can't be used
173    :" with :normal because it moves the cursor to the command line. Thanks
174    :" to ZyX <[email protected]> for the idea to use an <expr> mapping.
175    :let curpos = []
176    :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n"
177    :normal ztj
178    GGk
179    :" We should end up in the same column when running these commands on the
180    :" two lines.
181    :normal ft
182    GGk
183    :normal $
184    GGk
185    :normal 0j
186    GGk
187    :normal ft
188    GGk
189    :normal $
190    GGk
191    :normal 0j0j
192    GGk
193    :" Same for next test block.
194    :normal ft
195    GGk
196    :normal $
197    GGk
198    :normal 0j
199    GGk
200    :normal ft
201    GGk
202    :normal $
203    GGk
204    :normal 0j0j
205    GGk
206    :" And check W with multiple tabs and conceals in a line.
207    :normal W
208    GGk
209    :normal W
210    GGk
211    :normal W
212    GGk
213    :normal $
214    GGk
215    :normal 0j
216    GGk
217    :normal W
218    GGk
219    :normal W
220    GGk
221    :normal W
222    GGk
223    :normal $
224    GGk
225    :set lbr
226    :normal $
227    GGk
228    :set list listchars=tab:>-
229    :normal 0
230    GGk
231    :normal W
232    GGk
233    :normal W
234    GGk
235    :normal W
236    GGk
237    :normal $
238    GGk
239    :call writefile(curpos, 'Xconceal_curpos.out')
240    :q!
241
242  [CODE]
243  call writefile(code, 'XTest_conceal_curpos')
244
245  if RunVim([], [], '-s XTest_conceal_curpos')
246    call assert_equal([
247          \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25',
248          \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25',
249          \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1',
250          \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out'))
251  endif
252
253  call delete('Xconceal_curpos.out')
254  call delete('XTest_conceal_curpos')
255endfunc
256
257" vim: shiftwidth=2 sts=2 expandtab
258