blob: 71f687b7c2cd15ab60930e200a3c0f22b7426a28 [file] [log] [blame]
Bram Moolenaar8c87a2b2018-04-10 13:15:47 +02001" Test for block inserting
Bram Moolenaar8c87a2b2018-04-10 13:15:47 +02002
3func Test_blockinsert_indent()
4 new
5 filetype plugin indent on
6 setlocal sw=2 et ft=vim
7 call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']'])
8 call cursor(2, 3)
9 exe "norm! \<c-v>2jI\\ \<esc>"
10 call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'],
11 \ getline(1,'$'))
12 " reset to sane state
13 filetype off
14 bwipe!
15endfunc
16
Bram Moolenaare9b0b402021-11-27 13:28:24 +000017func Test_blockinsert_autoindent()
18 new
19 let lines =<< trim END
Bram Moolenaar47da9342022-09-27 22:18:13 +010020 vim9script
Bram Moolenaare9b0b402021-11-27 13:28:24 +000021 var d = {
22 a: () => 0,
23 b: () => 0,
24 c: () => 0,
25 }
26 END
27 call setline(1, lines)
28 filetype plugin indent on
29 setlocal sw=2 et ft=vim
30 setlocal indentkeys+=:
Bram Moolenaar47da9342022-09-27 22:18:13 +010031 exe "norm! 3Gf)\<c-v>2jA: asdf\<esc>"
Bram Moolenaare9b0b402021-11-27 13:28:24 +000032 let expected =<< trim END
Bram Moolenaar47da9342022-09-27 22:18:13 +010033 vim9script
Bram Moolenaare9b0b402021-11-27 13:28:24 +000034 var d = {
Bram Moolenaar47da9342022-09-27 22:18:13 +010035 a: (): asdf => 0,
Bram Moolenaare9b0b402021-11-27 13:28:24 +000036 b: (): asdf => 0,
37 c: (): asdf => 0,
38 }
39 END
Bram Moolenaar47da9342022-09-27 22:18:13 +010040 call assert_equal(expected, getline(1, 6))
Bram Moolenaare9b0b402021-11-27 13:28:24 +000041
Bram Moolenaar59f4f952021-11-27 22:47:43 +000042 " insert on the next column should do exactly the same
43 :%dele
44 call setline(1, lines)
Bram Moolenaar47da9342022-09-27 22:18:13 +010045 exe "norm! 3Gf)l\<c-v>2jI: asdf\<esc>"
46 call assert_equal(expected, getline(1, 6))
Bram Moolenaar59f4f952021-11-27 22:47:43 +000047
48 :%dele
49 call setline(1, lines)
50 setlocal sw=8 noet
Bram Moolenaar47da9342022-09-27 22:18:13 +010051 exe "norm! 3Gf)\<c-v>2jA: asdf\<esc>"
Bram Moolenaar59f4f952021-11-27 22:47:43 +000052 let expected =<< trim END
Bram Moolenaar47da9342022-09-27 22:18:13 +010053 vim9script
Bram Moolenaar59f4f952021-11-27 22:47:43 +000054 var d = {
Bram Moolenaar94722c52023-01-28 19:19:03 +000055 a: (): asdf => 0,
Bram Moolenaar59f4f952021-11-27 22:47:43 +000056 b: (): asdf => 0,
57 c: (): asdf => 0,
58 }
59 END
Bram Moolenaar47da9342022-09-27 22:18:13 +010060 call assert_equal(expected, getline(1, 6))
Bram Moolenaar59f4f952021-11-27 22:47:43 +000061
62 " insert on the next column should do exactly the same
63 :%dele
64 call setline(1, lines)
Bram Moolenaar47da9342022-09-27 22:18:13 +010065 exe "norm! 3Gf)l\<c-v>2jI: asdf\<esc>"
66 call assert_equal(expected, getline(1, 6))
Bram Moolenaar59f4f952021-11-27 22:47:43 +000067
Bram Moolenaare9b0b402021-11-27 13:28:24 +000068 filetype off
69 bwipe!
70endfunc
71
Bram Moolenaar35e802e2018-04-30 17:21:03 +020072func Test_blockinsert_delete()
73 new
74 let _bs = &bs
75 set bs=2
76 call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;'])
77 exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>"
78 "call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti')
79 call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"],
80 \ getline(1,'$'))
81 " reset to sane state
82 let &bs = _bs
83 bwipe!
84endfunc
Bram Moolenaar8c87a2b2018-04-10 13:15:47 +020085
Bram Moolenaar4067bd32021-06-29 18:54:35 +020086func Test_blockappend_eol_cursor()
87 new
88 " Test 1 Move 1 char left
89 call setline(1, ['aaa', 'bbb', 'ccc'])
90 exe "norm! gg$\<c-v>2jA\<left>x\<esc>"
91 call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
92 " Test 2 Move 2 chars left
93 sil %d
94 call setline(1, ['aaa', 'bbb', 'ccc'])
95 exe "norm! gg$\<c-v>2jA\<left>\<left>x\<esc>"
96 call assert_equal(['axaa', 'bxbb', 'cxcc'], getline(1, '$'))
97 " Test 3 Move 3 chars left (outside of the visual selection)
98 sil %d
99 call setline(1, ['aaa', 'bbb', 'ccc'])
100 exe "norm! ggl$\<c-v>2jA\<left>\<left>\<left>x\<esc>"
101 call assert_equal(['xaaa', 'bbb', 'ccc'], getline(1, '$'))
102 bw!
103endfunc
104
105func Test_blockappend_eol_cursor2()
106 new
107 " Test 1 Move 1 char left
108 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
109 exe "norm! gg\<c-v>$2jA\<left>x\<esc>"
110 call assert_equal(['aaaaxa', 'bbbx', 'ccccxc'], getline(1, '$'))
111 " Test 2 Move 2 chars left
112 sil %d
113 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
114 exe "norm! gg\<c-v>$2jA\<left>\<left>x\<esc>"
115 call assert_equal(['aaaxaa', 'bbbx', 'cccxcc'], getline(1, '$'))
116 " Test 3 Move 3 chars left (to the beginning of the visual selection)
117 sil %d
118 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
119 exe "norm! gg\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
120 call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
121 " Test 4 Move 3 chars left (outside of the visual selection)
122 sil %d
123 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
124 exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
125 call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
126 " Test 5 Move 4 chars left (outside of the visual selection)
127 sil %d
128 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
129 exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>\<left>x\<esc>"
130 call assert_equal(['axaaaa', 'bxbb', 'cxcccc'], getline(1, '$'))
131 bw!
132endfunc
133
Bram Moolenaar8c87a2b2018-04-10 13:15:47 +0200134" vim: shiftwidth=2 sts=2 expandtab