Bram Moolenaar | d5e3cc1 | 2019-08-12 14:38:02 +0200 | [diff] [blame] | 1 | " Test shifting lines with :> and :< |
| 2 | |
| 3 | source check.vim |
| 4 | |
| 5 | func Test_ex_shift_right() |
| 6 | set shiftwidth=2 |
| 7 | |
| 8 | " shift right current line. |
| 9 | call setline(1, range(1, 5)) |
| 10 | 2 |
| 11 | > |
| 12 | 3 |
| 13 | >> |
| 14 | call assert_equal(['1', |
| 15 | \ ' 2', |
| 16 | \ ' 3', |
| 17 | \ '4', |
| 18 | \ '5'], getline(1, '$')) |
| 19 | |
| 20 | " shift right with range. |
| 21 | call setline(1, range(1, 4)) |
| 22 | 2,3>> |
| 23 | call assert_equal(['1', |
| 24 | \ ' 2', |
| 25 | \ ' 3', |
| 26 | \ '4', |
| 27 | \ '5'], getline(1, '$')) |
| 28 | |
| 29 | " shift right with range and count. |
| 30 | call setline(1, range(1, 4)) |
| 31 | 2>3 |
| 32 | call assert_equal(['1', |
| 33 | \ ' 2', |
| 34 | \ ' 3', |
| 35 | \ ' 4', |
| 36 | \ '5'], getline(1, '$')) |
| 37 | |
| 38 | bw! |
| 39 | set shiftwidth& |
| 40 | endfunc |
| 41 | |
| 42 | func Test_ex_shift_left() |
| 43 | set shiftwidth=2 |
| 44 | |
| 45 | call setline(1, range(1, 5)) |
| 46 | %>>> |
| 47 | |
| 48 | " left shift current line. |
| 49 | 2< |
| 50 | 3<< |
| 51 | 4<<<<< |
| 52 | call assert_equal([' 1', |
| 53 | \ ' 2', |
| 54 | \ ' 3', |
| 55 | \ '4', |
| 56 | \ ' 5'], getline(1, '$')) |
| 57 | |
| 58 | " shift right with range. |
| 59 | call setline(1, range(1, 5)) |
| 60 | %>>> |
| 61 | 2,3<< |
| 62 | call assert_equal([' 1', |
| 63 | \ ' 2', |
| 64 | \ ' 3', |
| 65 | \ ' 4', |
| 66 | \ ' 5'], getline(1, '$')) |
| 67 | |
| 68 | " shift right with range and count. |
| 69 | call setline(1, range(1, 5)) |
| 70 | %>>> |
| 71 | 2<<3 |
| 72 | call assert_equal([' 1', |
| 73 | \ ' 2', |
| 74 | \ ' 3', |
| 75 | \ ' 4', |
| 76 | \ ' 5'], getline(1, '$')) |
| 77 | |
| 78 | bw! |
| 79 | set shiftwidth& |
| 80 | endfunc |
| 81 | |
| 82 | func Test_ex_shift_rightleft() |
| 83 | CheckFeature rightleft |
| 84 | |
| 85 | set shiftwidth=2 rightleft |
| 86 | |
| 87 | call setline(1, range(1, 4)) |
| 88 | 2,3<< |
| 89 | call assert_equal(['1', |
| 90 | \ ' 2', |
| 91 | \ ' 3', |
| 92 | \ '4'], getline(1, '$')) |
| 93 | |
| 94 | 3,4> |
| 95 | call assert_equal(['1', |
| 96 | \ ' 2', |
| 97 | \ ' 3', |
| 98 | \ '4'], getline(1, '$')) |
| 99 | |
| 100 | bw! |
| 101 | set rightleft& shiftwidth& |
| 102 | endfunc |
| 103 | |
| 104 | func Test_ex_shift_errors() |
| 105 | call assert_fails('><', 'E488:') |
| 106 | call assert_fails('<>', 'E488:') |
| 107 | |
| 108 | call assert_fails('>!', 'E477:') |
| 109 | call assert_fails('<!', 'E477:') |
| 110 | |
| 111 | call assert_fails('2,1>', 'E493:') |
| 112 | call assert_fails('2,1<', 'E493:') |
| 113 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 114 | |
Gary Johnson | eed63f9 | 2024-12-09 21:03:48 +0100 | [diff] [blame] | 115 | " Test inserting a backspace at the start of a line. |
| 116 | " |
| 117 | " This is to verify the proper behavior of tabstop_start() as called from |
| 118 | " ins_bs(). |
| 119 | " |
| 120 | func Test_shift_ins_bs() |
| 121 | set backspace=indent,start |
| 122 | set softtabstop=11 |
| 123 | |
| 124 | call setline(1, repeat(" ", 33) . "word") |
| 125 | exe "norm! I\<BS>" |
| 126 | call assert_equal(repeat(" ", 22) . "word", getline(1)) |
| 127 | call setline(1, repeat(" ", 23) . "word") |
| 128 | exe "norm! I\<BS>" |
| 129 | call assert_equal(repeat(" ", 22) . "word", getline(1)) |
| 130 | exe "norm! I\<BS>" |
| 131 | call assert_equal(repeat(" ", 11) . "word", getline(1)) |
| 132 | |
| 133 | set backspace& softtabstop& |
| 134 | bw! |
| 135 | endfunc |
| 136 | |
| 137 | " Test inserting a backspace at the start of a line, with 'varsofttabstop'. |
| 138 | " |
| 139 | func Test_shift_ins_bs_vartabs() |
| 140 | CheckFeature vartabs |
| 141 | set backspace=indent,start |
| 142 | set varsofttabstop=13,11,7 |
| 143 | |
| 144 | call setline(1, repeat(" ", 44) . "word") |
| 145 | exe "norm! I\<BS>" |
| 146 | call assert_equal(repeat(" ", 38) . "word", getline(1)) |
| 147 | call setline(1, repeat(" ", 39) . "word") |
| 148 | exe "norm! I\<BS>" |
| 149 | call assert_equal(repeat(" ", 38) . "word", getline(1)) |
| 150 | exe "norm! I\<BS>" |
| 151 | call assert_equal(repeat(" ", 31) . "word", getline(1)) |
| 152 | exe "norm! I\<BS>" |
| 153 | call assert_equal(repeat(" ", 24) . "word", getline(1)) |
| 154 | exe "norm! I\<BS>" |
| 155 | call assert_equal(repeat(" ", 13) . "word", getline(1)) |
| 156 | exe "norm! I\<BS>" |
| 157 | call assert_equal( "word", getline(1)) |
| 158 | exe "norm! I\<BS>" |
| 159 | call assert_equal( "word", getline(1)) |
| 160 | |
| 161 | set backspace& varsofttabstop& |
| 162 | bw! |
| 163 | endfunc |
| 164 | |
| 165 | " Test the >> and << normal-mode commands. |
| 166 | " |
| 167 | func Test_shift_norm() |
| 168 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 169 | " results. |
| 170 | |
| 171 | set shiftwidth=5 |
| 172 | set tabstop=7 |
| 173 | |
| 174 | call setline(1, " word") |
| 175 | |
| 176 | " Shift by 'shiftwidth' right and left. |
| 177 | |
| 178 | norm! >> |
| 179 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 180 | norm! >> |
| 181 | call assert_equal(repeat(" ", 12) . "word", getline(1)) |
| 182 | norm! >> |
| 183 | call assert_equal(repeat(" ", 17) . "word", getline(1)) |
| 184 | |
| 185 | norm! << |
| 186 | call assert_equal(repeat(" ", 12) . "word", getline(1)) |
| 187 | norm! << |
| 188 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 189 | norm! << |
| 190 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 191 | norm! << |
| 192 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 193 | |
| 194 | " Shift by 'tabstop' right and left. |
| 195 | |
| 196 | set shiftwidth=0 |
| 197 | call setline(1, " word") |
| 198 | |
| 199 | norm! >> |
| 200 | call assert_equal(repeat(" ", 9) . "word", getline(1)) |
| 201 | norm! >> |
| 202 | call assert_equal(repeat(" ", 16) . "word", getline(1)) |
| 203 | norm! >> |
| 204 | call assert_equal(repeat(" ", 23) . "word", getline(1)) |
| 205 | |
| 206 | norm! << |
| 207 | call assert_equal(repeat(" ", 16) . "word", getline(1)) |
| 208 | norm! << |
| 209 | call assert_equal(repeat(" ", 9) . "word", getline(1)) |
| 210 | norm! << |
| 211 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 212 | norm! << |
| 213 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 214 | |
| 215 | set expandtab& shiftwidth& tabstop& |
| 216 | bw! |
| 217 | endfunc |
| 218 | |
| 219 | " Test the >> and << normal-mode commands, with 'vartabstop'. |
| 220 | " |
| 221 | func Test_shift_norm_vartabs() |
| 222 | CheckFeature vartabs |
| 223 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 224 | " results. |
| 225 | |
| 226 | set shiftwidth=0 |
| 227 | set vartabstop=19,17,11 |
| 228 | |
| 229 | " Shift by 'vartabstop' right and left. |
| 230 | |
| 231 | call setline(1, " word") |
| 232 | |
| 233 | norm! >> |
| 234 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 235 | norm! >> |
| 236 | call assert_equal(repeat(" ", 38) . "word", getline(1)) |
| 237 | norm! >> |
| 238 | call assert_equal(repeat(" ", 49) . "word", getline(1)) |
| 239 | norm! >> |
| 240 | call assert_equal(repeat(" ", 60) . "word", getline(1)) |
| 241 | |
| 242 | norm! << |
| 243 | call assert_equal(repeat(" ", 49) . "word", getline(1)) |
| 244 | norm! << |
| 245 | call assert_equal(repeat(" ", 38) . "word", getline(1)) |
| 246 | norm! << |
| 247 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 248 | norm! << |
| 249 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 250 | norm! << |
| 251 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 252 | |
| 253 | set expandtab& shiftwidth& vartabstop& |
| 254 | bw! |
| 255 | endfunc |
| 256 | |
| 257 | " Test the >> and << normal-mode commands with 'shiftround'. |
| 258 | " |
| 259 | func Test_shift_norm_round() |
| 260 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 261 | " results. |
| 262 | |
| 263 | set shiftround |
| 264 | set shiftwidth=5 |
| 265 | set tabstop=7 |
| 266 | |
| 267 | call setline(1, "word") |
| 268 | |
| 269 | " Shift by 'shiftwidth' right and left. |
| 270 | |
| 271 | exe "norm! I " |
| 272 | norm! >> |
| 273 | call assert_equal(repeat(" ", 5) . "word", getline(1)) |
| 274 | exe "norm! I " |
| 275 | norm! >> |
| 276 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 277 | exe "norm! I " |
| 278 | norm! >> |
| 279 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 280 | norm! >> |
| 281 | call assert_equal(repeat(" ", 20) . "word", getline(1)) |
| 282 | norm! >> |
| 283 | call assert_equal(repeat(" ", 25) . "word", getline(1)) |
| 284 | |
| 285 | norm! << |
| 286 | call assert_equal(repeat(" ", 20) . "word", getline(1)) |
| 287 | norm! << |
| 288 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 289 | norm! << |
| 290 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 291 | exe "norm! I " |
| 292 | norm! << |
| 293 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 294 | |
| 295 | call setline(1, repeat(" ", 7) . "word") |
| 296 | norm! << |
| 297 | call assert_equal(repeat(" ", 5) . "word", getline(1)) |
| 298 | norm! << |
| 299 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 300 | norm! << |
| 301 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 302 | call setline(1, repeat(" ", 2) . "word") |
| 303 | norm! << |
| 304 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 305 | |
| 306 | " Shift by 'tabstop' right and left. |
| 307 | |
| 308 | set shiftwidth=0 |
| 309 | call setline(1, "word") |
| 310 | |
| 311 | exe "norm! I " |
| 312 | norm! >> |
| 313 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 314 | exe "norm! I " |
| 315 | norm! >> |
| 316 | call assert_equal(repeat(" ", 14) . "word", getline(1)) |
| 317 | exe "norm! I " |
| 318 | norm! >> |
| 319 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 320 | norm! >> |
| 321 | call assert_equal(repeat(" ", 28) . "word", getline(1)) |
| 322 | norm! >> |
| 323 | call assert_equal(repeat(" ", 35) . "word", getline(1)) |
| 324 | |
| 325 | norm! << |
| 326 | call assert_equal(repeat(" ", 28) . "word", getline(1)) |
| 327 | norm! << |
| 328 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 329 | norm! << |
| 330 | call assert_equal(repeat(" ", 14) . "word", getline(1)) |
| 331 | exe "norm! I " |
| 332 | norm! << |
| 333 | call assert_equal(repeat(" ", 14) . "word", getline(1)) |
| 334 | |
| 335 | call setline(1, repeat(" ", 9) . "word") |
| 336 | norm! << |
| 337 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 338 | norm! << |
| 339 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 340 | norm! << |
| 341 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 342 | call setline(1, repeat(" ", 2) . "word") |
| 343 | norm! << |
| 344 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 345 | |
| 346 | set expandtab& shiftround& shiftwidth& tabstop& |
| 347 | bw! |
| 348 | endfunc |
| 349 | |
| 350 | " Test the >> and << normal-mode commands with 'shiftround' and 'vartabstop'. |
| 351 | " |
| 352 | func Test_shift_norm_round_vartabs() |
| 353 | CheckFeature vartabs |
| 354 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 355 | " results. |
| 356 | |
| 357 | set shiftround |
| 358 | set shiftwidth=0 |
| 359 | set vartabstop=19,17,11 |
| 360 | |
| 361 | " Shift by 'vartabstop' right and left. |
| 362 | |
| 363 | call setline(1, "word") |
| 364 | |
| 365 | exe "norm! I " |
| 366 | norm! >> |
| 367 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 368 | exe "norm! I " |
| 369 | norm! >> |
| 370 | call assert_equal(repeat(" ", 36) . "word", getline(1)) |
| 371 | exe "norm! I " |
| 372 | norm! >> |
| 373 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 374 | exe "norm! I " |
| 375 | norm! >> |
| 376 | call assert_equal(repeat(" ", 58) . "word", getline(1)) |
| 377 | |
| 378 | exe "norm! I " |
| 379 | norm! << |
| 380 | call assert_equal(repeat(" ", 58) . "word", getline(1)) |
| 381 | norm! << |
| 382 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 383 | norm! << |
| 384 | call assert_equal(repeat(" ", 36) . "word", getline(1)) |
| 385 | norm! << |
| 386 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 387 | exe "norm! I " |
| 388 | norm! << |
| 389 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 390 | norm! << |
| 391 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 392 | exe "norm! I " |
| 393 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 394 | norm! << |
| 395 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 396 | norm! << |
| 397 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 398 | |
| 399 | set expandtab& shiftround& shiftwidth& vartabstop& |
| 400 | bw! |
| 401 | endfunc |
| 402 | |
| 403 | " Test the V> and V< visual-mode commands. |
| 404 | " |
| 405 | " See ":help v_<" and ":help v_>". See also the last paragraph of "3. Simple |
| 406 | " changes", ":help simple-change", immediately above "4. Complex changes", |
| 407 | " ":help complex-change". |
| 408 | " |
| 409 | func Test_shift_vis() |
| 410 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 411 | " results. |
| 412 | |
| 413 | set shiftwidth=5 |
| 414 | set tabstop=7 |
| 415 | |
| 416 | call setline(1, " word") |
| 417 | |
| 418 | " Shift by 'shiftwidth' right and left. |
| 419 | |
| 420 | norm! V> |
| 421 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 422 | norm! V2> |
| 423 | call assert_equal(repeat(" ", 17) . "word", getline(1)) |
| 424 | norm! V3> |
| 425 | call assert_equal(repeat(" ", 32) . "word", getline(1)) |
| 426 | |
| 427 | norm! V< |
| 428 | call assert_equal(repeat(" ", 27) . "word", getline(1)) |
| 429 | norm! V2< |
| 430 | call assert_equal(repeat(" ", 17) . "word", getline(1)) |
| 431 | norm! V3< |
| 432 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 433 | norm! V< |
| 434 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 435 | norm! V3< |
| 436 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 437 | |
| 438 | " Shift by 'tabstop' right and left. |
| 439 | |
| 440 | set shiftwidth=0 |
| 441 | call setline(1, " word") |
| 442 | |
| 443 | norm! V> |
| 444 | call assert_equal(repeat(" ", 9) . "word", getline(1)) |
| 445 | norm! V2> |
| 446 | call assert_equal(repeat(" ", 23) . "word", getline(1)) |
| 447 | norm! V3> |
| 448 | call assert_equal(repeat(" ", 44) . "word", getline(1)) |
| 449 | |
| 450 | norm! V< |
| 451 | call assert_equal(repeat(" ", 37) . "word", getline(1)) |
| 452 | norm! V2< |
| 453 | call assert_equal(repeat(" ", 23) . "word", getline(1)) |
| 454 | norm! V3< |
| 455 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 456 | norm! V< |
| 457 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 458 | norm! V3< |
| 459 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 460 | |
| 461 | set expandtab& shiftwidth& tabstop& |
| 462 | bw! |
| 463 | endfunc |
| 464 | |
| 465 | " Test the V> and V< visual-mode commands, with 'vartabstop'. |
| 466 | " |
| 467 | " See ":help v_<" and ":help v_>". See also the last paragraph of "3. Simple |
| 468 | " changes", ":help simple-change", immediately above "4. Complex changes", |
| 469 | " ":help complex-change". |
| 470 | " |
| 471 | func Test_shift_vis_vartabs() |
| 472 | CheckFeature vartabs |
| 473 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 474 | " results. |
| 475 | |
| 476 | set shiftwidth=0 |
| 477 | set vartabstop=19,17,11 |
| 478 | |
| 479 | " Shift by 'vartabstop' right and left. |
| 480 | |
| 481 | call setline(1, " word") |
| 482 | |
| 483 | norm! V> |
| 484 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 485 | norm! V2> |
| 486 | call assert_equal(repeat(" ", 49) . "word", getline(1)) |
| 487 | norm! V3> |
| 488 | call assert_equal(repeat(" ", 82) . "word", getline(1)) |
| 489 | |
| 490 | norm! V< |
| 491 | call assert_equal(repeat(" ", 71) . "word", getline(1)) |
| 492 | norm! V2< |
| 493 | call assert_equal(repeat(" ", 49) . "word", getline(1)) |
| 494 | norm! V3< |
| 495 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 496 | norm! V< |
| 497 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 498 | norm! V3< |
| 499 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 500 | |
| 501 | set expandtab& shiftwidth& vartabstop& |
| 502 | bw! |
| 503 | endfunc |
| 504 | |
| 505 | " Test the V> and V< visual-mode commands with 'shiftround'. |
| 506 | " |
| 507 | func Test_shift_vis_round() |
| 508 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 509 | " results. |
| 510 | |
| 511 | set shiftround |
| 512 | set shiftwidth=5 |
| 513 | set tabstop=7 |
| 514 | |
| 515 | call setline(1, "word") |
| 516 | |
| 517 | " Shift by 'shiftwidth' right and left. |
| 518 | |
| 519 | exe "norm! I " |
| 520 | norm! V> |
| 521 | call assert_equal(repeat(" ", 5) . "word", getline(1)) |
| 522 | exe "norm! I " |
| 523 | norm! V2> |
| 524 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 525 | exe "norm! I " |
| 526 | norm! V3> |
| 527 | call assert_equal(repeat(" ", 30) . "word", getline(1)) |
| 528 | |
| 529 | exe "norm! I " |
| 530 | norm! V2< |
| 531 | call assert_equal(repeat(" ", 25) . "word", getline(1)) |
| 532 | norm! V3< |
| 533 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 534 | norm! V< |
| 535 | call assert_equal(repeat(" ", 5) . "word", getline(1)) |
| 536 | norm! V< |
| 537 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 538 | norm! V3< |
| 539 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 540 | |
| 541 | " Shift by 'tabstop' right and left. |
| 542 | |
| 543 | set shiftwidth=0 |
| 544 | call setline(1, "word") |
| 545 | |
| 546 | exe "norm! I " |
| 547 | norm! V> |
| 548 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 549 | exe "norm! I " |
| 550 | norm! V2> |
| 551 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 552 | exe "norm! I " |
| 553 | norm! V3> |
| 554 | call assert_equal(repeat(" ", 42) . "word", getline(1)) |
| 555 | |
| 556 | exe "norm! I " |
| 557 | norm! V< |
| 558 | call assert_equal(repeat(" ", 42) . "word", getline(1)) |
| 559 | norm! V< |
| 560 | call assert_equal(repeat(" ", 35) . "word", getline(1)) |
| 561 | norm! V2< |
| 562 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 563 | norm! V3< |
| 564 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 565 | norm! V< |
| 566 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 567 | norm! V3< |
| 568 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 569 | |
| 570 | call setline(1, " word") |
| 571 | norm! V< |
| 572 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 573 | |
| 574 | |
| 575 | set expandtab& shiftround& shiftwidth& tabstop& |
| 576 | bw! |
| 577 | endfunc |
| 578 | |
| 579 | " Test the V> and V< visual-mode commands with 'shiftround' and 'vartabstop'. |
| 580 | " |
| 581 | func Test_shift_vis_round_vartabs() |
| 582 | CheckFeature vartabs |
| 583 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 584 | " results. |
| 585 | |
| 586 | set shiftround |
| 587 | set shiftwidth=0 |
| 588 | set vartabstop=19,17,11 |
| 589 | |
| 590 | " Shift by 'vartabstop' right and left. |
| 591 | |
| 592 | call setline(1, "word") |
| 593 | |
| 594 | exe "norm! I " |
| 595 | norm! V> |
| 596 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 597 | exe "norm! I " |
| 598 | norm! V3> |
| 599 | call assert_equal(repeat(" ", 58) . "word", getline(1)) |
| 600 | |
| 601 | exe "norm! I " |
| 602 | norm! V2< |
| 603 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 604 | exe "norm! I " |
| 605 | norm! V3< |
| 606 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 607 | exe "norm! I " |
| 608 | norm! V3< |
| 609 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 610 | exe "norm! I " |
| 611 | norm! V< |
| 612 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 613 | |
| 614 | set expandtab& shiftround& shiftwidth& vartabstop& |
| 615 | bw! |
| 616 | endfunc |
| 617 | |
| 618 | " Test the :> and :< ex-mode commands. |
| 619 | " |
| 620 | func Test_shift_ex() |
| 621 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 622 | " results. |
| 623 | |
| 624 | set shiftwidth=5 |
| 625 | set tabstop=7 |
| 626 | |
| 627 | call setline(1, " word") |
| 628 | |
| 629 | " Shift by 'shiftwidth' right and left. |
| 630 | |
| 631 | > |
| 632 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 633 | >> |
| 634 | call assert_equal(repeat(" ", 17) . "word", getline(1)) |
| 635 | >>> |
| 636 | call assert_equal(repeat(" ", 32) . "word", getline(1)) |
| 637 | |
| 638 | <<<< |
| 639 | call assert_equal(repeat(" ", 12) . "word", getline(1)) |
| 640 | < |
| 641 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 642 | < |
| 643 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 644 | < |
| 645 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 646 | |
| 647 | " Shift by 'tabstop' right and left. |
| 648 | |
| 649 | set shiftwidth=0 |
| 650 | call setline(1, " word") |
| 651 | |
| 652 | > |
| 653 | call assert_equal(repeat(" ", 9) . "word", getline(1)) |
| 654 | >> |
| 655 | call assert_equal(repeat(" ", 23) . "word", getline(1)) |
| 656 | >>> |
| 657 | call assert_equal(repeat(" ", 44) . "word", getline(1)) |
| 658 | |
| 659 | <<<< |
| 660 | call assert_equal(repeat(" ", 16) . "word", getline(1)) |
| 661 | << |
| 662 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 663 | < |
| 664 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 665 | |
| 666 | set expandtab& shiftwidth& tabstop& |
| 667 | bw! |
| 668 | endfunc |
| 669 | |
| 670 | " Test the :> and :< ex-mode commands, with vartabstop. |
| 671 | " |
| 672 | func Test_shift_ex_vartabs() |
| 673 | CheckFeature vartabs |
| 674 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 675 | " results. |
| 676 | |
| 677 | set shiftwidth=0 |
| 678 | set vartabstop=19,17,11 |
| 679 | |
| 680 | " Shift by 'vartabstop' right and left. |
| 681 | |
| 682 | call setline(1, " word") |
| 683 | |
| 684 | > |
| 685 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 686 | >> |
| 687 | call assert_equal(repeat(" ", 49) . "word", getline(1)) |
| 688 | >>> |
| 689 | call assert_equal(repeat(" ", 82) . "word", getline(1)) |
| 690 | |
| 691 | <<<< |
| 692 | call assert_equal(repeat(" ", 38) . "word", getline(1)) |
| 693 | << |
| 694 | call assert_equal(repeat(" ", 2) . "word", getline(1)) |
| 695 | < |
| 696 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 697 | |
| 698 | set expandtab& shiftwidth& vartabstop& |
| 699 | bw! |
| 700 | endfunc |
| 701 | |
| 702 | " Test the :> and :< ex-mode commands with 'shiftround'. |
| 703 | " |
| 704 | func Test_shift_ex_round() |
| 705 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 706 | " results. |
| 707 | |
| 708 | set shiftround |
| 709 | set shiftwidth=5 |
| 710 | set tabstop=7 |
| 711 | |
| 712 | call setline(1, "word") |
| 713 | |
| 714 | " Shift by 'shiftwidth' right and left. |
| 715 | |
| 716 | exe "norm! I " |
| 717 | > |
| 718 | call assert_equal(repeat(" ", 5) . "word", getline(1)) |
| 719 | exe "norm! I " |
| 720 | >> |
| 721 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 722 | exe "norm! I " |
| 723 | >>> |
| 724 | call assert_equal(repeat(" ", 30) . "word", getline(1)) |
| 725 | |
| 726 | exe "norm! I " |
| 727 | <<<< |
| 728 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 729 | exe "norm! I " |
| 730 | << |
| 731 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 732 | << |
| 733 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 734 | >> |
| 735 | <<< |
| 736 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 737 | |
| 738 | " Shift by 'tabstop' right and left. |
| 739 | |
| 740 | set shiftwidth=0 |
| 741 | call setline(1, "word") |
| 742 | |
| 743 | exe "norm! I " |
| 744 | > |
| 745 | call assert_equal(repeat(" ", 7) . "word", getline(1)) |
| 746 | exe "norm! I " |
| 747 | >> |
| 748 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 749 | exe "norm! I " |
| 750 | >>> |
| 751 | call assert_equal(repeat(" ", 42) . "word", getline(1)) |
| 752 | |
| 753 | exe "norm! I " |
| 754 | <<<< |
| 755 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 756 | exe "norm! I " |
| 757 | << |
| 758 | call assert_equal(repeat(" ", 14) . "word", getline(1)) |
| 759 | exe "norm! I " |
| 760 | <<< |
| 761 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 762 | >> |
| 763 | <<< |
| 764 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 765 | |
| 766 | set expandtab& shiftround& shiftwidth& tabstop& |
| 767 | bw! |
| 768 | endfunc |
| 769 | |
| 770 | " Test the :> and :< ex-mode commands with 'shiftround' and 'vartabstop'. |
| 771 | " |
| 772 | func Test_shift_ex_round_vartabs() |
| 773 | CheckFeature vartabs |
| 774 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 775 | " results. |
| 776 | |
| 777 | set shiftround |
| 778 | set shiftwidth=0 |
| 779 | set vartabstop=19,17,11 |
| 780 | |
| 781 | " Shift by 'vartabstop' right and left. |
| 782 | |
| 783 | call setline(1, "word") |
| 784 | |
| 785 | exe "norm! I " |
| 786 | > |
| 787 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 788 | exe "norm! I " |
| 789 | >> |
| 790 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 791 | >>> |
| 792 | call assert_equal(repeat(" ", 80) . "word", getline(1)) |
| 793 | |
| 794 | <<<< |
| 795 | call assert_equal(repeat(" ", 36) . "word", getline(1)) |
| 796 | exe "norm! I " |
| 797 | << |
| 798 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 799 | exe "norm! I " |
| 800 | << |
| 801 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 802 | < |
| 803 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 804 | |
| 805 | set expandtab& shiftround& shiftwidth& vartabstop& |
| 806 | bw! |
| 807 | endfunc |
| 808 | |
| 809 | " Test shifting lines with <C-T> and <C-D>. |
| 810 | " |
| 811 | func Test_shift_ins() |
| 812 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 813 | " results. |
| 814 | |
| 815 | set shiftwidth=5 |
| 816 | set tabstop=7 |
| 817 | |
| 818 | " Shift by 'shiftwidth' right and left. |
| 819 | |
| 820 | call setline(1, repeat(" ", 7) . "word") |
| 821 | exe "norm! 9|i\<C-T>" |
| 822 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 823 | exe "norm! A\<C-T>" |
| 824 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 825 | exe "norm! I \<C-T>" |
| 826 | call assert_equal(repeat(" ", 20) . "word", getline(1)) |
| 827 | |
| 828 | exe "norm! I \<C-D>" |
| 829 | call assert_equal(repeat(" ", 20) . "word", getline(1)) |
| 830 | exe "norm! I " |
| 831 | exe "norm! 24|i\<C-D>" |
| 832 | call assert_equal(repeat(" ", 20) . "word", getline(1)) |
| 833 | exe "norm! A\<C-D>" |
| 834 | call assert_equal(repeat(" ", 15) . "word", getline(1)) |
| 835 | exe "norm! I " |
| 836 | exe "norm! A\<C-D>\<C-D>" |
| 837 | call assert_equal(repeat(" ", 10) . "word", getline(1)) |
| 838 | exe "norm! I\<C-D>\<C-D>\<C-D>" |
| 839 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 840 | exe "norm! I\<C-D>" |
| 841 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 842 | |
| 843 | " Shift by 'tabstop' right and left. |
| 844 | |
| 845 | set shiftwidth=0 |
| 846 | call setline(1, "word") |
| 847 | |
| 848 | call setline(1, repeat(" ", 9) . "word") |
| 849 | exe "norm! 11|i\<C-T>" |
| 850 | call assert_equal(repeat(" ", 14) . "word", getline(1)) |
| 851 | exe "norm! A\<C-T>" |
| 852 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 853 | exe "norm! I \<C-T>" |
| 854 | call assert_equal(repeat(" ", 28) . "word", getline(1)) |
| 855 | |
| 856 | exe "norm! I \<C-D>" |
| 857 | call assert_equal(repeat(" ", 28) . "word", getline(1)) |
| 858 | exe "norm! I " |
| 859 | exe "norm! 32|i\<C-D>" |
| 860 | call assert_equal(repeat(" ", 28) . "word", getline(1)) |
| 861 | exe "norm! A\<C-D>" |
| 862 | call assert_equal(repeat(" ", 21) . "word", getline(1)) |
| 863 | exe "norm! I " |
| 864 | exe "norm! A\<C-D>\<C-D>" |
| 865 | call assert_equal(repeat(" ", 14) . "word", getline(1)) |
| 866 | exe "norm! I\<C-D>\<C-D>\<C-D>" |
| 867 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 868 | exe "norm! I\<C-D>" |
| 869 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 870 | |
| 871 | set expandtab& shiftwidth& tabstop& |
| 872 | bw! |
| 873 | endfunc |
| 874 | |
| 875 | " Test shifting lines with <C-T> and <C-D>, with 'vartabstop'. |
| 876 | " |
| 877 | func Test_shift_ins_vartabs() |
| 878 | CheckFeature vartabs |
| 879 | set expandtab " Don't want to worry about tabs vs. spaces in |
| 880 | " results. |
| 881 | |
| 882 | set shiftwidth=0 |
| 883 | set vartabstop=19,17,11 |
| 884 | |
| 885 | " Shift by 'vartabstop' right and left. |
| 886 | |
| 887 | call setline(1, "word") |
| 888 | |
| 889 | call setline(1, repeat(" ", 9) . "word") |
| 890 | exe "norm! 11|i\<C-T>" |
| 891 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 892 | exe "norm! A\<C-T>" |
| 893 | call assert_equal(repeat(" ", 36) . "word", getline(1)) |
| 894 | exe "norm! I \<C-T>" |
| 895 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 896 | |
| 897 | exe "norm! I \<C-D>" |
| 898 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 899 | exe "norm! I " |
| 900 | exe "norm! 51|i\<C-D>" |
| 901 | call assert_equal(repeat(" ", 47) . "word", getline(1)) |
| 902 | exe "norm! A\<C-D>" |
| 903 | call assert_equal(repeat(" ", 36) . "word", getline(1)) |
| 904 | exe "norm! I " |
| 905 | exe "norm! A\<C-D>\<C-D>" |
| 906 | call assert_equal(repeat(" ", 19) . "word", getline(1)) |
| 907 | exe "norm! I\<C-D>\<C-D>\<C-D>" |
| 908 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 909 | exe "norm! I\<C-D>" |
| 910 | call assert_equal(repeat(" ", 0) . "word", getline(1)) |
| 911 | |
| 912 | set expandtab& shiftwidth& vartabstop& |
| 913 | bw! |
| 914 | endfunc |
| 915 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 916 | " vim: shiftwidth=2 sts=2 expandtab |