Files
neovim/test/functional/legacy/069_multibyte_formatting_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

342 lines
6.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Test for multibyte text formatting.
-- Also test, that 'mps' with multibyte chars works.
-- And test "ra" on multibyte characters.
-- Also test byteidx() and byteidxcomp()
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local feed, insert, eq, eval, clear, feed_command, expect =
n.feed, n.insert, t.eq, n.eval, n.clear, n.feed_command, n.expect
describe('multibyte text', function()
before_each(clear)
it('formatting with "set fo=t"', function()
insert([[
{
abc
}]])
feed_command('/^{/+1')
feed_command('set tw=2 fo=t')
feed('gqgqjgqgqo<cr>')
feed('<cr>')
feed('abc <esc><esc>')
expect([[
{
abc
abc
}]])
end)
it('formatting with "set fo=tm"', function()
insert([[
{
a
a
}]])
feed_command('/^{/+1')
feed_command('set tw=1 fo=tm')
feed('gqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
feed('<cr>')
feed('a<cr>')
feed(' a<cr>')
feed('<cr>')
feed(' <esc><esc>')
expect([[
{
a
a
a
a
}]])
end)
it('formatting with "set fo=tm" (part 2)', function()
insert([[
{
a
a
a
ab
abc
ab c
ab
}]])
feed_command('/^{/+1')
feed_command('set tw=2 fo=tm')
feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
feed('<cr>')
feed('a<cr>')
feed(' a<cr>')
feed('<cr>')
feed(' <cr>')
feed('a<cr>')
feed('ab<cr>')
feed('abc<cr>')
feed('ab c<cr>')
feed('ab<esc><esc>')
expect([[
{
a
a
a
ab
abc
ab
c
ab
a
a
a
ab
abc
ab
c
ab
}]])
end)
it('formatting with "set ai fo=tm"', function()
insert([[
{
a
}]])
feed_command('/^{/+1')
feed_command('set ai tw=2 fo=tm')
feed('gqgqjgqgqo<cr>')
feed('<cr>')
feed('a<esc>')
expect([[
{
a
a
}]])
end)
it('formatting with "set ai fo=tm" (part 2)', function()
insert([[
{
a
}]])
feed_command('/^{/+1')
feed_command('set noai tw=2 fo=tm')
feed('gqgqjgqgqo<cr>')
feed(' <cr>')
feed(' a<esc>')
expect([[
{
a
a
}]])
end)
it('formatting with "set fo=cqm" and multibyte comments', function()
insert([[
{
a
a
a
}]])
feed_command('/^{/+1')
feed_command('set tw=2 fo=cqm comments=n:')
feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
feed('<cr>')
feed('a<cr>')
feed('a<cr>')
feed('<cr>')
feed('<cr>')
feed(' <cr>')
feed(' <cr>')
feed('<cr>')
feed('a<cr>')
feed('<esc><esc>')
expect([[
{
a
a
a
a
a
a
}]])
end)
it('formatting in replace mode', function()
insert([[
{
}]])
feed_command('/^{/+1')
feed_command('set tw=2 fo=tm')
feed('Ra<esc>')
expect([[
{
a
}]])
end)
it("as values of 'mps'", function()
insert([[
{
two three four
}]])
feed_command('/^{/+1')
feed_command('set mps+=:')
feed('d%<cr>')
expect([[
{
four
}]])
end)
it('can be replaced with r', function()
insert([[
bb
b]])
feed('gg0Vjra<cr>')
expect([[
aaaa
aaa]])
end)
it("doesn't interfere with 'whichwrap'", function()
insert([[
á
x]])
feed_command('set whichwrap+=h')
feed_command('/^x')
feed('dh')
expect([[
áx]])
end)
it('can be queried with byteidx() and byteidxcomp()', function()
-- One char of two bytes.
feed_command("let a = '.é.'")
-- Normal e with composing char.
feed_command("let b = '.é.'")
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)'))
end)
it('correctly interact with the \zs pattern', function()
eq('aaaa', eval([[substitute('', '\zs', 'a', 'g')]]))
end)
end)