xref: /vim-8.2.3635/src/testdir/test_conceal.vim (revision 2e693a88)
1" Tests for 'conceal'.
2" Also see test88.in (should be converted to a test function here).
3
4source check.vim
5CheckFeature conceal
6
7source screendump.vim
8CheckScreendump
9
10func Test_conceal_two_windows()
11  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')
28  " 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', {})
63  call term_sendkeys(buf, "a")
64  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {})
65  call term_sendkeys(buf, "\<Esc>/e")
66  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {})
67  call term_sendkeys(buf, "\<Esc>v")
68  call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {})
69  call term_sendkeys(buf, "\<Esc>")
70
71  " Check that with cursor line is only concealed in Command mode
72  call term_sendkeys(buf, ":set concealcursor=c\r")
73  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {})
74  call term_sendkeys(buf, "a")
75  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {})
76  call term_sendkeys(buf, "\<Esc>/e")
77  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {})
78  call term_sendkeys(buf, "\<Esc>v")
79  call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {})
80  call term_sendkeys(buf, "\<Esc>")
81
82  " Check that with cursor line is only concealed in Visual mode
83  call term_sendkeys(buf, ":set concealcursor=v\r")
84  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {})
85  call term_sendkeys(buf, "a")
86  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {})
87  call term_sendkeys(buf, "\<Esc>/e")
88  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {})
89  call term_sendkeys(buf, "\<Esc>v")
90  call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {})
91  call term_sendkeys(buf, "\<Esc>")
92
93  " Check moving the cursor while in insert mode.
94  call term_sendkeys(buf, ":set concealcursor=\r")
95  call term_sendkeys(buf, "a")
96  call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {})
97  call term_sendkeys(buf, "\<Down>")
98  call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {})
99  call term_sendkeys(buf, "\<Esc>")
100
101  " Check the "o" command
102  call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {})
103  call term_sendkeys(buf, "o")
104  call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {})
105  call term_sendkeys(buf, "\<Esc>")
106
107  " clean up
108  call StopVimInTerminal(buf)
109  call delete('XTest_conceal')
110endfunc
111
112func Test_conceal_with_cursorline()
113  " Opens a help window, where 'conceal' is set, switches to the other window
114  " where 'cursorline' needs to be updated when the cursor moves.
115  let code =<< trim [CODE]
116    set cursorline
117    normal othis is a test
118    new
119    call setline(1, ["one", "two", "three", "four", "five"])
120    set ft=help
121    normal M
122  [CODE]
123
124  call writefile(code, 'XTest_conceal_cul')
125  let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
126  call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
127
128  call term_sendkeys(buf, ":wincmd w\r")
129  call VerifyScreenDump(buf, 'Test_conceal_cul_02', {})
130
131  call term_sendkeys(buf, "k")
132  call VerifyScreenDump(buf, 'Test_conceal_cul_03', {})
133
134  " clean up
135  call StopVimInTerminal(buf)
136  call delete('XTest_conceal_cul')
137endfunc
138
139func Test_conceal_resize_term()
140  let code =<< trim [CODE]
141    call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
142    setl cocu=n cole=3
143    syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
144    normal fb
145  [CODE]
146  call writefile(code, 'XTest_conceal_resize')
147  let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
148  call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
149
150  call win_execute(buf->win_findbuf()[0], 'wincmd +')
151  call term_wait(buf)
152  call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
153
154  " clean up
155  call StopVimInTerminal(buf)
156  call delete('XTest_conceal_resize')
157endfunc
158