xref: /vim-8.2.3635/src/testdir/test_number.vim (revision 577fadfc)
1" Test for 'number' and 'relativenumber'
2
3source view_util.vim
4
5func s:screen_lines(start, end) abort
6  return ScreenLines([a:start, a:end], 8)
7endfunc
8
9func s:compare_lines(expect, actual)
10  call assert_equal(a:expect, a:actual)
11endfunc
12
13func s:test_windows(h, w) abort
14  call NewWindow(a:h, a:w)
15endfunc
16
17func s:close_windows() abort
18  call CloseWindow()
19endfunc
20
21func s:validate_cursor() abort
22  " update skipcol.
23  " wincol():
24  "   f_wincol
25  "     -> validate_cursor
26  "          -> curs_columns
27  call wincol()
28endfunc
29
30func Test_set_options()
31  set nu rnu
32  call assert_equal(1, &nu)
33  call assert_equal(1, &rnu)
34
35  call s:test_windows(10, 20)
36  call assert_equal(1, &nu)
37  call assert_equal(1, &rnu)
38  call s:close_windows()
39
40  set nu& rnu&
41endfunc
42
43func Test_set_global_and_local()
44  " setlocal must NOT reset the other global value
45  set nonu nornu
46  setglobal nu
47  setlocal rnu
48  call assert_equal(1, &g:nu)
49
50  set nonu nornu
51  setglobal rnu
52  setlocal nu
53  call assert_equal(1, &g:rnu)
54
55  " setglobal MUST reset the other global value
56  set nonu nornu
57  setglobal nu
58  setglobal rnu
59  call assert_equal(1, &g:nu)
60
61  set nonu nornu
62  setglobal rnu
63  setglobal nu
64  call assert_equal(1, &g:rnu)
65
66  " set MUST reset the other global value
67  set nonu nornu
68  set nu
69  set rnu
70  call assert_equal(1, &g:nu)
71
72  set nonu nornu
73  set rnu
74  set nu
75  call assert_equal(1, &g:rnu)
76
77  set nu& rnu&
78endfunc
79
80func Test_number()
81  call s:test_windows(10, 20)
82  call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
83  setl number
84  let lines = s:screen_lines(1, 4)
85  let expect = [
86\ "  1 abcd",
87\ "  2 klmn",
88\ "  3 uvwx",
89\ "  4 EFGH",
90\ ]
91  call s:compare_lines(expect, lines)
92  call s:close_windows()
93endfunc
94
95func Test_relativenumber()
96  call s:test_windows(10, 20)
97  call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
98  3
99  setl relativenumber
100  let lines = s:screen_lines(1, 6)
101  let expect = [
102\ "  2 abcd",
103\ "  1 klmn",
104\ "  0 uvwx",
105\ "  1 EFGH",
106\ "  2 OPQR",
107\ "  3 YZ  ",
108\ ]
109  call s:compare_lines(expect, lines)
110  call s:close_windows()
111endfunc
112
113func Test_number_with_relativenumber()
114  call s:test_windows(10, 20)
115  call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
116  4
117  setl number relativenumber
118  let lines = s:screen_lines(1, 6)
119  let expect = [
120\ "  3 abcd",
121\ "  2 klmn",
122\ "  1 uvwx",
123\ "4   EFGH",
124\ "  1 OPQR",
125\ "  2 YZ  ",
126\ ]
127  call s:compare_lines(expect, lines)
128  call s:close_windows()
129endfunc
130
131func Test_number_with_linewrap1()
132  call s:test_windows(3, 20)
133  normal! 61ia
134  setl number wrap
135  call s:validate_cursor()
136  let lines = s:screen_lines(1, 3)
137  let expect = [
138\ "--1 aaaa",
139\ "    aaaa",
140\ "    aaaa",
141\ ]
142  call s:compare_lines(expect, lines)
143  call s:close_windows()
144endfunc
145
146" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI
147func XTest_number_with_linewrap2()
148  call s:test_windows(3, 20)
149  normal! 61ia
150  setl number wrap
151  call s:validate_cursor()
152  0
153  call s:validate_cursor()
154  let lines = s:screen_lines(1, 3)
155  let expect = [
156\ "  1 aaaa",
157\ "    aaaa",
158\ "    aaaa",
159\ ]
160  call s:compare_lines(expect, lines)
161  call s:close_windows()
162endfunc
163
164" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI
165func XTest_number_with_linewrap3()
166  call s:test_windows(4, 20)
167  normal! 81ia
168  setl number wrap
169  call s:validate_cursor()
170  setl nonumber
171  call s:validate_cursor()
172  let lines = s:screen_lines(1, 4)
173  let expect = [
174\ "aaaaaaaa",
175\ "aaaaaaaa",
176\ "aaaaaaaa",
177\ "a       ",
178\ ]
179  call s:compare_lines(expect, lines)
180  call s:close_windows()
181endfunc
182
183func Test_numberwidth()
184  call s:test_windows(10, 20)
185  call setline(1, repeat(['aaaa'], 10))
186  setl number numberwidth=6
187  let lines = s:screen_lines(1, 3)
188  let expect = [
189\ "    1 aa",
190\ "    2 aa",
191\ "    3 aa",
192\ ]
193  call s:compare_lines(expect, lines)
194
195  set relativenumber
196  let lines = s:screen_lines(1, 3)
197  let expect = [
198\ "1     aa",
199\ "    1 aa",
200\ "    2 aa",
201\ ]
202  call s:compare_lines(expect, lines)
203
204  set nonumber
205  let lines = s:screen_lines(1, 3)
206  let expect = [
207\ "    0 aa",
208\ "    1 aa",
209\ "    2 aa",
210\ ]
211  call s:compare_lines(expect, lines)
212  call s:close_windows()
213endfunc
214
215func Test_numberwidth_adjusted()
216  call s:test_windows(10, 20)
217  call setline(1, repeat(['aaaa'], 10000))
218  setl number numberwidth=4
219  let lines = s:screen_lines(1, 3)
220  let expect = [
221\ "    1 aa",
222\ "    2 aa",
223\ "    3 aa",
224\ ]
225  call s:compare_lines(expect, lines)
226
227  $
228  let lines = s:screen_lines(8, 10)
229  let expect = [
230\ " 9998 aa",
231\ " 9999 aa",
232\ "10000 aa",
233\ ]
234  call s:compare_lines(expect, lines)
235
236  setl relativenumber
237  let lines = s:screen_lines(8, 10)
238  let expect = [
239\ "    2 aa",
240\ "    1 aa",
241\ "10000 aa",
242\ ]
243  call s:compare_lines(expect, lines)
244
245  setl nonumber
246  let lines = s:screen_lines(8, 10)
247  let expect = [
248\ "  2 aaaa",
249\ "  1 aaaa",
250\ "  0 aaaa",
251\ ]
252  call s:compare_lines(expect, lines)
253  call s:close_windows()
254endfunc
255