Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 1 | " Test for 'number' and 'relativenumber' |
| 2 | |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 4 | source view_util.vim |
| 5 | |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 6 | source screendump.vim |
| 7 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 8 | func s:screen_lines(start, end) abort |
Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 9 | return ScreenLines([a:start, a:end], 8) |
| 10 | endfunc |
| 11 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 12 | func s:compare_lines(expect, actual) |
Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 13 | call assert_equal(a:expect, a:actual) |
| 14 | endfunc |
| 15 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 16 | func s:test_windows(h, w) abort |
Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 17 | call NewWindow(a:h, a:w) |
| 18 | endfunc |
| 19 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 20 | func s:close_windows() abort |
Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 21 | call CloseWindow() |
| 22 | endfunc |
| 23 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 24 | func s:validate_cursor() abort |
Bram Moolenaar | dc9a081 | 2017-02-23 18:46:50 +0100 | [diff] [blame] | 25 | " update skipcol. |
| 26 | " wincol(): |
| 27 | " f_wincol |
| 28 | " -> validate_cursor |
| 29 | " -> curs_columns |
| 30 | call wincol() |
| 31 | endfunc |
| 32 | |
| 33 | func Test_set_options() |
| 34 | set nu rnu |
| 35 | call assert_equal(1, &nu) |
| 36 | call assert_equal(1, &rnu) |
| 37 | |
| 38 | call s:test_windows(10, 20) |
| 39 | call assert_equal(1, &nu) |
| 40 | call assert_equal(1, &rnu) |
| 41 | call s:close_windows() |
| 42 | |
| 43 | set nu& rnu& |
| 44 | endfunc |
| 45 | |
| 46 | func Test_set_global_and_local() |
| 47 | " setlocal must NOT reset the other global value |
| 48 | set nonu nornu |
| 49 | setglobal nu |
| 50 | setlocal rnu |
| 51 | call assert_equal(1, &g:nu) |
| 52 | |
| 53 | set nonu nornu |
| 54 | setglobal rnu |
| 55 | setlocal nu |
| 56 | call assert_equal(1, &g:rnu) |
| 57 | |
| 58 | " setglobal MUST reset the other global value |
| 59 | set nonu nornu |
| 60 | setglobal nu |
| 61 | setglobal rnu |
| 62 | call assert_equal(1, &g:nu) |
| 63 | |
| 64 | set nonu nornu |
| 65 | setglobal rnu |
| 66 | setglobal nu |
| 67 | call assert_equal(1, &g:rnu) |
| 68 | |
| 69 | " set MUST reset the other global value |
| 70 | set nonu nornu |
| 71 | set nu |
| 72 | set rnu |
| 73 | call assert_equal(1, &g:nu) |
| 74 | |
| 75 | set nonu nornu |
| 76 | set rnu |
| 77 | set nu |
| 78 | call assert_equal(1, &g:rnu) |
| 79 | |
| 80 | set nu& rnu& |
| 81 | endfunc |
| 82 | |
| 83 | func Test_number() |
| 84 | call s:test_windows(10, 20) |
| 85 | call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"]) |
| 86 | setl number |
| 87 | let lines = s:screen_lines(1, 4) |
| 88 | let expect = [ |
| 89 | \ " 1 abcd", |
| 90 | \ " 2 klmn", |
| 91 | \ " 3 uvwx", |
| 92 | \ " 4 EFGH", |
| 93 | \ ] |
| 94 | call s:compare_lines(expect, lines) |
| 95 | call s:close_windows() |
| 96 | endfunc |
| 97 | |
| 98 | func Test_relativenumber() |
| 99 | call s:test_windows(10, 20) |
| 100 | call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"]) |
| 101 | 3 |
| 102 | setl relativenumber |
| 103 | let lines = s:screen_lines(1, 6) |
| 104 | let expect = [ |
| 105 | \ " 2 abcd", |
| 106 | \ " 1 klmn", |
| 107 | \ " 0 uvwx", |
| 108 | \ " 1 EFGH", |
| 109 | \ " 2 OPQR", |
| 110 | \ " 3 YZ ", |
| 111 | \ ] |
| 112 | call s:compare_lines(expect, lines) |
| 113 | call s:close_windows() |
| 114 | endfunc |
| 115 | |
| 116 | func Test_number_with_relativenumber() |
| 117 | call s:test_windows(10, 20) |
| 118 | call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"]) |
| 119 | 4 |
| 120 | setl number relativenumber |
| 121 | let lines = s:screen_lines(1, 6) |
| 122 | let expect = [ |
| 123 | \ " 3 abcd", |
| 124 | \ " 2 klmn", |
| 125 | \ " 1 uvwx", |
| 126 | \ "4 EFGH", |
| 127 | \ " 1 OPQR", |
| 128 | \ " 2 YZ ", |
| 129 | \ ] |
| 130 | call s:compare_lines(expect, lines) |
| 131 | call s:close_windows() |
| 132 | endfunc |
| 133 | |
| 134 | func Test_number_with_linewrap1() |
| 135 | call s:test_windows(3, 20) |
| 136 | normal! 61ia |
| 137 | setl number wrap |
| 138 | call s:validate_cursor() |
| 139 | let lines = s:screen_lines(1, 3) |
| 140 | let expect = [ |
| 141 | \ "--1 aaaa", |
| 142 | \ " aaaa", |
| 143 | \ " aaaa", |
| 144 | \ ] |
| 145 | call s:compare_lines(expect, lines) |
| 146 | call s:close_windows() |
| 147 | endfunc |
| 148 | |
| 149 | " Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI |
| 150 | func XTest_number_with_linewrap2() |
| 151 | call s:test_windows(3, 20) |
| 152 | normal! 61ia |
| 153 | setl number wrap |
| 154 | call s:validate_cursor() |
| 155 | 0 |
| 156 | call s:validate_cursor() |
| 157 | let lines = s:screen_lines(1, 3) |
| 158 | let expect = [ |
| 159 | \ " 1 aaaa", |
| 160 | \ " aaaa", |
| 161 | \ " aaaa", |
| 162 | \ ] |
| 163 | call s:compare_lines(expect, lines) |
| 164 | call s:close_windows() |
| 165 | endfunc |
| 166 | |
| 167 | " Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI |
| 168 | func XTest_number_with_linewrap3() |
| 169 | call s:test_windows(4, 20) |
| 170 | normal! 81ia |
| 171 | setl number wrap |
| 172 | call s:validate_cursor() |
| 173 | setl nonumber |
| 174 | call s:validate_cursor() |
| 175 | let lines = s:screen_lines(1, 4) |
| 176 | let expect = [ |
| 177 | \ "aaaaaaaa", |
| 178 | \ "aaaaaaaa", |
| 179 | \ "aaaaaaaa", |
| 180 | \ "a ", |
| 181 | \ ] |
| 182 | call s:compare_lines(expect, lines) |
| 183 | call s:close_windows() |
| 184 | endfunc |
| 185 | |
| 186 | func Test_numberwidth() |
| 187 | call s:test_windows(10, 20) |
| 188 | call setline(1, repeat(['aaaa'], 10)) |
| 189 | setl number numberwidth=6 |
| 190 | let lines = s:screen_lines(1, 3) |
| 191 | let expect = [ |
| 192 | \ " 1 aa", |
| 193 | \ " 2 aa", |
| 194 | \ " 3 aa", |
| 195 | \ ] |
| 196 | call s:compare_lines(expect, lines) |
| 197 | |
| 198 | set relativenumber |
| 199 | let lines = s:screen_lines(1, 3) |
| 200 | let expect = [ |
| 201 | \ "1 aa", |
| 202 | \ " 1 aa", |
| 203 | \ " 2 aa", |
| 204 | \ ] |
| 205 | call s:compare_lines(expect, lines) |
| 206 | |
| 207 | set nonumber |
| 208 | let lines = s:screen_lines(1, 3) |
| 209 | let expect = [ |
| 210 | \ " 0 aa", |
| 211 | \ " 1 aa", |
| 212 | \ " 2 aa", |
| 213 | \ ] |
| 214 | call s:compare_lines(expect, lines) |
| 215 | call s:close_windows() |
| 216 | endfunc |
| 217 | |
| 218 | func Test_numberwidth_adjusted() |
| 219 | call s:test_windows(10, 20) |
| 220 | call setline(1, repeat(['aaaa'], 10000)) |
| 221 | setl number numberwidth=4 |
| 222 | let lines = s:screen_lines(1, 3) |
| 223 | let expect = [ |
| 224 | \ " 1 aa", |
| 225 | \ " 2 aa", |
| 226 | \ " 3 aa", |
| 227 | \ ] |
| 228 | call s:compare_lines(expect, lines) |
| 229 | |
| 230 | $ |
| 231 | let lines = s:screen_lines(8, 10) |
| 232 | let expect = [ |
| 233 | \ " 9998 aa", |
| 234 | \ " 9999 aa", |
| 235 | \ "10000 aa", |
| 236 | \ ] |
| 237 | call s:compare_lines(expect, lines) |
| 238 | |
| 239 | setl relativenumber |
| 240 | let lines = s:screen_lines(8, 10) |
| 241 | let expect = [ |
| 242 | \ " 2 aa", |
| 243 | \ " 1 aa", |
| 244 | \ "10000 aa", |
| 245 | \ ] |
| 246 | call s:compare_lines(expect, lines) |
| 247 | |
| 248 | setl nonumber |
| 249 | let lines = s:screen_lines(8, 10) |
| 250 | let expect = [ |
| 251 | \ " 2 aaaa", |
| 252 | \ " 1 aaaa", |
| 253 | \ " 0 aaaa", |
| 254 | \ ] |
| 255 | call s:compare_lines(expect, lines) |
| 256 | call s:close_windows() |
| 257 | endfunc |
Bram Moolenaar | ec572ad | 2019-07-07 14:26:59 +0200 | [diff] [blame] | 258 | |
| 259 | " This was causing a memcheck error |
| 260 | func Test_relativenumber_uninitialised() |
| 261 | new |
| 262 | set rnu |
| 263 | call setline(1, ["a", "b"]) |
| 264 | redraw |
| 265 | call feedkeys("j", 'xt') |
| 266 | redraw |
| 267 | bwipe! |
| 268 | endfunc |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 269 | |
| 270 | func Test_relativenumber_colors() |
| 271 | CheckScreendump |
| 272 | |
| 273 | let lines =<< trim [CODE] |
| 274 | call setline(1, range(200)) |
| 275 | 111 |
| 276 | set number relativenumber |
| 277 | hi LineNr ctermfg=red |
| 278 | [CODE] |
| 279 | call writefile(lines, 'XTest_relnr') |
| 280 | |
| 281 | " Check that the balloon shows up after a mouse move |
| 282 | let buf = RunVimInTerminal('-S XTest_relnr', {'rows': 10, 'cols': 50}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 283 | call TermWait(buf, 50) |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 284 | " Default colors |
| 285 | call VerifyScreenDump(buf, 'Test_relnr_colors_1', {}) |
| 286 | |
Bram Moolenaar | 8040a71 | 2020-02-23 13:38:08 +0100 | [diff] [blame] | 287 | call term_sendkeys(buf, ":hi LineNrAbove ctermfg=blue\<CR>:\<CR>") |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 288 | call VerifyScreenDump(buf, 'Test_relnr_colors_2', {}) |
| 289 | |
Bram Moolenaar | 8040a71 | 2020-02-23 13:38:08 +0100 | [diff] [blame] | 290 | call term_sendkeys(buf, ":hi LineNrBelow ctermfg=green\<CR>:\<CR>") |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 291 | call VerifyScreenDump(buf, 'Test_relnr_colors_3', {}) |
| 292 | |
| 293 | call term_sendkeys(buf, ":hi clear LineNrAbove\<CR>") |
| 294 | call VerifyScreenDump(buf, 'Test_relnr_colors_4', {}) |
| 295 | |
| 296 | " clean up |
| 297 | call StopVimInTerminal(buf) |
| 298 | call delete('XTest_relnr') |
| 299 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 300 | |
zeertzjq | 3e559cd | 2022-03-27 19:26:55 +0100 | [diff] [blame] | 301 | func Test_relativenumber_callback() |
| 302 | CheckScreendump |
| 303 | CheckFeature timers |
| 304 | |
| 305 | let lines =<< trim END |
| 306 | call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) |
| 307 | set relativenumber |
| 308 | call cursor(4, 1) |
| 309 | |
| 310 | func Func(timer) |
| 311 | call cursor(1, 1) |
| 312 | endfunc |
| 313 | |
| 314 | call timer_start(300, 'Func') |
| 315 | END |
| 316 | call writefile(lines, 'Xrnu_timer') |
| 317 | |
| 318 | let buf = RunVimInTerminal('-S Xrnu_timer', #{rows: 8}) |
| 319 | call TermWait(buf, 310) |
| 320 | call VerifyScreenDump(buf, 'Test_relativenumber_callback_1', {}) |
| 321 | |
| 322 | call StopVimInTerminal(buf) |
| 323 | call delete('Xrnu_timer') |
| 324 | endfunc |
| 325 | |
Christian Brabandt | 29f0dc3 | 2021-06-16 19:28:34 +0200 | [diff] [blame] | 326 | " Test for displaying line numbers with 'rightleft' |
| 327 | func Test_number_rightleft() |
| 328 | CheckFeature rightleft |
| 329 | new |
| 330 | setlocal number |
| 331 | setlocal rightleft |
| 332 | call setline(1, range(1, 1000)) |
| 333 | normal! 9Gzt |
| 334 | redraw! |
| 335 | call assert_match('^\s\+9 9$', Screenline(1)) |
| 336 | normal! 10Gzt |
| 337 | redraw! |
| 338 | call assert_match('^\s\+01 10$', Screenline(1)) |
| 339 | normal! 100Gzt |
| 340 | redraw! |
| 341 | call assert_match('^\s\+001 100$', Screenline(1)) |
| 342 | normal! 1000Gzt |
| 343 | redraw! |
| 344 | call assert_match('^\s\+0001 1000$', Screenline(1)) |
| 345 | bw! |
| 346 | endfunc |
| 347 | |
Bram Moolenaar | 02f8694 | 2021-08-17 22:14:29 +0200 | [diff] [blame] | 348 | " This used to cause a divide by zero |
| 349 | func Test_number_no_text_virtual_edit() |
| 350 | vnew |
| 351 | call setline(1, ['line one', 'line two']) |
| 352 | set number virtualedit=all |
| 353 | normal w |
| 354 | 4wincmd | |
| 355 | normal j |
| 356 | bwipe! |
| 357 | endfunc |
| 358 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 359 | " vim: shiftwidth=2 sts=2 expandtab |