blob: 0292fa1f80736a51ce13a423db56419f6c6a824e [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
124 END
125 call writefile(lines, 'XSmoothNumber', 'D')
126 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
127
128 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
129 call term_sendkeys(buf, "\<C-E>")
130 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
131 call term_sendkeys(buf, "\<C-E>")
132 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
133
134 call term_sendkeys(buf, ":set cpo-=n\<CR>")
135 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
136 call term_sendkeys(buf, "\<C-Y>")
137 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
138 call term_sendkeys(buf, "\<C-Y>")
139 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
140
141 call StopVimInTerminal(buf)
142endfunc
143
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100144func Test_smoothscroll_diff_mode()
145 CheckScreendump
146
147 let lines =<< trim END
148 vim9script
149 var text = 'just some text here'
150 setline(1, text)
151 set smoothscroll
152 diffthis
153 new
154 setline(1, text)
155 set smoothscroll
156 diffthis
157 END
158 call writefile(lines, 'XSmoothDiff', 'D')
159 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
160
161 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
162 call term_sendkeys(buf, "\<C-Y>")
163 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
164 call term_sendkeys(buf, "\<C-E>")
165 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
166
167 call StopVimInTerminal(buf)
168endfunc
169
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100170func Test_smoothscroll_wrap_scrolloff_zero()
171 CheckScreendump
172
173 let lines =<< trim END
174 vim9script
175 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
176 set smoothscroll scrolloff=0
177 :3
178 END
179 call writefile(lines, 'XSmoothWrap', 'D')
180 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
181
182 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
183
Bram Moolenaar46b54742022-10-06 15:46:49 +0100184 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100185 call term_sendkeys(buf, "j")
186 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
187
188 call term_sendkeys(buf, "\<C-E>j")
189 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
190
191 call term_sendkeys(buf, "G")
192 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
193
Bram Moolenaar46b54742022-10-06 15:46:49 +0100194 " moving cursor up - whole top line shows
195 call term_sendkeys(buf, "2k")
196 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
197
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100198 call StopVimInTerminal(buf)
199endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100200
201
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200202" vim: shiftwidth=2 sts=2 expandtab