mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-18 08:44:21 +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"))
|
||||
fp:close()
|
||||
|
||||
local i
|
||||
local c = 0
|
||||
local ostr = "local xxxxxxxxxxx = \""
|
||||
for i = 1, string.len(str) do
|
||||
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"
|
||||
|
||||
|
||||
function check_one(to, from, text)
|
||||
local function check_one(to, from, text)
|
||||
print("\n-- Testing conversion from " .. from .. " to " .. to)
|
||||
local cd = iconv.new(to .. "//TRANSLIT", from)
|
||||
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
|
||||
-- with the garbage collector methods.
|
||||
local cd = iconv.new("iso-8859-1", "utf-8")
|
||||
local _, e = cd:iconv("atenção")
|
||||
local _, e, cd, s, gc
|
||||
cd = iconv.new("iso-8859-1", "utf-8")
|
||||
_, e = cd:iconv("atenção")
|
||||
assert(e == nil, "Unexpected conversion error")
|
||||
local gc = getmetatable(cd).__gc
|
||||
gc = getmetatable(cd).__gc
|
||||
gc(cd)
|
||||
local _, e = cd:iconv("atenção")
|
||||
_, e = cd:iconv("atenção")
|
||||
assert(e == iconv.ERROR_FINALIZED, "Failed to detect double-freed objects")
|
||||
gc(cd)
|
||||
|
||||
|
||||
-- Test expected return values
|
||||
local cd = iconv.new("ascii", "utf-8")
|
||||
local _, e = cd:iconv("atenção")
|
||||
cd = iconv.new("ascii", "utf-8")
|
||||
_, e = cd:iconv("atenção")
|
||||
assert(e == iconv.ERROR_INVALID, "Unexpected return value for invalid conversion")
|
||||
|
||||
|
||||
local cd = iconv.new("iso-8859-1", "utf-8")
|
||||
local s, e = cd:iconv("atenção")
|
||||
cd = iconv.new("iso-8859-1", "utf-8")
|
||||
s, e = cd:iconv("atenção")
|
||||
assert(s == "aten\231\227o", "Unexpected result for valid conversion")
|
||||
assert(e == nil, "Unexpected return value for valid conversion")
|
||||
|
Loading…
x
Reference in New Issue
Block a user