1" Test for 'number' and 'relativenumber' 2 3source check.vim 4source view_util.vim 5 6source screendump.vim 7 8func s:screen_lines(start, end) abort 9 return ScreenLines([a:start, a:end], 8) 10endfunc 11 12func s:compare_lines(expect, actual) 13 call assert_equal(a:expect, a:actual) 14endfunc 15 16func s:test_windows(h, w) abort 17 call NewWindow(a:h, a:w) 18endfunc 19 20func s:close_windows() abort 21 call CloseWindow() 22endfunc 23 24func s:validate_cursor() abort 25 " update skipcol. 26 " wincol(): 27 " f_wincol 28 " -> validate_cursor 29 " -> curs_columns 30 call wincol() 31endfunc 32 33func 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& 44endfunc 45 46func 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& 81endfunc 82 83func 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() 96endfunc 97 98func 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() 114endfunc 115 116func 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() 132endfunc 133 134func 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() 147endfunc 148 149" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI 150func 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() 165endfunc 166 167" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI 168func 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() 184endfunc 185 186func 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() 216endfunc 217 218func 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() 257endfunc 258 259" This was causing a memcheck error 260func 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! 268endfunc 269 270func 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}) 283 call TermWait(buf, 50) 284 " Default colors 285 call VerifyScreenDump(buf, 'Test_relnr_colors_1', {}) 286 287 call term_sendkeys(buf, ":hi LineNrAbove ctermfg=blue\<CR>:\<CR>") 288 call VerifyScreenDump(buf, 'Test_relnr_colors_2', {}) 289 290 call term_sendkeys(buf, ":hi LineNrBelow ctermfg=green\<CR>:\<CR>") 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') 299endfunc 300