xref: /vim-8.2.3635/src/testdir/test_display.vim (revision 2387773d)
1" Test for displaying stuff
2if !has('gui_running') && has('unix')
3  set term=ansi
4endif
5
6source view_util.vim
7source check.vim
8source screendump.vim
9
10func Test_display_foldcolumn()
11  CheckFeature folding
12
13  new
14  vnew
15  vert resize 25
16  call assert_equal(25, winwidth(winnr()))
17  set isprint=@
18
19  1put='e more noise blah blah‚ more stuff here'
20
21  let expect = [
22        \ "e more noise blah blah<82",
23        \ "> more stuff here        "
24        \ ]
25
26  call cursor(2, 1)
27  norm! zt
28  let lines = ScreenLines([1,2], winwidth(0))
29  call assert_equal(expect, lines)
30  set fdc=2
31  let lines = ScreenLines([1,2], winwidth(0))
32  let expect = [
33        \ "  e more noise blah blah<",
34        \ "  82> more stuff here    "
35        \ ]
36  call assert_equal(expect, lines)
37
38  quit!
39  quit!
40endfunc
41
42func Test_display_foldtext_mbyte()
43  CheckFeature folding
44
45  call NewWindow(10, 40)
46  call append(0, range(1,20))
47  exe "set foldmethod=manual foldtext=foldtext() fillchars=fold:\u2500,vert:\u2502 fdc=2"
48  call cursor(2, 1)
49  norm! zf13G
50  let lines=ScreenLines([1,3], winwidth(0)+1)
51  let expect=[
52        \ "  1                                     \u2502",
53        \ "+ +-- 12 lines: 2". repeat("\u2500", 23). "\u2502",
54        \ "  14                                    \u2502",
55        \ ]
56  call assert_equal(expect, lines)
57
58  set fillchars=fold:-,vert:\|
59  let lines=ScreenLines([1,3], winwidth(0)+1)
60  let expect=[
61        \ "  1                                     |",
62        \ "+ +-- 12 lines: 2". repeat("-", 23). "|",
63        \ "  14                                    |",
64        \ ]
65  call assert_equal(expect, lines)
66
67  set foldtext& fillchars& foldmethod& fdc&
68  bw!
69endfunc
70
71" check that win_ins_lines() and win_del_lines() work when t_cs is empty.
72func Test_scroll_without_region()
73  CheckScreendump
74
75  let lines =<< trim END
76    call setline(1, range(1, 20))
77    set t_cs=
78    set laststatus=2
79  END
80  call writefile(lines, 'Xtestscroll')
81  let buf = RunVimInTerminal('-S Xtestscroll', #{rows: 10})
82
83  call VerifyScreenDump(buf, 'Test_scroll_no_region_1', {})
84
85  call term_sendkeys(buf, ":3delete\<cr>")
86  call VerifyScreenDump(buf, 'Test_scroll_no_region_2', {})
87
88  call term_sendkeys(buf, ":4put\<cr>")
89  call VerifyScreenDump(buf, 'Test_scroll_no_region_3', {})
90
91  call term_sendkeys(buf, ":undo\<cr>")
92  call term_sendkeys(buf, ":undo\<cr>")
93  call term_sendkeys(buf, ":set laststatus=0\<cr>")
94  call VerifyScreenDump(buf, 'Test_scroll_no_region_4', {})
95
96  call term_sendkeys(buf, ":3delete\<cr>")
97  call VerifyScreenDump(buf, 'Test_scroll_no_region_5', {})
98
99  call term_sendkeys(buf, ":4put\<cr>")
100  call VerifyScreenDump(buf, 'Test_scroll_no_region_6', {})
101
102  " clean up
103  call StopVimInTerminal(buf)
104  call delete('Xtestscroll')
105endfunc
106
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 = [
146        \ "<aaa aaa a|",
147        \ "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
161
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'
174  call writefile(lines, filename)
175  let buf = RunVimInTerminal('-S '.filename, #{rows: 5, cols: 50})
176  call term_sendkeys(buf, "k")
177  call term_wait(buf)
178  call VerifyScreenDump(buf, 'Test_winline_rnu', {})
179
180  " clean up
181  call StopVimInTerminal(buf)
182  call delete(filename)
183endfunc
184
185" check a long file name does not result in the hit-enter prompt
186func Test_edit_long_file_name()
187  CheckScreendump
188
189  let longName = 'x'->repeat(min([&columns, 255]))
190  call writefile([], longName)
191  let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8})
192
193  call VerifyScreenDump(buf, 'Test_long_file_name_1', {})
194
195  call term_sendkeys(buf, ":q\<cr>")
196
197  " clean up
198  call StopVimInTerminal(buf)
199  call delete(longName)
200endfunc
201
202