mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-22 20:24:36 +02:00
chore: Fix lint issues, mostly with proper variable scopes
This commit is contained in:
parent
939fc2901b
commit
51c1d732ed
@ -3,8 +3,6 @@ local fp = assert(io.open(arg[1], "rb"))
|
|||||||
local str = assert(fp:read("*a"))
|
local str = assert(fp:read("*a"))
|
||||||
fp:close()
|
fp:close()
|
||||||
|
|
||||||
local i
|
|
||||||
local c = 0
|
|
||||||
local ostr = "local xxxxxxxxxxx = \""
|
local ostr = "local xxxxxxxxxxx = \""
|
||||||
for i = 1, string.len(str) do
|
for i = 1, string.len(str) do
|
||||||
ostr = ostr .. "\\" .. string.byte(string.sub(str, i, i+1))
|
ostr = ostr .. "\\" .. string.byte(string.sub(str, i, i+1))
|
||||||
|
@ -76,7 +76,7 @@ local ebcdic = "\193\150\64\147\150\149\135\133\107\64\129\150\64\147\164\129"
|
|||||||
.. "\37"
|
.. "\37"
|
||||||
|
|
||||||
|
|
||||||
function check_one(to, from, text)
|
local function check_one(to, from, text)
|
||||||
print("\n-- Testing conversion from " .. from .. " to " .. to)
|
print("\n-- Testing conversion from " .. from .. " to " .. to)
|
||||||
local cd = iconv.new(to .. "//TRANSLIT", from)
|
local cd = iconv.new(to .. "//TRANSLIT", from)
|
||||||
assert(cd, "Failed to create a converter object.")
|
assert(cd, "Failed to create a converter object.")
|
||||||
@ -102,23 +102,24 @@ check_one(termcs, "EBCDIC-CP-ES", ebcdic)
|
|||||||
|
|
||||||
-- The library must never crash the interpreter, even if the user tweaks
|
-- The library must never crash the interpreter, even if the user tweaks
|
||||||
-- with the garbage collector methods.
|
-- with the garbage collector methods.
|
||||||
local cd = iconv.new("iso-8859-1", "utf-8")
|
local _, e, cd, s, gc
|
||||||
local _, e = cd:iconv("atenção")
|
cd = iconv.new("iso-8859-1", "utf-8")
|
||||||
|
_, e = cd:iconv("atenção")
|
||||||
assert(e == nil, "Unexpected conversion error")
|
assert(e == nil, "Unexpected conversion error")
|
||||||
local gc = getmetatable(cd).__gc
|
gc = getmetatable(cd).__gc
|
||||||
gc(cd)
|
gc(cd)
|
||||||
local _, e = cd:iconv("atenção")
|
_, e = cd:iconv("atenção")
|
||||||
assert(e == iconv.ERROR_FINALIZED, "Failed to detect double-freed objects")
|
assert(e == iconv.ERROR_FINALIZED, "Failed to detect double-freed objects")
|
||||||
gc(cd)
|
gc(cd)
|
||||||
|
|
||||||
|
|
||||||
-- Test expected return values
|
-- Test expected return values
|
||||||
local cd = iconv.new("ascii", "utf-8")
|
cd = iconv.new("ascii", "utf-8")
|
||||||
local _, e = cd:iconv("atenção")
|
_, e = cd:iconv("atenção")
|
||||||
assert(e == iconv.ERROR_INVALID, "Unexpected return value for invalid conversion")
|
assert(e == iconv.ERROR_INVALID, "Unexpected return value for invalid conversion")
|
||||||
|
|
||||||
|
|
||||||
local cd = iconv.new("iso-8859-1", "utf-8")
|
cd = iconv.new("iso-8859-1", "utf-8")
|
||||||
local s, e = cd:iconv("atenção")
|
s, e = cd:iconv("atenção")
|
||||||
assert(s == "aten\231\227o", "Unexpected result for valid conversion")
|
assert(s == "aten\231\227o", "Unexpected result for valid conversion")
|
||||||
assert(e == nil, "Unexpected return value for valid conversion")
|
assert(e == nil, "Unexpected return value for valid conversion")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user