mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
test(vim.text): add test cases for error conditions
This commit is contained in:
parent
d14f78ee0e
commit
f6549cee26
@ -41,6 +41,9 @@ function M.hexdecode(enc)
|
||||
for i = 1, #enc, 2 do
|
||||
local u = lookup[enc:sub(i, i)] --[[@as integer]]
|
||||
local l = lookup[enc:sub(i + 1, i + 1)] --[[@as integer]]
|
||||
if not u or not l then
|
||||
return nil, 'string must contain only hex characters'
|
||||
end
|
||||
str[#str + 1] = string.char(u * 16 + l)
|
||||
end
|
||||
return table.concat(str), nil
|
||||
|
@ -26,5 +26,21 @@ describe('vim.text', function()
|
||||
eq(output, vim.text.hexencode(input))
|
||||
eq(input, vim.text.hexdecode(output))
|
||||
end)
|
||||
|
||||
it('errors on invalid input', function()
|
||||
-- Odd number of hex characters
|
||||
do
|
||||
local res, err = vim.text.hexdecode('ABC')
|
||||
eq(nil, res)
|
||||
eq('string must have an even number of hex characters', err)
|
||||
end
|
||||
|
||||
-- Non-hexadecimal input
|
||||
do
|
||||
local res, err = vim.text.hexdecode('nothex')
|
||||
eq(nil, res)
|
||||
eq('string must contain only hex characters', err)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user