blob: 5bf9e5eac8806778f62e4834ada21bae2ddd7e60 [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 Moolenaar6a2c5a72020-04-08 21:50:25 +0200178 call TermWait(buf)
Bram Moolenaar28686682019-10-24 15:12:37 +0200179 call VerifyScreenDump(buf, 'Test_winline_rnu', {})
180
181 " clean up
182 call StopVimInTerminal(buf)
183 call delete(filename)
184endfunc
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100185
186" check a long file name does not result in the hit-enter prompt
187func Test_edit_long_file_name()
188 CheckScreendump
189
Bram Moolenaar6e43b302019-12-14 17:53:27 +0100190 let longName = 'x'->repeat(min([&columns, 255]))
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100191 call writefile([], longName)
192 let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8})
193
194 call VerifyScreenDump(buf, 'Test_long_file_name_1', {})
195
Bram Moolenaar0efd1bd2019-12-11 19:00:04 +0100196 " clean up
197 call StopVimInTerminal(buf)
198 call delete(longName)
199endfunc
200
Bram Moolenaar32ee6272020-06-10 14:16:49 +0200201func Test_unprintable_fileformats()
202 CheckScreendump
203
204 call writefile(["unix\r", "two"], 'Xunix.txt')
205 call writefile(["mac\r", "two"], 'Xmac.txt')
206 let lines =<< trim END
207 edit Xunix.txt
208 split Xmac.txt
209 edit ++ff=mac
210 END
211 let filename = 'Xunprintable'
212 call writefile(lines, filename)
213 let buf = RunVimInTerminal('-S '.filename, #{rows: 9, cols: 50})
214 call VerifyScreenDump(buf, 'Test_display_unprintable_01', {})
215 call term_sendkeys(buf, "\<C-W>\<C-W>\<C-L>")
216 call VerifyScreenDump(buf, 'Test_display_unprintable_02', {})
217
218 " clean up
219 call StopVimInTerminal(buf)
220 call delete('Xunix.txt')
221 call delete('Xmac.txt')
222 call delete(filename)
223endfunc
Bram Moolenaarf8992d42020-08-01 19:14:13 +0200224
225" Test for scrolling that modifies buffer during visual block
226func Test_visual_block_scroll()
227 CheckScreendump
228
229 let lines =<< trim END
230 source $VIMRUNTIME/plugin/matchparen.vim
231 set scrolloff=1
232 call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
233 call cursor(5, 1)
234 END
235
236 let filename = 'Xvisualblockmodifiedscroll'
237 call writefile(lines, filename)
238
239 let buf = RunVimInTerminal('-S '.filename, #{rows: 7})
240 call term_sendkeys(buf, "V\<C-D>\<C-D>")
241
242 call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {})
243
244 call StopVimInTerminal(buf)
245 call delete(filename)
246endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200247
Bram Moolenaar9dc19172020-08-19 20:19:48 +0200248func Test_display_scroll_at_topline()
249 CheckScreendump
250
251 let buf = RunVimInTerminal('', #{cols: 20})
252 call term_sendkeys(buf, ":call setline(1, repeat('a', 21))\<CR>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200253 call TermWait(buf)
Bram Moolenaar9dc19172020-08-19 20:19:48 +0200254 call term_sendkeys(buf, "O\<Esc>")
255 call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4})
256
257 call StopVimInTerminal(buf)
258endfunc
259
Bram Moolenaara98f8a22021-02-13 18:24:23 +0100260" Test for 'eob' (EndOfBuffer) item in 'fillchars'
261func Test_eob_fillchars()
262 " default value
263 call assert_match('eob:\~', &fillchars)
264 " invalid values
265 call assert_fails(':set fillchars=eob:', 'E474:')
266 call assert_fails(':set fillchars=eob:xy', 'E474:')
267 call assert_fails(':set fillchars=eob:\255', 'E474:')
268 call assert_fails(':set fillchars=eob:<ff>', 'E474:')
269 " default is ~
270 new
271 call assert_equal('~', Screenline(2))
272 set fillchars=eob:+
273 redraw!
274 call assert_equal('+', Screenline(2))
275 set fillchars=eob:\
276 redraw!
277 call assert_equal(' ', nr2char(screenchar(2, 1)))
278 set fillchars&
279 close
280endfunc
281
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200282" vim: shiftwidth=2 sts=2 expandtab