robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
5.4 KiB241 linesraw
1-- Test Visual block mode commands
2-- And test "U" in Visual mode, also on German sharp S.
3
4local t = require('test.testutil')
5local n = require('test.functional.testnvim')()
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local api, eq = n.api, t.eq
9local insert, feed = n.insert, n.feed
10local clear, expect = n.clear, n.expect
11local feed_command = n.feed_command
12
13describe('Visual block mode', function()
14  before_each(function()
15    clear()
16
17    feed_command('set ts&vi sw&vi sts&vi noet') -- Vim compatible
18  end)
19
20  it('should shift, insert, replace and change a block', function()
21    insert([[
22      abcdefghijklm
23      abcdefghijklm
24      abcdefghijklm
25      abcdefghijklm
26      abcdefghijklm]])
27
28    feed('gg')
29    -- Test shift-right of a block
30    feed('jllll<C-v>jj>wll<C-v>jlll><CR>')
31    -- Test shift-left of a block
32    feed('G$hhhh<C-v>kk<lt>')
33    -- Test block-insert
34    feed('Gkl<C-v>kkkIxyz<ESC>')
35    -- Test block-replace
36    feed('Gllll<C-v>kkklllrq')
37    -- Test block-change
38    feed('G$khhh<C-v>hhkkcmno<ESC>')
39
40    expect([[
41      axyzbcdefghijklm
42      axyzqqqq   mno	      ghijklm
43      axyzqqqqef mno        ghijklm
44      axyzqqqqefgmnoklm
45      abcdqqqqijklm]])
46  end)
47
48  -- luacheck: ignore 611 (Line contains only whitespaces)
49  it('should insert a block using cursor keys for movement', function()
50    insert([[
51      aaaaaa
52      bbbbbb
53      cccccc
54      dddddd
55      
56      xaaa
57      bbbb
58      cccc
59      dddd]])
60
61    feed_command('/^aa')
62    feed('l<C-v>jjjlllI<Right><Right>  <ESC>')
63    feed_command('/xaaa$')
64    feed('<C-v>jjjI<lt>><Left>p<ESC>')
65
66    expect([[
67      aaa  aaa
68      bbb  bbb
69      ccc  ccc
70      ddd  ddd
71      
72      <p>xaaa
73      <p>bbbb
74      <p>cccc
75      <p>dddd]])
76  end)
77
78  it('should create a block', function()
79    insert([[
80      A23
81      4567
82      
83      B23
84      4567
85      
86      C23
87      4567]])
88
89    -- Test for Visual block was created with the last <C-v>$.
90    feed_command('/^A23$/')
91    feed('l<C-v>j$Aab<ESC>')
92    -- Test for Visual block was created with the middle <C-v>$ (1).
93    feed_command('/^B23$/')
94    feed('l<C-v>j$hAab<ESC>')
95    -- Test for Visual block was created with the middle <C-v>$ (2).
96    feed_command('/^C23$/')
97    feed('l<C-v>j$hhAab<ESC>')
98
99    expect([[
100      A23ab
101      4567ab
102      
103      B23 ab
104      4567ab
105      
106      C23ab
107      456ab7]])
108  end)
109
110  -- luacheck: ignore 621 (Indentation)
111  it('should insert and append a block when virtualedit=all', function()
112    insert([[
113      		line1
114      		line2
115      		line3
116      .
117    ]])
118
119    -- Test for Visual block insert when virtualedit=all and utf-8 encoding.
120    feed_command('set ve=all')
121    feed_command('/\t\tline')
122    feed('07l<C-v>jjIx<ESC>')
123
124    expect([[
125             x 	line1
126             x 	line2
127             x 	line3
128      .
129    ]])
130
131    -- Test for Visual block append when virtualedit=all.
132    feed('012l<C-v>jjAx<ESC>')
133
134    expect([[
135             x     x   line1
136             x     x   line2
137             x     x   line3
138      .
139    ]])
140  end)
141
142  it('should make a selected part uppercase', function()
143    -- GUe must uppercase a whole word, also when ß changes to ẞ.
144    feed('Gothe youtußeuu end<ESC>Ypk0wgUe<CR>')
145    -- GUfx must uppercase until x, inclusive.
146    feed('O- youßtußexu -<ESC>0fogUfx<CR>')
147    -- VU must uppercase a whole line.
148    feed('YpkVU<CR>')
149    -- Same, when it's the last line in the buffer.
150    feed('YPGi111<ESC>VUddP<CR>')
151    -- Uppercase two lines.
152    feed('Oblah di<CR>')
153    feed('doh dut<ESC>VkUj<CR>')
154    -- Uppercase part of two lines.
155    feed('ddppi333<ESC>k0i222<esc>fyllvjfuUk<CR>')
156
157    expect([[
158      
159      the YOUTUẞEUU end
160      - yOUẞTUẞEXu -
161      THE YOUTUẞEUU END
162      111THE YOUTUẞEUU END
163      BLAH DI
164      DOH DUT
165      222the yoUTUẞEUU END
166      333THE YOUTUßeuu end]])
167  end)
168
169  it('should replace using Enter or NL', function()
170    -- Visual replace using Enter or NL.
171    feed('G3o123456789<ESC>2k05l<C-v>2jr<CR>')
172    feed('G3o98765<ESC>2k02l<C-v>2jr<C-v><CR>')
173    feed('G3o123456789<ESC>2k05l<C-v>2jr<CR>')
174    feed('G3o98765<ESC>2k02l<C-v>2jr<C-v><Nul>')
175
176    local expected = [[
177      
178      12345
179      789
180      12345
181      789
182      12345
183      789
184      98<CR>65
185      98<CR>65
186      98<CR>65
187      12345
188      789
189      12345
190      789
191      12345
192      789
193      98<Nul>65
194      98<Nul>65
195      98<Nul>65]]
196    expected = expected:gsub('<CR>', '\r')
197    expected = expected:gsub('<Nul>', '\000')
198
199    expect(expected)
200  end)
201
202  it('should treat cursor position correctly when virtualedit=block', function()
203    insert([[
204      12345
205      789
206      98765]])
207
208    -- Test cursor position. When virtualedit=block and Visual block mode and $gj.
209    feed_command('set ve=block')
210    feed('G2l')
211    feed('2k<C-v>$gj<ESC>')
212    feed_command([[let cpos=getpos("'>")]])
213    local cpos = api.nvim_get_var('cpos')
214    local expected = {
215      col = 4,
216      off = 0,
217    }
218    local actual = {
219      col = cpos[3],
220      off = cpos[4],
221    }
222
223    eq(expected, actual)
224  end)
225
226  it('should replace spaces in front of the block with tabs', function()
227    insert([[
228      #define BO_ALL	    0x0001
229      #define BO_BS	    0x0002
230      #define BO_CRSR	    0x0004]])
231
232    -- Block_insert when replacing spaces in front of the block with tabs.
233    feed_command('set ts=8 sts=4 sw=4')
234    feed('ggf0<C-v>2jI<TAB><ESC>')
235
236    expect([[
237      #define BO_ALL		0x0001
238      #define BO_BS	    	0x0002
239      #define BO_CRSR	    	0x0004]])
240  end)
241end)