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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
" Test for 'number' and 'relativenumber'
source check.vim
source view_util.vim
source screendump.vim
func s:screen_lines(start, end) abort
return ScreenLines([a:start, a:end], 8)
endfunc
func s:compare_lines(expect, actual)
call assert_equal(a:expect, a:actual)
endfunc
func s:test_windows(h, w) abort
call NewWindow(a:h, a:w)
endfunc
func s:close_windows() abort
call CloseWindow()
endfunc
func s:validate_cursor() abort
" update skipcol.
" wincol():
" f_wincol
" -> validate_cursor
" -> curs_columns
call wincol()
endfunc
func Test_set_options()
set nu rnu
call assert_equal(1, &nu)
call assert_equal(1, &rnu)
call s:test_windows(10, 20)
call assert_equal(1, &nu)
call assert_equal(1, &rnu)
call s:close_windows()
set nu& rnu&
endfunc
func Test_set_global_and_local()
" setlocal must NOT reset the other global value
set nonu nornu
setglobal nu
setlocal rnu
call assert_equal(1, &g:nu)
set nonu nornu
setglobal rnu
setlocal nu
call assert_equal(1, &g:rnu)
" setglobal MUST reset the other global value
set nonu nornu
setglobal nu
setglobal rnu
call assert_equal(1, &g:nu)
set nonu nornu
setglobal rnu
setglobal nu
call assert_equal(1, &g:rnu)
" set MUST reset the other global value
set nonu nornu
set nu
set rnu
call assert_equal(1, &g:nu)
set nonu nornu
set rnu
set nu
call assert_equal(1, &g:rnu)
set nu& rnu&
endfunc
func Test_number()
call s:test_windows(10, 20)
call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
setl number
let lines = s:screen_lines(1, 4)
let expect = [
\ " 1 abcd",
\ " 2 klmn",
\ " 3 uvwx",
\ " 4 EFGH",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_relativenumber()
call s:test_windows(10, 20)
call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
3
setl relativenumber
let lines = s:screen_lines(1, 6)
let expect = [
\ " 2 abcd",
\ " 1 klmn",
\ " 0 uvwx",
\ " 1 EFGH",
\ " 2 OPQR",
\ " 3 YZ ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_number_with_relativenumber()
call s:test_windows(10, 20)
call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
4
setl number relativenumber
let lines = s:screen_lines(1, 6)
let expect = [
\ " 3 abcd",
\ " 2 klmn",
\ " 1 uvwx",
\ "4 EFGH",
\ " 1 OPQR",
\ " 2 YZ ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_number_with_linewrap1()
call s:test_windows(3, 20)
normal! 61ia
setl number wrap
call s:validate_cursor()
let lines = s:screen_lines(1, 3)
let expect = [
\ "--1 aaaa",
\ " aaaa",
\ " aaaa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI
func XTest_number_with_linewrap2()
call s:test_windows(3, 20)
normal! 61ia
setl number wrap
call s:validate_cursor()
0
call s:validate_cursor()
let lines = s:screen_lines(1, 3)
let expect = [
\ " 1 aaaa",
\ " aaaa",
\ " aaaa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI
func XTest_number_with_linewrap3()
call s:test_windows(4, 20)
normal! 81ia
setl number wrap
call s:validate_cursor()
setl nonumber
call s:validate_cursor()
let lines = s:screen_lines(1, 4)
let expect = [
\ "aaaaaaaa",
\ "aaaaaaaa",
\ "aaaaaaaa",
\ "a ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_numberwidth()
call s:test_windows(10, 20)
call setline(1, repeat(['aaaa'], 10))
setl number numberwidth=6
let lines = s:screen_lines(1, 3)
let expect = [
\ " 1 aa",
\ " 2 aa",
\ " 3 aa",
\ ]
call s:compare_lines(expect, lines)
set relativenumber
let lines = s:screen_lines(1, 3)
let expect = [
\ "1 aa",
\ " 1 aa",
\ " 2 aa",
\ ]
call s:compare_lines(expect, lines)
set nonumber
let lines = s:screen_lines(1, 3)
let expect = [
\ " 0 aa",
\ " 1 aa",
\ " 2 aa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_numberwidth_adjusted()
call s:test_windows(10, 20)
call setline(1, repeat(['aaaa'], 10000))
setl number numberwidth=4
let lines = s:screen_lines(1, 3)
let expect = [
\ " 1 aa",
\ " 2 aa",
\ " 3 aa",
\ ]
call s:compare_lines(expect, lines)
$
let lines = s:screen_lines(8, 10)
let expect = [
\ " 9998 aa",
\ " 9999 aa",
\ "10000 aa",
\ ]
call s:compare_lines(expect, lines)
setl relativenumber
let lines = s:screen_lines(8, 10)
let expect = [
\ " 2 aa",
\ " 1 aa",
\ "10000 aa",
\ ]
call s:compare_lines(expect, lines)
setl nonumber
let lines = s:screen_lines(8, 10)
let expect = [
\ " 2 aaaa",
\ " 1 aaaa",
\ " 0 aaaa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
" This was causing a memcheck error
func Test_relativenumber_uninitialised()
new
set rnu
call setline(1, ["a", "b"])
redraw
call feedkeys("j", 'xt')
redraw
bwipe!
endfunc
func Test_relativenumber_colors()
CheckScreendump
let lines =<< trim [CODE]
call setline(1, range(200))
111
set number relativenumber
hi LineNr ctermfg=red
[CODE]
call writefile(lines, 'XTest_relnr')
" Check that the balloon shows up after a mouse move
let buf = RunVimInTerminal('-S XTest_relnr', {'rows': 10, 'cols': 50})
call TermWait(buf, 50)
" Default colors
call VerifyScreenDump(buf, 'Test_relnr_colors_1', {})
call term_sendkeys(buf, ":hi LineNrAbove ctermfg=blue\<CR>:\<CR>")
call VerifyScreenDump(buf, 'Test_relnr_colors_2', {})
call term_sendkeys(buf, ":hi LineNrBelow ctermfg=green\<CR>:\<CR>")
call VerifyScreenDump(buf, 'Test_relnr_colors_3', {})
call term_sendkeys(buf, ":hi clear LineNrAbove\<CR>")
call VerifyScreenDump(buf, 'Test_relnr_colors_4', {})
" clean up
call StopVimInTerminal(buf)
call delete('XTest_relnr')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
|