summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_scrollbind.vim
blob: 211b05ea0d9155ff1055aa7f845d71054250a167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
" Test for 'scrollbind' causing an unexpected scroll of one of the windows.

func Test_scrollbind()
  " We don't want the status line to cause problems:
  set laststatus=0
  let totalLines = &lines * 20
  let middle = totalLines / 2
  new | only
  for i in range(1, totalLines)
      call setline(i, 'LINE ' . i)
  endfor
  exe string(middle)
  normal zt
  normal M
  aboveleft vert new
  for i in range(1, totalLines)
      call setline(i, 'line ' . i)
  endfor
  exe string(middle)
  normal zt
  normal M
  " Execute the following two commands at once to reproduce the problem.
  setl scb | wincmd p
  setl scb
  wincmd w
  let topLineLeft = line('w0')
  wincmd p
  let topLineRight = line('w0')
  setl noscrollbind
  wincmd p
  setl noscrollbind
  call assert_equal(0, topLineLeft - topLineRight)
endfunc

" Test for 'scrollbind'
func Test_scrollbind_opt()
  new | only
  set noscrollbind
  set scrollopt=ver,jump scrolloff=2 nowrap noequalalways splitbelow

  " Insert the text used for the test
  append


start of window 1
. line 01 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 01
. line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02
. line 03 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 03
. line 04 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 04
. line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05
. line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06
. line 07 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 07
. line 08 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 08
. line 09 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 09
. line 10 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 10
. line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11
. line 12 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 12
. line 13 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 13
. line 14 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 14
. line 15 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 15
end of window 1


start of window 2
. line 01 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 01
. line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02
. line 03 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 03
. line 04 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 04
. line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05
. line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06
. line 07 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 07
. line 08 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 08
. line 09 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 09
. line 10 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 10
. line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11
. line 12 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 12
. line 13 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 13
. line 14 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 14
. line 15 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 15
. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16
end of window 2

.

  " Test using two windows open to one buffer, one extra empty window
  split
  new
  wincmd t
  resize 8
  call search('^start of window 1$')
  normal zt
  set scrollbind
  wincmd j
  resize 7
  call search('^start of window 2$')
  normal zt
  set scrollbind

  " -- start of tests --
  " Test scrolling down
  normal L5jHyy
  wincmd b | normal pr0
  wincmd t | normal Hyy
  wincmd b | normal pr1
  wincmd t | normal L6jHyy
  wincmd b | normal pr2
  wincmd k | normal Hyy
  wincmd b | normal pr3

  " Test scrolling up
  wincmd t | normal H4k
  wincmd j | normal H
  wincmd t | normal Hyy
  wincmd b | normal pr4
  wincmd k | normal Hyy
  wincmd b | normal pr5
  wincmd k | normal 3k
  wincmd t | normal H
  wincmd j | normal Hyy
  wincmd b | normal pr6
  wincmd t | normal Hyy
  wincmd b | normal pr7

  " Test horizontal scrolling
  set scrollopt+=hor
  normal gg"zyyG"zpG
  wincmd t | normal 015zly$
  wincmd b | normal p"zpG
  wincmd k | normal y$
  wincmd b | normal p"zpG
  wincmd k | normal 10jH7zhg0y$
  wincmd b | normal p"zpG
  wincmd t | normal Hg0y$
  wincmd b | normal p"zpG
  set scrollopt-=hor

  wincmd b
  call assert_equal([
	      \ '',
	      \ '0 line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05',
	      \ '1 line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05',
	      \ '2 line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11',
	      \ '3 line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11',
	      \ '4 line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06',
	      \ '5 line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06',
	      \ '6 line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02',
	      \ '7 line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
	      \ '56789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
	      \ 'UTSRQPONMLKJIHGREDCBA9876543210 02',
	      \ '. line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11',
	      \ '. line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11',
	      \ ''],  getline(1, '$'))
  enew!

  " ****** tests using two different buffers *****
  wincmd t | wincmd j | close
  wincmd t | set noscrollbind
  /start of window 2$/,/^end of window 2$/y
  new
  wincmd t | wincmd j | normal 4"zpGp
  wincmd t
  call search('^start of window 1$')
  normal zt
  set scrollbind
  wincmd j
  call search('^start of window 2$')
  normal zt
  set scrollbind

  " -- start of tests --
  " Test scrolling down
  normal L5jHyy
  wincmd b | normal pr0
  wincmd t | normal Hyy
  wincmd b | normal pr1
  wincmd t | normal L6jHyy
  wincmd b | normal pr2
  wincmd k | normal Hyy
  wincmd b | normal pr3

  " Test scrolling up
  wincmd t | normal H4k
  wincmd j | normal H
  wincmd t | normal Hyy
  wincmd b | normal pr4
  wincmd k | normal Hyy
  wincmd b | normal pr5
  wincmd k | normal 3k
  wincmd t | normal H
  wincmd j | normal Hyy
  wincmd b | normal pr6
  wincmd t | normal Hyy
  wincmd b | normal pr7

  " Test horizontal scrolling
  set scrollopt+=hor
  normal gg"zyyG"zpG
  wincmd t | normal 015zly$
  wincmd b | normal p"zpG
  wincmd k | normal y$
  wincmd b | normal p"zpG
  wincmd k | normal 10jH7zhg0y$
  wincmd b | normal p"zpG
  wincmd t | normal Hg0y$
  wincmd b | normal p"zpG
  set scrollopt-=hor

  wincmd b
  call assert_equal([
	      \ '',
	      \ '0 line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05',
	      \ '1 line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05',
	      \ '2 line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11',
	      \ '3 line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11',
	      \ '4 line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06',
	      \ '5 line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06',
	      \ '6 line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02',
	      \ '7 line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
	      \ '56789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
	      \ 'UTSRQPONMLKJIHGREDCBA9876543210 02',
	      \ '. line 10 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 10',
	      \ '. line 10 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 10',
	      \ ''],  getline(1, '$'))
  enew!

  " Test 'syncbind'
  wincmd t | set noscrollbind | normal ggL
  wincmd j | set noscrollbind | normal ggL
  set scrollbind
  wincmd t | set scrollbind | normal G
  wincmd j | normal G
  syncbind
  normal Hk
  wincmd t | normal H
  wincmd j | normal Hyy
  wincmd b | normal p
  wincmd t | normal yy
  wincmd b | normal p
  wincmd t | set noscrollbind | normal ggL
  wincmd j | set noscrollbind
  normal ggL
  set scrollbind
  wincmd t | set scrollbind
  wincmd t | normal G
  wincmd j | normal G
  wincmd t | syncbind | normal Hk
  wincmd j | normal H
  wincmd t | normal Hyy
  wincmd b | normal p
  wincmd t | wincmd j | normal yy
  wincmd b | normal p
  wincmd t | normal H3k
  wincmd j | normal H
  wincmd t | normal Hyy
  wincmd b | normal p
  wincmd t | wincmd j | normal yy
  wincmd b | normal p

  wincmd b
  call assert_equal([
	      \ '',
	      \ '. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16',
	      \ 'start of window 2',
	      \ 'start of window 2',
	      \ '. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16',
	      \ '. line 15 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 15',
	      \ '. line 12 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 12',
	      \ ],  getline(1, '$'))
  enew!

  new | only!
  set scrollbind& scrollopt& scrolloff& wrap& equalalways& splitbelow&
endfunc

" vim: shiftwidth=2 sts=2 expandtab