Files
neovim/test/functional/legacy/utf8_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

90 lines
2.4 KiB
Lua

-- Tests for Unicode manipulations
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear, feed, insert = n.clear, n.feed, n.insert
local command, expect = n.command, n.expect
local eq, eval = t.eq, n.eval
local source = n.source
local poke_eventloop = n.poke_eventloop
describe('utf8', function()
before_each(clear)
it('is working', function()
insert('start:')
command('new')
command('call setline(1, ["aaa", "あああ", "bbb"])')
-- Visual block Insert adjusts for multi-byte char
feed('gg0l<C-V>jjIx<Esc>')
poke_eventloop()
command('let r = getline(1, "$")')
command('bwipeout!')
command('$put=r')
command('call garbagecollect(1)')
expect([[
start:
axaa
xあああ
bxbb]])
end)
it('strchars()', function()
eq(1, eval('strchars("a")'))
eq(1, eval('strchars("a", 0)'))
eq(1, eval('strchars("a", 1)'))
eq(3, eval('strchars("あいa")'))
eq(3, eval('strchars("あいa", 0)'))
eq(3, eval('strchars("あいa", 1)'))
eq(2, eval('strchars("A\\u20dd")'))
eq(2, eval('strchars("A\\u20dd", 0)'))
eq(1, eval('strchars("A\\u20dd", 1)'))
eq(3, eval('strchars("A\\u20dd\\u20dd")'))
eq(3, eval('strchars("A\\u20dd\\u20dd", 0)'))
eq(1, eval('strchars("A\\u20dd\\u20dd", 1)'))
eq(1, eval('strchars("\\u20dd")'))
eq(1, eval('strchars("\\u20dd", 0)'))
eq(1, eval('strchars("\\u20dd", 1)'))
end)
-- luacheck: ignore 613 (Trailing whitespace in a string)
it('customlist completion', function()
source([[
function! CustomComplete1(lead, line, pos)
return ['あ', 'い']
endfunction
command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo]])
feed(":Test1 <C-L>'<C-B>$put='<CR>")
source([[
function! CustomComplete2(lead, line, pos)
return ['あたし', 'あたま', 'あたりめ']
endfunction
command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo]])
feed(":Test2 <C-L>'<C-B>$put='<CR>")
source([[
function! CustomComplete3(lead, line, pos)
return ['Nこ', 'Nん', 'Nぶ']
endfunction
command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo]])
feed(":Test3 <C-L>'<C-B>$put='<CR>")
expect([[
Test1
Test2 あた
Test3 N]])
end)
end)