blob: 779c6472a6fdc4a0d1a00ee7fdec8603277b81c3 [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
20 var d = {
21 a: () => 0,
22 b: () => 0,
23 c: () => 0,
24 }
25 END
26 call setline(1, lines)
27 filetype plugin indent on
28 setlocal sw=2 et ft=vim
29 setlocal indentkeys+=:
30 exe "norm! 2Gf)\<c-v>2jA: asdf\<esc>"
Bram Moolenaar66000ff2022-09-27 17:47:12 +010031 " FIXME: what do we really expect?
Bram Moolenaare9b0b402021-11-27 13:28:24 +000032 let expected =<< trim END
33 var d = {
Bram Moolenaar66000ff2022-09-27 17:47:12 +010034 a: (): asdf => 0,
Bram Moolenaare9b0b402021-11-27 13:28:24 +000035 b: (): asdf => 0,
36 c: (): asdf => 0,
37 }
38 END
39 call assert_equal(expected, getline(1, 5))
40
Bram Moolenaar59f4f952021-11-27 22:47:43 +000041 " insert on the next column should do exactly the same
42 :%dele
43 call setline(1, lines)
44 exe "norm! 2Gf)l\<c-v>2jI: asdf\<esc>"
45 call assert_equal(expected, getline(1, 5))
46
47 :%dele
48 call setline(1, lines)
49 setlocal sw=8 noet
50 exe "norm! 2Gf)\<c-v>2jA: asdf\<esc>"
Bram Moolenaar66000ff2022-09-27 17:47:12 +010051 " FIXME: what do we really expect?
Bram Moolenaar59f4f952021-11-27 22:47:43 +000052 let expected =<< trim END
53 var d = {
Bram Moolenaar66000ff2022-09-27 17:47:12 +010054 a: (): asdf => 0,
Bram Moolenaar59f4f952021-11-27 22:47:43 +000055 b: (): asdf => 0,
56 c: (): asdf => 0,
57 }
58 END
59 call assert_equal(expected, getline(1, 5))
60
61 " insert on the next column should do exactly the same
62 :%dele
63 call setline(1, lines)
64 exe "norm! 2Gf)l\<c-v>2jI: asdf\<esc>"
65 call assert_equal(expected, getline(1, 5))
66
Bram Moolenaare9b0b402021-11-27 13:28:24 +000067 filetype off
68 bwipe!
69endfunc
70
Bram Moolenaar35e802e2018-04-30 17:21:03 +020071func Test_blockinsert_delete()
72 new
73 let _bs = &bs
74 set bs=2
75 call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;'])
76 exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>"
77 "call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti')
78 call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"],
79 \ getline(1,'$'))
80 " reset to sane state
81 let &bs = _bs
82 bwipe!
83endfunc
Bram Moolenaar8c87a2b2018-04-10 13:15:47 +020084
Bram Moolenaar4067bd32021-06-29 18:54:35 +020085func Test_blockappend_eol_cursor()
86 new
87 " Test 1 Move 1 char left
88 call setline(1, ['aaa', 'bbb', 'ccc'])
89 exe "norm! gg$\<c-v>2jA\<left>x\<esc>"
90 call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
91 " Test 2 Move 2 chars left
92 sil %d
93 call setline(1, ['aaa', 'bbb', 'ccc'])
94 exe "norm! gg$\<c-v>2jA\<left>\<left>x\<esc>"
95 call assert_equal(['axaa', 'bxbb', 'cxcc'], getline(1, '$'))
96 " Test 3 Move 3 chars left (outside of the visual selection)
97 sil %d
98 call setline(1, ['aaa', 'bbb', 'ccc'])
99 exe "norm! ggl$\<c-v>2jA\<left>\<left>\<left>x\<esc>"
100 call assert_equal(['xaaa', 'bbb', 'ccc'], getline(1, '$'))
101 bw!
102endfunc
103
104func Test_blockappend_eol_cursor2()
105 new
106 " Test 1 Move 1 char left
107 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
108 exe "norm! gg\<c-v>$2jA\<left>x\<esc>"
109 call assert_equal(['aaaaxa', 'bbbx', 'ccccxc'], getline(1, '$'))
110 " Test 2 Move 2 chars left
111 sil %d
112 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
113 exe "norm! gg\<c-v>$2jA\<left>\<left>x\<esc>"
114 call assert_equal(['aaaxaa', 'bbbx', 'cccxcc'], getline(1, '$'))
115 " Test 3 Move 3 chars left (to the beginning of the visual selection)
116 sil %d
117 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
118 exe "norm! gg\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
119 call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
120 " Test 4 Move 3 chars left (outside of the visual selection)
121 sil %d
122 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
123 exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
124 call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
125 " Test 5 Move 4 chars left (outside of the visual selection)
126 sil %d
127 call setline(1, ['aaaaa', 'bbb', 'ccccc'])
128 exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>\<left>x\<esc>"
129 call assert_equal(['axaaaa', 'bxbb', 'cxcccc'], getline(1, '$'))
130 bw!
131endfunc
132
Bram Moolenaar8c87a2b2018-04-10 13:15:47 +0200133" vim: shiftwidth=2 sts=2 expandtab