feat(lua): add vim.iconv (#18286)

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
Lewis Russell
2022-08-24 14:41:31 +01:00
committed by GitHub
parent 9be4bfc5f4
commit b1eaa2b9a3
3 changed files with 102 additions and 0 deletions

View File

@@ -2721,6 +2721,39 @@ describe('lua stdlib', function()
]]
end)
end)
describe('vim.iconv', function()
it('can convert strings', function()
eq('hello', exec_lua[[
return vim.iconv('hello', 'latin1', 'utf-8')
]])
end)
it('can validate arguments', function()
eq({false, 'Expected at least 3 arguments'}, exec_lua[[
return {pcall(vim.iconv, 'hello')}
]])
eq({false, 'bad argument #3 to \'?\' (expected string)'}, exec_lua[[
return {pcall(vim.iconv, 'hello', 'utf-8', true)}
]])
end)
it('can handle bad encodings', function()
eq(NIL, exec_lua[[
return vim.iconv('hello', 'foo', 'bar')
]])
end)
it('can handle strings with NUL bytes', function()
eq(7, exec_lua[[
local a = string.char(97, 98, 99, 0, 100, 101, 102) -- abc\0def
return string.len(vim.iconv(a, 'latin1', 'utf-8'))
]])
end)
end)
end)
describe('lua: builtin modules', function()