Skip to content

Commit

Permalink
chore: Fix lint issues, mostly with proper variable scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 5, 2023
1 parent 939fc29 commit 51c1d73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 0 additions & 2 deletions makestr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
19 changes: 10 additions & 9 deletions test_iconv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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")

0 comments on commit 51c1d73

Please sign in to comment.