blob: f5c8dc51e544f281f3bbbe30d54e9369489561bd [file] [log] [blame]
Bram Moolenaar62706602016-12-09 19:28:48 +01001" Test for displaying stuff
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Bram Moolenaar62706602016-12-09 19:28:48 +01003if !has('gui_running') && has('unix')
4 set term=ansi
5endif
6
Bram Moolenaarc6cd8402017-03-29 14:40:47 +02007source view_util.vim
Bram Moolenaar3c8ee622019-08-03 22:55:50 +02008source check.vim
9source screendump.vim
Bram Moolenaar62706602016-12-09 19:28:48 +010010
Bram Moolenaar1e115362019-01-09 23:01:02 +010011func Test_display_foldcolumn()
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020012 CheckFeature folding
13
Bram Moolenaar62706602016-12-09 19:28:48 +010014 new
15 vnew
16 vert resize 25
Bram Moolenaar70892372016-12-09 19:51:49 +010017 call assert_equal(25, winwidth(winnr()))
18 set isprint=@
Bram Moolenaar62706602016-12-09 19:28:48 +010019
20 1put='e more noise blah blah‚ more stuff here'
21
Bram Moolenaarc6cd8402017-03-29 14:40:47 +020022 let expect = [
23 \ "e more noise blah blah<82",
24 \ "> more stuff here "
25 \ ]
Bram Moolenaar62706602016-12-09 19:28:48 +010026
27 call cursor(2, 1)
28 norm! zt
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020029 let lines = ScreenLines([1,2], winwidth(0))
Bram Moolenaarc6cd8402017-03-29 14:40:47 +020030 call assert_equal(expect, lines)
Bram Moolenaar62706602016-12-09 19:28:48 +010031 set fdc=2
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020032 let lines = ScreenLines([1,2], winwidth(0))
Bram Moolenaarc6cd8402017-03-29 14:40:47 +020033 let expect = [
34 \ " e more noise blah blah<",
35 \ " 82> more stuff here "
36 \ ]
37 call assert_equal(expect, lines)
Bram Moolenaar62706602016-12-09 19:28:48 +010038
39 quit!
40 quit!
Bram Moolenaarc6cd8402017-03-29 14:40:47 +020041endfunc
42
Bram Moolenaar1e115362019-01-09 23:01:02 +010043func Test_display_foldtext_mbyte()
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020044 CheckFeature folding
45
Bram Moolenaarc6cd8402017-03-29 14:40:47 +020046 call NewWindow(10, 40)
47 call append(0, range(1,20))
48 exe "set foldmethod=manual foldtext=foldtext() fillchars=fold:\u2500,vert:\u2502 fdc=2"
49 call cursor(2, 1)
50 norm! zf13G
51 let lines=ScreenLines([1,3], winwidth(0)+1)
52 let expect=[
53 \ " 1 \u2502",
54 \ "+ +-- 12 lines: 2". repeat("\u2500", 23). "\u2502",
55 \ " 14 \u2502",
56 \ ]
57 call assert_equal(expect, lines)
Bram Moolenaar8da1e6c2017-03-29 20:38:59 +020058
59 set fillchars=fold:-,vert:\|
60 let lines=ScreenLines([1,3], winwidth(0)+1)
61 let expect=[
62 \ " 1 |",
63 \ "+ +-- 12 lines: 2". repeat("-", 23). "|",
64 \ " 14 |",
65 \ ]
66 call assert_equal(expect, lines)
67
Bram Moolenaarc6cd8402017-03-29 14:40:47 +020068 set foldtext& fillchars& foldmethod& fdc&
69 bw!
70endfunc
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020071
72" check that win_ins_lines() and win_del_lines() work when t_cs is empty.
73func Test_scroll_without_region()
74 CheckScreendump
75
76 let lines =<< trim END
77 call setline(1, range(1, 20))
78 set t_cs=
79 set laststatus=2
80 END
81 call writefile(lines, 'Xtestscroll')
82 let buf = RunVimInTerminal('-S Xtestscroll', #{rows: 10})
83
84 call VerifyScreenDump(buf, 'Test_scroll_no_region_1', {})
85
86 call term_sendkeys(buf, ":3delete\<cr>")
87 call VerifyScreenDump(buf, 'Test_scroll_no_region_2', {})
88
89 call term_sendkeys(buf, ":4put\<cr>")
90 call VerifyScreenDump(buf, 'Test_scroll_no_region_3', {})
91
Bram Moolenaar7cc53512019-08-03 23:30:21 +020092 call term_sendkeys(buf, ":undo\<cr>")
93 call term_sendkeys(buf, ":undo\<cr>")
94 call term_sendkeys(buf, ":set laststatus=0\<cr>")
95 call VerifyScreenDump(buf, 'Test_scroll_no_region_4', {})
96
97 call term_sendkeys(buf, ":3delete\<cr>")
98 call VerifyScreenDump(buf, 'Test_scroll_no_region_5', {})
99
100 call term_sendkeys(buf, ":4put\<cr>")
101 call VerifyScreenDump(buf, 'Test_scroll_no_region_6', {})
102
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200103 " clean up
104 call StopVimInTerminal(buf)
105 call delete('Xtestscroll')
106endfunc
Bram Moolenaarbffba7f2019-09-20 17:00:17 +0200107
108func Test_display_listchars_precedes()
109 call NewWindow(10, 10)
110 " Need a physical line that wraps over the complete
111 " window size
112 call append(0, repeat('aaa aaa aa ', 10))
113 call append(1, repeat(['bbb bbb bbb bbb'], 2))
114 " remove blank trailing line
115 $d
116 set list nowrap
117 call cursor(1, 1)
118 " move to end of line and scroll 2 characters back
119 norm! $2zh
120 let lines=ScreenLines([1,4], winwidth(0)+1)
121 let expect = [
122 \ " aaa aa $ |",
123 \ "$ |",
124 \ "$ |",
125 \ "~ |",
126 \ ]
127 call assert_equal(expect, lines)
128 set list listchars+=precedes:< nowrap
129 call cursor(1, 1)
130 " move to end of line and scroll 2 characters back
131 norm! $2zh
132 let lines = ScreenLines([1,4], winwidth(0)+1)
133 let expect = [
134 \ "<aaa aa $ |",
135 \ "< |",
136 \ "< |",
137 \ "~ |",
138 \ ]
139 call assert_equal(expect, lines)
140 set wrap
141 call cursor(1, 1)
142 " the complete line should be displayed in the window
143 norm! $
144
145 let lines = ScreenLines([1,10], winwidth(0)+1)
146 let expect = [
147 \ "<aaa aaa a|",
148 \ "a aaa aaa |",
149 \ "aa aaa aaa|",
150 \ " aa aaa aa|",
151 \ "a aa aaa a|",
152 \ "aa aa aaa |",
153 \ "aaa aa aaa|",
154 \ " aaa aa aa|",
155 \ "a aaa aa a|",
156 \ "aa aaa aa |",
157 \ ]
158 call assert_equal(expect, lines)
159 set list& listchars& wrap&
160 bw!
161endfunc
Bram Moolenaar28686682019-10-24 15:12:37 +0200162
163" Check that win_lines() works correctly with the number_only parameter=TRUE
164" should break early to optimize cost of drawing, but needs to make sure
165" that the number column is correctly highlighted.
166func Test_scroll_CursorLineNr_update()
167 CheckScreendump
168
169 let lines =<< trim END
170 hi CursorLineNr ctermfg=73 ctermbg=236
171 set nu rnu cursorline cursorlineopt=number
172 exe ":norm! o\<esc>110ia\<esc>"
173 END
174 let filename = 'Xdrawscreen'
175 call writefile(lines, filename)
176 let buf = RunVimInTerminal('-S '.filename, #{rows: 5, cols: 50})
177 call term_sendkeys(buf, "k")
Bram Moolenaar28686682019-10-24 15:12:37 +0200178 call VerifyScreenDump(buf, 'Test_winline_rnu', {})
179
180 " clean up
181 call StopVimInTerminal(buf)
182 call delete(filename)
183endfunc
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100184
185" check a long file name does not result in the hit-enter prompt
186func Test_edit_long_file_name()
187 CheckScreendump
188
Bram Moolenaar6e43b302019-12-14 17:53:27 +0100189 let longName = 'x'->repeat(min([&columns, 255]))
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100190 call writefile([], longName)
191 let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8})
192
193 call VerifyScreenDump(buf, 'Test_long_file_name_1', {})
194
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100195 " clean up
196 call StopVimInTerminal(buf)
197 call delete(longName)
198endfunc
199
Bram Moolenaar32ee6272020-06-10 14:16:49 +0200200func Test_unprintable_fileformats()
201 CheckScreendump
202
203 call writefile(["unix\r", "two"], 'Xunix.txt')
204 call writefile(["mac\r", "two"], 'Xmac.txt')
205 let lines =<< trim END
206 edit Xunix.txt
207 split Xmac.txt
208 edit ++ff=mac
209 END
210 let filename = 'Xunprintable'
211 call writefile(lines, filename)
212 let buf = RunVimInTerminal('-S '.filename, #{rows: 9, cols: 50})
213 call VerifyScreenDump(buf, 'Test_display_unprintable_01', {})
214 call term_sendkeys(buf, "\<C-W>\<C-W>\<C-L>")
215 call VerifyScreenDump(buf, 'Test_display_unprintable_02', {})
216
217 " clean up
218 call StopVimInTerminal(buf)
219 call delete('Xunix.txt')
220 call delete('Xmac.txt')
221 call delete(filename)
222endfunc
Bram Moolenaarf8992d42020-08-01 19:14:13 +0200223
224" Test for scrolling that modifies buffer during visual block
225func Test_visual_block_scroll()
226 CheckScreendump
227
228 let lines =<< trim END
229 source $VIMRUNTIME/plugin/matchparen.vim
230 set scrolloff=1
231 call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
232 call cursor(5, 1)
233 END
234
235 let filename = 'Xvisualblockmodifiedscroll'
236 call writefile(lines, filename)
237
238 let buf = RunVimInTerminal('-S '.filename, #{rows: 7})
239 call term_sendkeys(buf, "V\<C-D>\<C-D>")
240
241 call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {})
242
243 call StopVimInTerminal(buf)
244 call delete(filename)
245endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200246
Bram Moolenaar9dc19172020-08-19 20:19:48 +0200247func Test_display_scroll_at_topline()
248 CheckScreendump
249
250 let buf = RunVimInTerminal('', #{cols: 20})
251 call term_sendkeys(buf, ":call setline(1, repeat('a', 21))\<CR>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200252 call TermWait(buf)
Bram Moolenaar9dc19172020-08-19 20:19:48 +0200253 call term_sendkeys(buf, "O\<Esc>")
254 call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4})
255
256 call StopVimInTerminal(buf)
257endfunc
258
Bram Moolenaarabb6fbd2022-03-25 15:42:27 +0000259func Test_display_scroll_update_visual()
260 CheckScreendump
261
262 let lines =<< trim END
263 set scrolloff=0
264 call setline(1, repeat(['foo'], 10))
265 call sign_define('foo', { 'text': '>' })
266 call sign_place(1, 'bar', 'foo', bufnr(), { 'lnum': 2 })
267 call sign_place(2, 'bar', 'foo', bufnr(), { 'lnum': 1 })
268 autocmd CursorMoved * if getcurpos()[1] == 2 | call sign_unplace('bar', { 'id': 1 }) | endif
269 END
270 call writefile(lines, 'XupdateVisual.vim')
271
272 let buf = RunVimInTerminal('-S XupdateVisual.vim', #{rows: 8, cols: 60})
273 call term_sendkeys(buf, "VG7kk")
274 call VerifyScreenDump(buf, 'Test_display_scroll_update_visual', {})
275
276 call StopVimInTerminal(buf)
277 call delete('XupdateVisual.vim')
278endfunc
279
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100280" Test for 'eob' (EndOfBuffer) item in 'fillchars'
281func Test_eob_fillchars()
282 " default value
283 call assert_match('eob:\~', &fillchars)
284 " invalid values
285 call assert_fails(':set fillchars=eob:', 'E474:')
286 call assert_fails(':set fillchars=eob:xy', 'E474:')
287 call assert_fails(':set fillchars=eob:\255', 'E474:')
288 call assert_fails(':set fillchars=eob:<ff>', 'E474:')
zeertzjq60618c82021-12-18 15:32:46 +0000289 call assert_fails(":set fillchars=eob:\x01", 'E474:')
290 call assert_fails(':set fillchars=eob:\\x01', 'E474:')
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100291 " default is ~
292 new
Bram Moolenaar2cec0272021-03-22 17:30:47 +0100293 redraw
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100294 call assert_equal('~', Screenline(2))
295 set fillchars=eob:+
Bram Moolenaar2cec0272021-03-22 17:30:47 +0100296 redraw
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100297 call assert_equal('+', Screenline(2))
298 set fillchars=eob:\
Bram Moolenaar2cec0272021-03-22 17:30:47 +0100299 redraw
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100300 call assert_equal(' ', nr2char(screenchar(2, 1)))
301 set fillchars&
302 close
303endfunc
304
Bram Moolenaar3aca5a62021-02-17 13:14:07 +0100305" Test for 'foldopen', 'foldclose' and 'foldsep' in 'fillchars'
306func Test_fold_fillchars()
307 new
308 set fdc=2 foldenable foldmethod=manual
309 call setline(1, ['one', 'two', 'three', 'four', 'five'])
310 2,4fold
311 " First check for the default setting for a closed fold
312 let lines = ScreenLines([1, 3], 8)
313 let expected = [
314 \ ' one ',
315 \ '+ +-- 3',
316 \ ' five '
317 \ ]
318 call assert_equal(expected, lines)
319 normal 2Gzo
320 " check the characters for an open fold
321 let lines = ScreenLines([1, 5], 8)
322 let expected = [
323 \ ' one ',
324 \ '- two ',
325 \ '| three ',
326 \ '| four ',
327 \ ' five '
328 \ ]
329 call assert_equal(expected, lines)
330
331 " change the setting
332 set fillchars=vert:\|,fold:-,eob:~,foldopen:[,foldclose:],foldsep:-
333
334 " check the characters for an open fold
335 let lines = ScreenLines([1, 5], 8)
336 let expected = [
337 \ ' one ',
338 \ '[ two ',
339 \ '- three ',
340 \ '- four ',
341 \ ' five '
342 \ ]
343 call assert_equal(expected, lines)
344
345 " check the characters for a closed fold
346 normal 2Gzc
347 let lines = ScreenLines([1, 3], 8)
348 let expected = [
349 \ ' one ',
350 \ '] +-- 3',
351 \ ' five '
352 \ ]
353 call assert_equal(expected, lines)
354
355 %bw!
356 set fillchars& fdc& foldmethod& foldenable&
357endfunc
358
Bram Moolenaara06e3452021-05-29 17:56:37 +0200359func Test_display_linebreak_breakat()
360 new
361 vert resize 25
362 let _breakat = &breakat
363 setl signcolumn=yes linebreak breakat=) showbreak=+\
364 call setline(1, repeat('x', winwidth(0) - 2) .. ')abc')
365 let lines = ScreenLines([1, 2], 25)
366 let expected = [
367 \ ' xxxxxxxxxxxxxxxxxxxxxxx',
368 \ ' + )abc '
369 \ ]
370 call assert_equal(expected, lines)
371 %bw!
372 let &breakat=_breakat
373endfunc
374
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100375func Test_display_lastline()
376 CheckScreendump
377
378 let lines =<< trim END
379 call setline(1, ['aaa', 'b'->repeat(100)])
380 set display=truncate
381 vsplit
382 100wincmd <
383 END
384 call writefile(lines, 'XdispLastline')
385 let buf = RunVimInTerminal('-S XdispLastline', #{rows: 10})
386 call VerifyScreenDump(buf, 'Test_display_lastline_1', {})
387
388 call term_sendkeys(buf, ":set display=lastline\<CR>")
389 call VerifyScreenDump(buf, 'Test_display_lastline_2', {})
390
391 call term_sendkeys(buf, ":100wincmd >\<CR>")
392 call VerifyScreenDump(buf, 'Test_display_lastline_3', {})
393
394 call term_sendkeys(buf, ":set display=truncate\<CR>")
395 call VerifyScreenDump(buf, 'Test_display_lastline_4', {})
396
397 call StopVimInTerminal(buf)
398 call delete('XdispLastline')
399endfunc
400
Bram Moolenaara06e3452021-05-29 17:56:37 +0200401
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200402" vim: shiftwidth=2 sts=2 expandtab