blob: 4d2ee9f202867218c46ea55fcd60574376147906 [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
Bram Moolenaar59173412022-09-20 22:01:33 +010081 call writefile(lines, 'Xtestscroll', 'D')
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020082 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)
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200105endfunc
Bram Moolenaarbffba7f2019-09-20 17:00:17 +0200106
107func Test_display_listchars_precedes()
108 call NewWindow(10, 10)
109 " Need a physical line that wraps over the complete
110 " window size
111 call append(0, repeat('aaa aaa aa ', 10))
112 call append(1, repeat(['bbb bbb bbb bbb'], 2))
113 " remove blank trailing line
114 $d
115 set list nowrap
116 call cursor(1, 1)
117 " move to end of line and scroll 2 characters back
118 norm! $2zh
119 let lines=ScreenLines([1,4], winwidth(0)+1)
120 let expect = [
121 \ " aaa aa $ |",
122 \ "$ |",
123 \ "$ |",
124 \ "~ |",
125 \ ]
126 call assert_equal(expect, lines)
127 set list listchars+=precedes:< nowrap
128 call cursor(1, 1)
129 " move to end of line and scroll 2 characters back
130 norm! $2zh
131 let lines = ScreenLines([1,4], winwidth(0)+1)
132 let expect = [
133 \ "<aaa aa $ |",
134 \ "< |",
135 \ "< |",
136 \ "~ |",
137 \ ]
138 call assert_equal(expect, lines)
139 set wrap
140 call cursor(1, 1)
141 " the complete line should be displayed in the window
142 norm! $
143
144 let lines = ScreenLines([1,10], winwidth(0)+1)
145 let expect = [
Bram Moolenaar0466d392022-10-03 17:07:34 +0100146 \ "<<<a aaa a|",
Bram Moolenaarbffba7f2019-09-20 17:00:17 +0200147 \ "a aaa aaa |",
148 \ "aa aaa aaa|",
149 \ " aa aaa aa|",
150 \ "a aa aaa a|",
151 \ "aa aa aaa |",
152 \ "aaa aa aaa|",
153 \ " aaa aa aa|",
154 \ "a aaa aa a|",
155 \ "aa aaa aa |",
156 \ ]
157 call assert_equal(expect, lines)
158 set list& listchars& wrap&
159 bw!
160endfunc
Bram Moolenaar28686682019-10-24 15:12:37 +0200161
162" Check that win_lines() works correctly with the number_only parameter=TRUE
163" should break early to optimize cost of drawing, but needs to make sure
164" that the number column is correctly highlighted.
165func Test_scroll_CursorLineNr_update()
166 CheckScreendump
167
168 let lines =<< trim END
169 hi CursorLineNr ctermfg=73 ctermbg=236
170 set nu rnu cursorline cursorlineopt=number
171 exe ":norm! o\<esc>110ia\<esc>"
172 END
173 let filename = 'Xdrawscreen'
Bram Moolenaar59173412022-09-20 22:01:33 +0100174 call writefile(lines, filename, 'D')
Bram Moolenaar28686682019-10-24 15:12:37 +0200175 let buf = RunVimInTerminal('-S '.filename, #{rows: 5, cols: 50})
176 call term_sendkeys(buf, "k")
Bram Moolenaar28686682019-10-24 15:12:37 +0200177 call VerifyScreenDump(buf, 'Test_winline_rnu', {})
178
179 " clean up
180 call StopVimInTerminal(buf)
Bram Moolenaar28686682019-10-24 15:12:37 +0200181endfunc
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100182
183" check a long file name does not result in the hit-enter prompt
184func Test_edit_long_file_name()
185 CheckScreendump
186
Bram Moolenaar6e43b302019-12-14 17:53:27 +0100187 let longName = 'x'->repeat(min([&columns, 255]))
Bram Moolenaar59173412022-09-20 22:01:33 +0100188 call writefile([], longName, 'D')
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100189 let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8})
190
191 call VerifyScreenDump(buf, 'Test_long_file_name_1', {})
192
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100193 " clean up
194 call StopVimInTerminal(buf)
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100195endfunc
196
Bram Moolenaar32ee6272020-06-10 14:16:49 +0200197func Test_unprintable_fileformats()
198 CheckScreendump
199
Bram Moolenaar59173412022-09-20 22:01:33 +0100200 call writefile(["unix\r", "two"], 'Xunix.txt', 'D')
201 call writefile(["mac\r", "two"], 'Xmac.txt', 'D')
Bram Moolenaar32ee6272020-06-10 14:16:49 +0200202 let lines =<< trim END
203 edit Xunix.txt
204 split Xmac.txt
205 edit ++ff=mac
206 END
207 let filename = 'Xunprintable'
Bram Moolenaar59173412022-09-20 22:01:33 +0100208 call writefile(lines, filename, 'D')
Bram Moolenaar32ee6272020-06-10 14:16:49 +0200209 let buf = RunVimInTerminal('-S '.filename, #{rows: 9, cols: 50})
210 call VerifyScreenDump(buf, 'Test_display_unprintable_01', {})
211 call term_sendkeys(buf, "\<C-W>\<C-W>\<C-L>")
212 call VerifyScreenDump(buf, 'Test_display_unprintable_02', {})
213
214 " clean up
215 call StopVimInTerminal(buf)
Bram Moolenaar32ee6272020-06-10 14:16:49 +0200216endfunc
Bram Moolenaarf8992d42020-08-01 19:14:13 +0200217
218" Test for scrolling that modifies buffer during visual block
219func Test_visual_block_scroll()
220 CheckScreendump
221
222 let lines =<< trim END
223 source $VIMRUNTIME/plugin/matchparen.vim
224 set scrolloff=1
225 call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
226 call cursor(5, 1)
227 END
228
229 let filename = 'Xvisualblockmodifiedscroll'
Bram Moolenaar59173412022-09-20 22:01:33 +0100230 call writefile(lines, filename, 'D')
Bram Moolenaarf8992d42020-08-01 19:14:13 +0200231
232 let buf = RunVimInTerminal('-S '.filename, #{rows: 7})
233 call term_sendkeys(buf, "V\<C-D>\<C-D>")
234
235 call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {})
236
237 call StopVimInTerminal(buf)
Bram Moolenaarf8992d42020-08-01 19:14:13 +0200238endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200239
Bram Moolenaar9dc19172020-08-19 20:19:48 +0200240func Test_display_scroll_at_topline()
241 CheckScreendump
242
243 let buf = RunVimInTerminal('', #{cols: 20})
244 call term_sendkeys(buf, ":call setline(1, repeat('a', 21))\<CR>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200245 call TermWait(buf)
Bram Moolenaar9dc19172020-08-19 20:19:48 +0200246 call term_sendkeys(buf, "O\<Esc>")
247 call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4})
248
249 call StopVimInTerminal(buf)
250endfunc
251
Bram Moolenaarabb6fbd2022-03-25 15:42:27 +0000252func Test_display_scroll_update_visual()
253 CheckScreendump
254
255 let lines =<< trim END
256 set scrolloff=0
257 call setline(1, repeat(['foo'], 10))
258 call sign_define('foo', { 'text': '>' })
259 call sign_place(1, 'bar', 'foo', bufnr(), { 'lnum': 2 })
260 call sign_place(2, 'bar', 'foo', bufnr(), { 'lnum': 1 })
261 autocmd CursorMoved * if getcurpos()[1] == 2 | call sign_unplace('bar', { 'id': 1 }) | endif
262 END
Bram Moolenaar59173412022-09-20 22:01:33 +0100263 call writefile(lines, 'XupdateVisual.vim', 'D')
Bram Moolenaarabb6fbd2022-03-25 15:42:27 +0000264
265 let buf = RunVimInTerminal('-S XupdateVisual.vim', #{rows: 8, cols: 60})
266 call term_sendkeys(buf, "VG7kk")
267 call VerifyScreenDump(buf, 'Test_display_scroll_update_visual', {})
268
269 call StopVimInTerminal(buf)
Bram Moolenaarabb6fbd2022-03-25 15:42:27 +0000270endfunc
271
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100272" Test for 'eob' (EndOfBuffer) item in 'fillchars'
273func Test_eob_fillchars()
274 " default value
275 call assert_match('eob:\~', &fillchars)
276 " invalid values
277 call assert_fails(':set fillchars=eob:', 'E474:')
278 call assert_fails(':set fillchars=eob:xy', 'E474:')
279 call assert_fails(':set fillchars=eob:\255', 'E474:')
280 call assert_fails(':set fillchars=eob:<ff>', 'E474:')
zeertzjq60618c82021-12-18 15:32:46 +0000281 call assert_fails(":set fillchars=eob:\x01", 'E474:')
282 call assert_fails(':set fillchars=eob:\\x01', 'E474:')
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100283 " default is ~
284 new
Bram Moolenaar2cec0272021-03-22 17:30:47 +0100285 redraw
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100286 call assert_equal('~', Screenline(2))
287 set fillchars=eob:+
Bram Moolenaar2cec0272021-03-22 17:30:47 +0100288 redraw
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100289 call assert_equal('+', Screenline(2))
290 set fillchars=eob:\
Bram Moolenaar2cec0272021-03-22 17:30:47 +0100291 redraw
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100292 call assert_equal(' ', nr2char(screenchar(2, 1)))
293 set fillchars&
294 close
295endfunc
296
Bram Moolenaar3aca5a62021-02-17 13:14:07 +0100297" Test for 'foldopen', 'foldclose' and 'foldsep' in 'fillchars'
298func Test_fold_fillchars()
299 new
300 set fdc=2 foldenable foldmethod=manual
301 call setline(1, ['one', 'two', 'three', 'four', 'five'])
302 2,4fold
303 " First check for the default setting for a closed fold
304 let lines = ScreenLines([1, 3], 8)
305 let expected = [
306 \ ' one ',
307 \ '+ +-- 3',
308 \ ' five '
309 \ ]
310 call assert_equal(expected, lines)
311 normal 2Gzo
312 " check the characters for an open fold
313 let lines = ScreenLines([1, 5], 8)
314 let expected = [
315 \ ' one ',
316 \ '- two ',
317 \ '| three ',
318 \ '| four ',
319 \ ' five '
320 \ ]
321 call assert_equal(expected, lines)
322
323 " change the setting
324 set fillchars=vert:\|,fold:-,eob:~,foldopen:[,foldclose:],foldsep:-
325
326 " check the characters for an open fold
327 let lines = ScreenLines([1, 5], 8)
328 let expected = [
329 \ ' one ',
330 \ '[ two ',
331 \ '- three ',
332 \ '- four ',
333 \ ' five '
334 \ ]
335 call assert_equal(expected, lines)
336
337 " check the characters for a closed fold
338 normal 2Gzc
339 let lines = ScreenLines([1, 3], 8)
340 let expected = [
341 \ ' one ',
342 \ '] +-- 3',
343 \ ' five '
344 \ ]
345 call assert_equal(expected, lines)
346
347 %bw!
348 set fillchars& fdc& foldmethod& foldenable&
349endfunc
350
Bram Moolenaar96ba25a2022-07-04 17:34:33 +0100351func Test_local_fillchars()
352 CheckScreendump
353
354 let lines =<< trim END
355 call setline(1, ['window 1']->repeat(3))
356 setlocal fillchars=stl:1,stlnc:a,vert:=,eob:x
357 vnew
358 call setline(1, ['window 2']->repeat(3))
359 setlocal fillchars=stl:2,stlnc:b,vert:+,eob:y
360 new
361 wincmd J
362 call setline(1, ['window 3']->repeat(3))
363 setlocal fillchars=stl:3,stlnc:c,vert:<,eob:z
364 vnew
365 call setline(1, ['window 4']->repeat(3))
366 setlocal fillchars=stl:4,stlnc:d,vert:>,eob:o
367 END
Bram Moolenaar59173412022-09-20 22:01:33 +0100368 call writefile(lines, 'Xdisplayfillchars', 'D')
Bram Moolenaar96ba25a2022-07-04 17:34:33 +0100369 let buf = RunVimInTerminal('-S Xdisplayfillchars', #{rows: 12})
370 call VerifyScreenDump(buf, 'Test_display_fillchars_1', {})
371
372 call term_sendkeys(buf, ":wincmd k\r")
373 call VerifyScreenDump(buf, 'Test_display_fillchars_2', {})
374
375 call StopVimInTerminal(buf)
Bram Moolenaar96ba25a2022-07-04 17:34:33 +0100376endfunc
377
Bram Moolenaara06e3452021-05-29 17:56:37 +0200378func Test_display_linebreak_breakat()
379 new
380 vert resize 25
381 let _breakat = &breakat
382 setl signcolumn=yes linebreak breakat=) showbreak=+\
383 call setline(1, repeat('x', winwidth(0) - 2) .. ')abc')
384 let lines = ScreenLines([1, 2], 25)
385 let expected = [
386 \ ' xxxxxxxxxxxxxxxxxxxxxxx',
387 \ ' + )abc '
388 \ ]
389 call assert_equal(expected, lines)
390 %bw!
391 let &breakat=_breakat
392endfunc
393
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100394func Run_Test_display_lastline(euro)
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100395 let lines =<< trim END
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100396 call setline(1, ['aaa', 'b'->repeat(200)])
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100397 set display=truncate
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100398
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100399 vsplit
400 100wincmd <
401 END
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100402 if a:euro != ''
403 let lines[2] = 'set fillchars=vert:\|,lastline:€'
404 endif
Bram Moolenaar59173412022-09-20 22:01:33 +0100405 call writefile(lines, 'XdispLastline', 'D')
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100406 let buf = RunVimInTerminal('-S XdispLastline', #{rows: 10})
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100407 call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}1', {})
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100408
409 call term_sendkeys(buf, ":set display=lastline\<CR>")
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100410 call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}2', {})
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100411
412 call term_sendkeys(buf, ":100wincmd >\<CR>")
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100413 call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}3', {})
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100414
415 call term_sendkeys(buf, ":set display=truncate\<CR>")
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100416 call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}4', {})
417
418 call term_sendkeys(buf, ":close\<CR>")
419 call term_sendkeys(buf, ":3split\<CR>")
420 call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}5', {})
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100421
422 call StopVimInTerminal(buf)
Bram Moolenaarcee9c842022-04-09 12:40:13 +0100423endfunc
424
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +0100425func Test_display_lastline()
426 CheckScreendump
427
428 call Run_Test_display_lastline('')
429 call Run_Test_display_lastline('euro_')
430
431 call assert_fails(':set fillchars=lastline:', 'E474:')
432 call assert_fails(':set fillchars=lastline:〇', 'E474:')
433endfunc
434
Bram Moolenaara06e3452021-05-29 17:56:37 +0200435
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200436" vim: shiftwidth=2 sts=2 expandtab