xref: /vim-8.2.3635/src/testdir/test_display.vim (revision 8ea05de6)
1" Test for displaying stuff
2
3if !has('gui_running') && has('unix')
4  set term=ansi
5endif
6
7source view_util.vim
8source check.vim
9source screendump.vim
10
11func Test_display_foldcolumn()
12  CheckFeature folding
13
14  new
15  vnew
16  vert resize 25
17  call assert_equal(25, winwidth(winnr()))
18  set isprint=@
19
20  1put='e more noise blah blah‚ more stuff here'
21
22  let expect = [
23        \ "e more noise blah blah<82",
24        \ "> more stuff here        "
25        \ ]
26
27  call cursor(2, 1)
28  norm! zt
29  let lines = ScreenLines([1,2], winwidth(0))
30  call assert_equal(expect, lines)
31  set fdc=2
32  let lines = ScreenLines([1,2], winwidth(0))
33  let expect = [
34        \ "  e more noise blah blah<",
35        \ "  82> more stuff here    "
36        \ ]
37  call assert_equal(expect, lines)
38
39  quit!
40  quit!
41endfunc
42
43func Test_display_foldtext_mbyte()
44  CheckFeature folding
45
46  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)
58
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
68  set foldtext& fillchars& foldmethod& fdc&
69  bw!
70endfunc
71
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
92  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
103  " clean up
104  call StopVimInTerminal(buf)
105  call delete('Xtestscroll')
106endfunc
107
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
162
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")
178  call TermWait(buf)
179  call VerifyScreenDump(buf, 'Test_winline_rnu', {})
180
181  " clean up
182  call StopVimInTerminal(buf)
183  call delete(filename)
184endfunc
185
186" check a long file name does not result in the hit-enter prompt
187func Test_edit_long_file_name()
188  CheckScreendump
189
190  let longName = 'x'->repeat(min([&columns, 255]))
191  call writefile([], longName)
192  let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8})
193
194  call VerifyScreenDump(buf, 'Test_long_file_name_1', {})
195
196  " clean up
197  call StopVimInTerminal(buf)
198  call delete(longName)
199endfunc
200
201func 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
224
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
247
248func 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>")
253  call TermWait(buf)
254  call term_sendkeys(buf, "O\<Esc>")
255  call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4})
256
257  call StopVimInTerminal(buf)
258endfunc
259
260" vim: shiftwidth=2 sts=2 expandtab
261