Fix i64 printing in tests

This commit is contained in:
Rerumu 2022-06-26 01:00:07 -04:00
parent c462a4472f
commit 2ad52aa6b1

View File

@ -71,13 +71,21 @@ local function is_number_equal(lhs, rhs)
return math.abs(lhs - rhs) < 0.00001 or string.format("%.3g", lhs) == string.format("%.3g", rhs) return math.abs(lhs - rhs) < 0.00001 or string.format("%.3g", lhs) == string.format("%.3g", rhs)
end end
local function to_string(data)
if type(data) == "table" then
data = rt.convert.f64_i64(data)
end
return tostring(data)
end
local function assert_eq(lhs, rhs, level) local function assert_eq(lhs, rhs, level)
if lhs == rhs or is_number_equal(lhs, rhs) then if lhs == rhs or is_number_equal(lhs, rhs) then
return return
end end
lhs = tostring(lhs) lhs = to_string(lhs)
rhs = tostring(rhs) rhs = to_string(rhs)
level = (level or 1) + 1 level = (level or 1) + 1
error(lhs .. " ~= " .. rhs, level) error(lhs .. " ~= " .. rhs, level)
@ -88,8 +96,8 @@ local function assert_neq(lhs, rhs, level)
return return
end end
lhs = tostring(lhs) lhs = to_string(lhs)
rhs = tostring(rhs) rhs = to_string(rhs)
level = (level or 1) + 1 level = (level or 1) + 1
error(lhs .. " == " .. rhs, level) error(lhs .. " == " .. rhs, level)