number_spec.lua (13910B)
1 local n = require('test.functional.testnvim')() 2 local Screen = require('test.functional.ui.screen') 3 4 local clear = n.clear 5 local command = n.command 6 local exec = n.exec 7 local feed = n.feed 8 9 describe("'number' and 'relativenumber'", function() 10 before_each(clear) 11 12 -- oldtest: Test_relativenumber_colors() 13 it('LineNr, LineNrAbove and LineNrBelow', function() 14 local screen = Screen.new(50, 10) 15 screen:add_extra_attr_ids { 16 [100] = { foreground = Screen.colors.WebGreen }, 17 } 18 exec([[ 19 call setline(1, range(200)) 20 111 21 set number relativenumber 22 hi LineNr guifg=red 23 ]]) 24 screen:expect([[ 25 {19: 4 }106 | 26 {19: 3 }107 | 27 {19: 2 }108 | 28 {19: 1 }109 | 29 {19:111 }^110 | 30 {19: 1 }111 | 31 {19: 2 }112 | 32 {19: 3 }113 | 33 {19: 4 }114 | 34 | 35 ]]) 36 command('hi LineNrAbove guifg=blue') 37 screen:expect([[ 38 {18: 4 }106 | 39 {18: 3 }107 | 40 {18: 2 }108 | 41 {18: 1 }109 | 42 {19:111 }^110 | 43 {19: 1 }111 | 44 {19: 2 }112 | 45 {19: 3 }113 | 46 {19: 4 }114 | 47 | 48 ]]) 49 command('hi LineNrBelow guifg=green') 50 screen:expect([[ 51 {18: 4 }106 | 52 {18: 3 }107 | 53 {18: 2 }108 | 54 {18: 1 }109 | 55 {19:111 }^110 | 56 {100: 1 }111 | 57 {100: 2 }112 | 58 {100: 3 }113 | 59 {100: 4 }114 | 60 | 61 ]]) 62 command('hi clear LineNrAbove') 63 screen:expect([[ 64 {19: 4 }106 | 65 {19: 3 }107 | 66 {19: 2 }108 | 67 {19: 1 }109 | 68 {19:111 }^110 | 69 {100: 1 }111 | 70 {100: 2 }112 | 71 {100: 3 }113 | 72 {100: 4 }114 | 73 | 74 ]]) 75 end) 76 77 -- oldtest: Test_relativenumber_colors_wrapped() 78 it('LineNr, LineNrAbove and LineNrBelow with wrapped lines', function() 79 local screen = Screen.new(50, 20) 80 screen:add_extra_attr_ids { 81 [100] = { foreground = Screen.colors.Gray0, background = Screen.colors.Red }, 82 [101] = { foreground = Screen.colors.Gray0, background = Screen.colors.Blue1 }, 83 [102] = { foreground = Screen.colors.Gray0, background = Screen.colors.WebGreen }, 84 } 85 exec([[ 86 set display=lastline scrolloff=0 87 call setline(1, range(200)->map('v:val->string()->repeat(40)')) 88 111 89 set number relativenumber 90 hi LineNr guibg=red guifg=black 91 hi LineNrAbove guibg=blue guifg=black 92 hi LineNrBelow guibg=green guifg=black 93 ]]) 94 screen:expect([[ 95 {101: 2 }1081081081081081081081081081081081081081081081| 96 {101: }0810810810810810810810810810810810810810810810| 97 {101: }8108108108108108108108108108 | 98 {101: 1 }1091091091091091091091091091091091091091091091| 99 {101: }0910910910910910910910910910910910910910910910| 100 {101: }9109109109109109109109109109 | 101 {100:111 }^1101101101101101101101101101101101101101101101| 102 {100: }1011011011011011011011011011011011011011011011| 103 {100: }0110110110110110110110110110 | 104 {102: 1 }1111111111111111111111111111111111111111111111| 105 {102: }1111111111111111111111111111111111111111111111| 106 {102: }1111111111111111111111111111 | 107 {102: 2 }1121121121121121121121121121121121121121121121| 108 {102: }1211211211211211211211211211211211211211211211| 109 {102: }2112112112112112112112112112 | 110 {102: 3 }1131131131131131131131131131131131131131131131| 111 {102: }1311311311311311311311311311311311311311311311| 112 {102: }3113113113113113113113113113 | 113 {102: 4 }1141141141141141141141141141141141141141141{1:@@@}| 114 | 115 ]]) 116 feed('k') 117 screen:expect([[ 118 {101: 1 }1081081081081081081081081081081081081081081081| 119 {101: }0810810810810810810810810810810810810810810810| 120 {101: }8108108108108108108108108108 | 121 {100:110 }^1091091091091091091091091091091091091091091091| 122 {100: }0910910910910910910910910910910910910910910910| 123 {100: }9109109109109109109109109109 | 124 {102: 1 }1101101101101101101101101101101101101101101101| 125 {102: }1011011011011011011011011011011011011011011011| 126 {102: }0110110110110110110110110110 | 127 {102: 2 }1111111111111111111111111111111111111111111111| 128 {102: }1111111111111111111111111111111111111111111111| 129 {102: }1111111111111111111111111111 | 130 {102: 3 }1121121121121121121121121121121121121121121121| 131 {102: }1211211211211211211211211211211211211211211211| 132 {102: }2112112112112112112112112112 | 133 {102: 4 }1131131131131131131131131131131131131131131131| 134 {102: }1311311311311311311311311311311311311311311311| 135 {102: }3113113113113113113113113113 | 136 {102: 5 }1141141141141141141141141141141141141141141{1:@@@}| 137 | 138 ]]) 139 feed('2j') 140 screen:expect([[ 141 {101: 3 }1081081081081081081081081081081081081081081081| 142 {101: }0810810810810810810810810810810810810810810810| 143 {101: }8108108108108108108108108108 | 144 {101: 2 }1091091091091091091091091091091091091091091091| 145 {101: }0910910910910910910910910910910910910910910910| 146 {101: }9109109109109109109109109109 | 147 {101: 1 }1101101101101101101101101101101101101101101101| 148 {101: }1011011011011011011011011011011011011011011011| 149 {101: }0110110110110110110110110110 | 150 {100:112 }^1111111111111111111111111111111111111111111111| 151 {100: }1111111111111111111111111111111111111111111111| 152 {100: }1111111111111111111111111111 | 153 {102: 1 }1121121121121121121121121121121121121121121121| 154 {102: }1211211211211211211211211211211211211211211211| 155 {102: }2112112112112112112112112112 | 156 {102: 2 }1131131131131131131131131131131131131131131131| 157 {102: }1311311311311311311311311311311311311311311311| 158 {102: }3113113113113113113113113113 | 159 {102: 3 }1141141141141141141141141141141141141141141{1:@@@}| 160 | 161 ]]) 162 feed('2j') 163 screen:expect([[ 164 {101: 5 }1081081081081081081081081081081081081081081081| 165 {101: }0810810810810810810810810810810810810810810810| 166 {101: }8108108108108108108108108108 | 167 {101: 4 }1091091091091091091091091091091091091091091091| 168 {101: }0910910910910910910910910910910910910910910910| 169 {101: }9109109109109109109109109109 | 170 {101: 3 }1101101101101101101101101101101101101101101101| 171 {101: }1011011011011011011011011011011011011011011011| 172 {101: }0110110110110110110110110110 | 173 {101: 2 }1111111111111111111111111111111111111111111111| 174 {101: }1111111111111111111111111111111111111111111111| 175 {101: }1111111111111111111111111111 | 176 {101: 1 }1121121121121121121121121121121121121121121121| 177 {101: }1211211211211211211211211211211211211211211211| 178 {101: }2112112112112112112112112112 | 179 {100:114 }^1131131131131131131131131131131131131131131131| 180 {100: }1311311311311311311311311311311311311311311311| 181 {100: }3113113113113113113113113113 | 182 {102: 1 }1141141141141141141141141141141141141141141{1:@@@}| 183 | 184 ]]) 185 feed('k') 186 screen:expect([[ 187 {101: 4 }1081081081081081081081081081081081081081081081| 188 {101: }0810810810810810810810810810810810810810810810| 189 {101: }8108108108108108108108108108 | 190 {101: 3 }1091091091091091091091091091091091091091091091| 191 {101: }0910910910910910910910910910910910910910910910| 192 {101: }9109109109109109109109109109 | 193 {101: 2 }1101101101101101101101101101101101101101101101| 194 {101: }1011011011011011011011011011011011011011011011| 195 {101: }0110110110110110110110110110 | 196 {101: 1 }1111111111111111111111111111111111111111111111| 197 {101: }1111111111111111111111111111111111111111111111| 198 {101: }1111111111111111111111111111 | 199 {100:113 }^1121121121121121121121121121121121121121121121| 200 {100: }1211211211211211211211211211211211211211211211| 201 {100: }2112112112112112112112112112 | 202 {102: 1 }1131131131131131131131131131131131131131131131| 203 {102: }1311311311311311311311311311311311311311311311| 204 {102: }3113113113113113113113113113 | 205 {102: 2 }1141141141141141141141141141141141141141141{1:@@@}| 206 | 207 ]]) 208 end) 209 210 -- oldtest: Test_relativenumber_callback() 211 it('relative line numbers are updated if cursor is moved from timer', function() 212 local screen = Screen.new(50, 8) 213 exec([[ 214 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) 215 set relativenumber 216 call cursor(4, 1) 217 218 func Func(timer) 219 call cursor(1, 1) 220 endfunc 221 ]]) 222 screen:expect([[ 223 {8: 3 }aaaaa | 224 {8: 2 }bbbbb | 225 {8: 1 }ccccc | 226 {8: 0 }^ddddd | 227 {1:~ }|*3 228 | 229 ]]) 230 command([[call timer_start(300, 'Func')]]) 231 screen:expect_unchanged(false, 100) 232 screen:expect([[ 233 {8: 0 }^aaaaa | 234 {8: 1 }bbbbb | 235 {8: 2 }ccccc | 236 {8: 3 }ddddd | 237 {1:~ }|*3 238 | 239 ]]) 240 end) 241 242 -- oldtest: Test_number_insert_delete_lines() 243 it('line numbers are updated when deleting/inserting lines', function() 244 local screen = Screen.new(50, 8) 245 exec([[ 246 call setline(1, range(1, 7)) 247 set number 248 call cursor(2, 1) 249 ]]) 250 local snapshot1 = [[ 251 {8: 1 }1 | 252 {8: 2 }^2 | 253 {8: 3 }3 | 254 {8: 4 }4 | 255 {8: 5 }5 | 256 {8: 6 }6 | 257 {8: 7 }7 | 258 | 259 ]] 260 screen:expect(snapshot1) 261 feed('dd') 262 screen:expect([[ 263 {8: 1 }1 | 264 {8: 2 }^3 | 265 {8: 3 }4 | 266 {8: 4 }5 | 267 {8: 5 }6 | 268 {8: 6 }7 | 269 {1:~ }| 270 | 271 ]]) 272 feed('P') 273 screen:expect(snapshot1) 274 feed('2dd') 275 screen:expect([[ 276 {8: 1 }1 | 277 {8: 2 }^4 | 278 {8: 3 }5 | 279 {8: 4 }6 | 280 {8: 5 }7 | 281 {1:~ }|*2 282 | 283 ]]) 284 feed('P') 285 screen:expect(snapshot1) 286 end) 287 end)