2015-07-10 06:01:57 -07:00
|
|
|
|
-- Test for multibyte text formatting.
|
2015-07-09 06:38:56 -07:00
|
|
|
|
-- Also test, that 'mps' with multibyte chars works.
|
2015-07-10 06:01:57 -07:00
|
|
|
|
-- And test "ra" on multibyte characters.
|
2015-07-09 06:38:56 -07:00
|
|
|
|
-- Also test byteidx() and byteidxcomp()
|
|
|
|
|
|
2015-07-10 06:01:57 -07:00
|
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2017-04-08 14:12:26 -07:00
|
|
|
|
local feed, insert, eq, eval, clear, feed_command, expect = helpers.feed,
|
|
|
|
|
helpers.insert, helpers.eq, helpers.eval, helpers.clear, helpers.feed_command,
|
2015-07-10 06:01:57 -07:00
|
|
|
|
helpers.expect
|
2015-07-09 06:38:56 -07:00
|
|
|
|
|
2015-07-10 06:01:57 -07:00
|
|
|
|
describe('multibyte text', function()
|
2015-07-09 06:38:56 -07:00
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
|
|
it('formatting with "set fo=t"', function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
XYZ
|
|
|
|
|
abc XYZ
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set tw=2 fo=t')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('gqgqjgqgqo<cr>')
|
|
|
|
|
feed('XYZ<cr>')
|
|
|
|
|
feed('abc XYZ<esc><esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
XYZ
|
|
|
|
|
abc
|
|
|
|
|
XYZ
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
XYZ
|
|
|
|
|
abc
|
|
|
|
|
XYZ
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('formatting with "set fo=tm"', function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
X a
|
|
|
|
|
XY
|
|
|
|
|
X Y
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set tw=1 fo=tm')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('gqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
|
|
|
|
|
feed('X<cr>')
|
|
|
|
|
feed('Xa<cr>')
|
|
|
|
|
feed('X a<cr>')
|
|
|
|
|
feed('XY<cr>')
|
|
|
|
|
feed('X Y<esc><esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
X
|
|
|
|
|
Y
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('formatting with "set fo=tm" (part 2)', function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
X a
|
|
|
|
|
XY
|
|
|
|
|
X Y
|
|
|
|
|
aX
|
|
|
|
|
abX
|
|
|
|
|
abcX
|
|
|
|
|
abX c
|
|
|
|
|
abXY
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set tw=2 fo=tm')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
|
|
|
|
|
feed('X<cr>')
|
|
|
|
|
feed('Xa<cr>')
|
|
|
|
|
feed('X a<cr>')
|
|
|
|
|
feed('XY<cr>')
|
|
|
|
|
feed('X Y<cr>')
|
|
|
|
|
feed('aX<cr>')
|
|
|
|
|
feed('abX<cr>')
|
|
|
|
|
feed('abcX<cr>')
|
|
|
|
|
feed('abX c<cr>')
|
|
|
|
|
feed('abXY<esc><esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
ab
|
|
|
|
|
X
|
|
|
|
|
abc
|
|
|
|
|
X
|
|
|
|
|
ab
|
|
|
|
|
X
|
|
|
|
|
c
|
|
|
|
|
ab
|
|
|
|
|
X
|
|
|
|
|
Y
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
a
|
|
|
|
|
X
|
|
|
|
|
ab
|
|
|
|
|
X
|
|
|
|
|
abc
|
|
|
|
|
X
|
|
|
|
|
ab
|
|
|
|
|
X
|
|
|
|
|
c
|
|
|
|
|
ab
|
|
|
|
|
X
|
|
|
|
|
Y
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('formatting with "set ai fo=tm"', function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set ai tw=2 fo=tm')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('gqgqjgqgqo<cr>')
|
|
|
|
|
feed('X<cr>')
|
|
|
|
|
feed('Xa<esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('formatting with "set ai fo=tm" (part 2)', function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set noai tw=2 fo=tm')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('gqgqjgqgqo<cr>')
|
|
|
|
|
-- Literal spaces will be trimmed from the by feed().
|
|
|
|
|
feed('<space><space>X<cr>')
|
|
|
|
|
feed('<space><space>Xa<esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
X
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
2015-07-10 06:01:57 -07:00
|
|
|
|
it('formatting with "set fo=cqm" and multibyte comments', function()
|
2015-07-09 06:38:56 -07:00
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
XaY
|
|
|
|
|
XY
|
|
|
|
|
XYZ
|
|
|
|
|
X Y
|
|
|
|
|
X YZ
|
|
|
|
|
XX
|
|
|
|
|
XXa
|
|
|
|
|
XXY
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set tw=2 fo=cqm comments=n:X')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
|
|
|
|
|
feed('X<cr>')
|
|
|
|
|
feed('Xa<cr>')
|
|
|
|
|
feed('XaY<cr>')
|
|
|
|
|
feed('XY<cr>')
|
|
|
|
|
feed('XYZ<cr>')
|
|
|
|
|
feed('X Y<cr>')
|
|
|
|
|
feed('X YZ<cr>')
|
|
|
|
|
feed('XX<cr>')
|
|
|
|
|
feed('XXa<cr>')
|
|
|
|
|
feed('XXY<esc><esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
Xa
|
|
|
|
|
XY
|
|
|
|
|
XY
|
|
|
|
|
XY
|
|
|
|
|
XZ
|
|
|
|
|
X Y
|
|
|
|
|
X Y
|
|
|
|
|
X Z
|
|
|
|
|
XX
|
|
|
|
|
XXa
|
|
|
|
|
XXY
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
X
|
|
|
|
|
Xa
|
|
|
|
|
Xa
|
|
|
|
|
XY
|
|
|
|
|
XY
|
|
|
|
|
XY
|
|
|
|
|
XZ
|
|
|
|
|
X Y
|
|
|
|
|
X Y
|
|
|
|
|
X Z
|
|
|
|
|
XX
|
|
|
|
|
XXa
|
|
|
|
|
XXY
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('formatting in replace mode', function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
2017-09-24 11:42:48 -07:00
|
|
|
|
|
2015-07-09 06:38:56 -07:00
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set tw=2 fo=tm')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('RXa<esc>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
X
|
|
|
|
|
a
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("as values of 'mps'", function()
|
|
|
|
|
insert([[
|
|
|
|
|
{
|
|
|
|
|
‘ two three ’ four
|
|
|
|
|
}]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('/^{/+1')
|
|
|
|
|
feed_command('set mps+=‘:’')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('d%<cr>')
|
|
|
|
|
expect([[
|
|
|
|
|
{
|
|
|
|
|
four
|
|
|
|
|
}]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('can be replaced with r', function()
|
|
|
|
|
insert([[
|
|
|
|
|
abba
|
|
|
|
|
aab]])
|
|
|
|
|
feed('gg0Vjra<cr>')
|
|
|
|
|
expect([[
|
|
|
|
|
aaaa
|
|
|
|
|
aaa]])
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("doesn't interfere with 'whichwrap'", function()
|
|
|
|
|
insert([[
|
|
|
|
|
á
|
|
|
|
|
x]])
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command('set whichwrap+=h')
|
|
|
|
|
feed_command('/^x')
|
2015-07-09 06:38:56 -07:00
|
|
|
|
feed('dh')
|
|
|
|
|
expect([[
|
|
|
|
|
áx]])
|
|
|
|
|
end)
|
|
|
|
|
|
2015-07-10 06:01:57 -07:00
|
|
|
|
it('can be queried with byteidx() and byteidxcomp()', function()
|
2015-07-09 06:38:56 -07:00
|
|
|
|
-- One char of two bytes.
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command("let a = '.é.'")
|
2015-07-09 06:38:56 -07:00
|
|
|
|
-- Normal e with composing char.
|
2017-04-08 14:12:26 -07:00
|
|
|
|
feed_command("let b = '.é.'")
|
2015-07-10 06:01:57 -07:00
|
|
|
|
eq(0, eval('byteidx(a, 0)'))
|
|
|
|
|
eq(1, eval('byteidx(a, 1)'))
|
|
|
|
|
eq(3, eval('byteidx(a, 2)'))
|
|
|
|
|
eq(4, eval('byteidx(a, 3)'))
|
|
|
|
|
eq(-1, eval('byteidx(a, 4)'))
|
|
|
|
|
eq(0, eval('byteidx(b, 0)'))
|
|
|
|
|
eq(1, eval('byteidx(b, 1)'))
|
|
|
|
|
eq(4, eval('byteidx(b, 2)'))
|
|
|
|
|
eq(5, eval('byteidx(b, 3)'))
|
|
|
|
|
eq(-1, eval('byteidx(b, 4)'))
|
|
|
|
|
eq(0, eval('byteidxcomp(a, 0)'))
|
|
|
|
|
eq(1, eval('byteidxcomp(a, 1)'))
|
|
|
|
|
eq(3, eval('byteidxcomp(a, 2)'))
|
|
|
|
|
eq(4, eval('byteidxcomp(a, 3)'))
|
|
|
|
|
eq(-1, eval('byteidxcomp(a, 4)'))
|
|
|
|
|
eq(0, eval('byteidxcomp(b, 0)'))
|
|
|
|
|
eq(1, eval('byteidxcomp(b, 1)'))
|
|
|
|
|
eq(2, eval('byteidxcomp(b, 2)'))
|
|
|
|
|
eq(4, eval('byteidxcomp(b, 3)'))
|
|
|
|
|
eq(5, eval('byteidxcomp(b, 4)'))
|
|
|
|
|
eq(-1, eval('byteidxcomp(b, 5)'))
|
2015-07-09 06:38:56 -07:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('correctly interact with the \zs pattern', function()
|
2015-07-10 06:01:57 -07:00
|
|
|
|
eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]]))
|
2015-07-09 06:38:56 -07:00
|
|
|
|
end)
|
|
|
|
|
end)
|