blob: 19c753d96e5a56952e8f4d69e04519dd829f3354 [file] [log] [blame]
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001" Test for reset 'scroll' and 'smoothscroll'
2
3source check.vim
4source screendump.vim
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01005
6func Test_reset_scroll()
7 let scr = &l:scroll
8
9 setlocal scroll=1
10 setlocal scroll&
11 call assert_equal(scr, &l:scroll)
12
13 setlocal scroll=1
14 setlocal scroll=0
15 call assert_equal(scr, &l:scroll)
16
17 try
18 execute 'setlocal scroll=' . (winheight(0) + 1)
19 " not reached
20 call assert_false(1)
21 catch
22 call assert_exception('E49:')
23 endtry
24
25 split
26
27 let scr = &l:scroll
28
29 setlocal scroll=1
30 setlocal scroll&
31 call assert_equal(scr, &l:scroll)
32
33 setlocal scroll=1
34 setlocal scroll=0
35 call assert_equal(scr, &l:scroll)
36
37 quit!
38endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020039
Bram Moolenaar8df97482022-10-03 12:11:13 +010040func Test_CtrlE_CtrlY_stop_at_end()
41 enew
42 call setline(1, ['one', 'two'])
43 set number
44 exe "normal \<C-Y>"
45 call assert_equal([" 1 one "], ScreenLines(1, 10))
46 exe "normal \<C-E>\<C-E>\<C-E>"
47 call assert_equal([" 2 two "], ScreenLines(1, 10))
48
49 bwipe!
50 set nonumber
51endfunc
52
Bram Moolenaarf6196f42022-10-02 21:29:55 +010053func Test_smoothscroll_CtrlE_CtrlY()
54 CheckScreendump
55
56 let lines =<< trim END
57 vim9script
58 setline(1, [
59 'line one',
60 'word '->repeat(20),
61 'line three',
62 'long word '->repeat(7),
63 'line',
64 'line',
65 'line',
66 ])
67 set smoothscroll
68 :5
69 END
70 call writefile(lines, 'XSmoothScroll', 'D')
71 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
72
73 call term_sendkeys(buf, "\<C-E>")
74 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
75 call term_sendkeys(buf, "\<C-E>")
76 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
77 call term_sendkeys(buf, "\<C-E>")
78 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
79 call term_sendkeys(buf, "\<C-E>")
80 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
81
82 call term_sendkeys(buf, "\<C-Y>")
83 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
84 call term_sendkeys(buf, "\<C-Y>")
85 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
86 call term_sendkeys(buf, "\<C-Y>")
87 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
88 call term_sendkeys(buf, "\<C-Y>")
89 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
90
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +010091 if has('folding')
92 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
93 " move the cursor so we can reuse the same dumps
94 call term_sendkeys(buf, "5G")
95 call term_sendkeys(buf, "\<C-E>")
96 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
97 call term_sendkeys(buf, "\<C-E>")
98 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
99 call term_sendkeys(buf, "7G")
100 call term_sendkeys(buf, "\<C-Y>")
101 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
102 call term_sendkeys(buf, "\<C-Y>")
103 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
104 endif
105
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100106 call StopVimInTerminal(buf)
107endfunc
108
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100109func Test_smoothscroll_number()
110 CheckScreendump
111
112 let lines =<< trim END
113 vim9script
114 setline(1, [
115 'one ' .. 'word '->repeat(20),
116 'two ' .. 'long word '->repeat(7),
117 'line',
118 'line',
119 'line',
120 ])
121 set smoothscroll
122 set number cpo+=n
123 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100124
125 def g:DoRel()
126 set number relativenumber scrolloff=0
127 :%del
128 setline(1, [
129 'one',
130 'very long text '->repeat(12),
131 'three',
132 ])
133 exe "normal 2Gzt\<C-E>"
134 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100135 END
136 call writefile(lines, 'XSmoothNumber', 'D')
137 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
138
139 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
140 call term_sendkeys(buf, "\<C-E>")
141 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
142 call term_sendkeys(buf, "\<C-E>")
143 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
144
145 call term_sendkeys(buf, ":set cpo-=n\<CR>")
146 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
147 call term_sendkeys(buf, "\<C-Y>")
148 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
149 call term_sendkeys(buf, "\<C-Y>")
150 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
151
Bram Moolenaareb4de622022-10-15 13:42:17 +0100152 call term_sendkeys(buf, ":call DoRel()\<CR>")
153 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
154
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100155 call StopVimInTerminal(buf)
156endfunc
157
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100158func Test_smoothscroll_diff_mode()
159 CheckScreendump
160
161 let lines =<< trim END
162 vim9script
163 var text = 'just some text here'
164 setline(1, text)
165 set smoothscroll
166 diffthis
167 new
168 setline(1, text)
169 set smoothscroll
170 diffthis
171 END
172 call writefile(lines, 'XSmoothDiff', 'D')
173 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
174
175 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
176 call term_sendkeys(buf, "\<C-Y>")
177 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
178 call term_sendkeys(buf, "\<C-E>")
179 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
180
181 call StopVimInTerminal(buf)
182endfunc
183
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100184func Test_smoothscroll_wrap_scrolloff_zero()
185 CheckScreendump
186
187 let lines =<< trim END
188 vim9script
189 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
190 set smoothscroll scrolloff=0
191 :3
192 END
193 call writefile(lines, 'XSmoothWrap', 'D')
194 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
195
196 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
197
Bram Moolenaar46b54742022-10-06 15:46:49 +0100198 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100199 call term_sendkeys(buf, "j")
200 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
201
202 call term_sendkeys(buf, "\<C-E>j")
203 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
204
205 call term_sendkeys(buf, "G")
206 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
207
Bram Moolenaar46b54742022-10-06 15:46:49 +0100208 " moving cursor up - whole top line shows
209 call term_sendkeys(buf, "2k")
210 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
211
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100212 call StopVimInTerminal(buf)
213endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100214
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100215func Test_smoothscroll_wrap_long_line()
216 CheckScreendump
217
218 let lines =<< trim END
219 vim9script
220 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))])
221 set smoothscroll scrolloff=0
222 normal 3G10|zt
223 END
224 call writefile(lines, 'XSmoothWrap', 'D')
225 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
226 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
227
228 " scrolling up, cursor moves screen line down
229 call term_sendkeys(buf, "\<C-E>")
230 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
231 call term_sendkeys(buf, "5\<C-E>")
232 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
233
234 " scrolling down, cursor moves screen line up
235 call term_sendkeys(buf, "5\<C-Y>")
236 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
237 call term_sendkeys(buf, "\<C-Y>")
238 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
239
Bram Moolenaar118c2352022-10-09 17:19:27 +0100240 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
241 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
242 call term_sendkeys(buf, "10|\<C-E>")
243 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
244
245 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
246 call term_sendkeys(buf, "\<C-E>")
247 call term_sendkeys(buf, "gjgj")
248 call term_sendkeys(buf, "\<C-Y>")
249 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
250
251 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
252 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
253 call term_sendkeys(buf, "10|\<C-E>")
254 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
255
256 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
257 call term_sendkeys(buf, "\<C-E>")
258 call term_sendkeys(buf, "gj")
259 call term_sendkeys(buf, "\<C-Y>")
260 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
261
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100262 call StopVimInTerminal(buf)
263endfunc
264
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100265func Test_smoothscroll_one_long_line()
266 CheckScreendump
267
268 let lines =<< trim END
269 vim9script
270 setline(1, 'with lots of text '->repeat(7))
271 set smoothscroll scrolloff=0
272 END
273 call writefile(lines, 'XSmoothOneLong', 'D')
274 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
275 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
276
277 call term_sendkeys(buf, "\<C-E>")
278 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
279
280 call term_sendkeys(buf, "0")
281 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
282
283 call StopVimInTerminal(buf)
284endfunc
285
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100286
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200287" vim: shiftwidth=2 sts=2 expandtab