robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
6.0 KiB341 linesraw
1-- Test for multibyte text formatting.
2-- Also test, that 'mps' with multibyte chars works.
3-- And test "ra" on multibyte characters.
4-- Also test byteidx() and byteidxcomp()
5
6local t = require('test.testutil')
7local n = require('test.functional.testnvim')()
8
9local describe, it, before_each = t.describe, t.it, t.before_each
10local feed, insert, eq, eval, clear, feed_command, expect =
11  n.feed, n.insert, t.eq, n.eval, n.clear, n.feed_command, n.expect
12
13describe('multibyte text', function()
14  before_each(clear)
15
16  it('formatting with "set fo=t"', function()
17    insert([[
18      {
19      XYZ
20      abc XYZ
21      }]])
22    feed_command('/^{/+1')
23    feed_command('set tw=2 fo=t')
24    feed('gqgqjgqgqo<cr>')
25    feed('XYZ<cr>')
26    feed('abc XYZ<esc><esc>')
27    expect([[
28      {
29      XYZ
30      abc
31      XYZ
32
33      XYZ
34      abc
35      XYZ
36      }]])
37  end)
38
39  it('formatting with "set fo=tm"', function()
40    insert([[
41      {
42      X
43      Xa
44      X a
45      XY
46      X Y
47      }]])
48    feed_command('/^{/+1')
49    feed_command('set tw=1 fo=tm')
50    feed('gqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
51    feed('X<cr>')
52    feed('Xa<cr>')
53    feed('X a<cr>')
54    feed('XY<cr>')
55    feed('X Y<esc><esc>')
56    expect([[
57      {
58      X
59      X
60      a
61      X
62      a
63      X
64      Y
65      X
66      Y
67
68      X
69      X
70      a
71      X
72      a
73      X
74      Y
75      X
76      Y
77      }]])
78  end)
79
80  it('formatting with "set fo=tm" (part 2)', function()
81    insert([[
82      {
83      X
84      Xa
85      X a
86      XY
87      X Y
88      aX
89      abX
90      abcX
91      abX c
92      abXY
93      }]])
94    feed_command('/^{/+1')
95    feed_command('set tw=2 fo=tm')
96    feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
97    feed('X<cr>')
98    feed('Xa<cr>')
99    feed('X a<cr>')
100    feed('XY<cr>')
101    feed('X Y<cr>')
102    feed('aX<cr>')
103    feed('abX<cr>')
104    feed('abcX<cr>')
105    feed('abX c<cr>')
106    feed('abXY<esc><esc>')
107    expect([[
108      {
109      X
110      X
111      a
112      X
113      a
114      X
115      Y
116      X
117      Y
118      a
119      X
120      ab
121      X
122      abc
123      X
124      ab
125      X
126      c
127      ab
128      X
129      Y
130
131      X
132      X
133      a
134      X
135      a
136      X
137      Y
138      X
139      Y
140      a
141      X
142      ab
143      X
144      abc
145      X
146      ab
147      X
148      c
149      ab
150      X
151      Y
152      }]])
153  end)
154
155  it('formatting with "set ai fo=tm"', function()
156    insert([[
157      {
158        X
159        Xa
160      }]])
161    feed_command('/^{/+1')
162    feed_command('set ai tw=2 fo=tm')
163    feed('gqgqjgqgqo<cr>')
164    feed('X<cr>')
165    feed('Xa<esc>')
166    expect([[
167      {
168        X
169        X
170        a
171
172        X
173        X
174        a
175      }]])
176  end)
177
178  it('formatting with "set ai fo=tm" (part 2)', function()
179    insert([[
180      {
181        X
182        Xa
183      }]])
184    feed_command('/^{/+1')
185    feed_command('set noai tw=2 fo=tm')
186    feed('gqgqjgqgqo<cr>')
187    feed('  X<cr>')
188    feed('  Xa<esc>')
189    expect([[
190      {
191        X
192        X
193      a
194
195        X
196        X
197      a
198      }]])
199  end)
200
201  it('formatting with "set fo=cqm" and multibyte comments', function()
202    insert([[
203      {
204      X
205      Xa
206      XaY
207      XY
208      XYZ
209      X Y
210      X YZ
211      XX
212      XXa
213      XXY
214      }]])
215    feed_command('/^{/+1')
216    feed_command('set tw=2 fo=cqm comments=n:X')
217    feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
218    feed('X<cr>')
219    feed('Xa<cr>')
220    feed('XaY<cr>')
221    feed('XY<cr>')
222    feed('XYZ<cr>')
223    feed('X Y<cr>')
224    feed('X YZ<cr>')
225    feed('XX<cr>')
226    feed('XXa<cr>')
227    feed('XXY<esc><esc>')
228    expect([[
229      {
230      X
231      Xa
232      Xa
233      XY
234      XY
235      XY
236      XZ
237      X Y
238      X Y
239      X Z
240      XX
241      XXa
242      XXY
243
244      X
245      Xa
246      Xa
247      XY
248      XY
249      XY
250      XZ
251      X Y
252      X Y
253      X Z
254      XX
255      XXa
256      XXY
257      }]])
258  end)
259
260  it('formatting in replace mode', function()
261    insert([[
262      {
263
264      }]])
265    feed_command('/^{/+1')
266    feed_command('set tw=2 fo=tm')
267    feed('RXa<esc>')
268    expect([[
269      {
270      X
271      a
272      }]])
273  end)
274
275  it("as values of 'mps'", function()
276    insert([[
277      {
278      ‘ two three ’ four
279      }]])
280    feed_command('/^{/+1')
281    feed_command('set mps+=‘:’')
282    feed('d%<cr>')
283    expect([[
284      {
285       four
286      }]])
287  end)
288
289  it('can be replaced with r', function()
290    insert([[
291      abba
292      aab]])
293    feed('gg0Vjra<cr>')
294    expect([[
295      aaaa
296      aaa]])
297  end)
298
299  it("doesn't interfere with 'whichwrap'", function()
300    insert([[
301      á
302      x]])
303    feed_command('set whichwrap+=h')
304    feed_command('/^x')
305    feed('dh')
306    expect([[
307      áx]])
308  end)
309
310  it('can be queried with byteidx() and byteidxcomp()', function()
311    -- One char of two bytes.
312    feed_command("let a = '.é.'")
313    -- Normal e with composing char.
314    feed_command("let b = '.é.'")
315    eq(0, eval('byteidx(a, 0)'))
316    eq(1, eval('byteidx(a, 1)'))
317    eq(3, eval('byteidx(a, 2)'))
318    eq(4, eval('byteidx(a, 3)'))
319    eq(-1, eval('byteidx(a, 4)'))
320    eq(0, eval('byteidx(b, 0)'))
321    eq(1, eval('byteidx(b, 1)'))
322    eq(4, eval('byteidx(b, 2)'))
323    eq(5, eval('byteidx(b, 3)'))
324    eq(-1, eval('byteidx(b, 4)'))
325    eq(0, eval('byteidxcomp(a, 0)'))
326    eq(1, eval('byteidxcomp(a, 1)'))
327    eq(3, eval('byteidxcomp(a, 2)'))
328    eq(4, eval('byteidxcomp(a, 3)'))
329    eq(-1, eval('byteidxcomp(a, 4)'))
330    eq(0, eval('byteidxcomp(b, 0)'))
331    eq(1, eval('byteidxcomp(b, 1)'))
332    eq(2, eval('byteidxcomp(b, 2)'))
333    eq(4, eval('byteidxcomp(b, 3)'))
334    eq(5, eval('byteidxcomp(b, 4)'))
335    eq(-1, eval('byteidxcomp(b, 5)'))
336  end)
337
338  it('correctly interact with the \zs pattern', function()
339    eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]]))
340  end)
341end)