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