mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 01:03:46 +01:00
Bluon: Fix nan reading
This commit is contained in:
parent
258d9d956d
commit
9af2d64ad9
@ -260,6 +260,7 @@ function write(self, value, stream)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local constants_flipped = modlib.table.flip(constants)
|
local constants_flipped = modlib.table.flip(constants)
|
||||||
|
constants_flipped[constant_nan] = 0/0
|
||||||
|
|
||||||
-- See https://www.lua.org/manual/5.1/manual.html#2.2
|
-- See https://www.lua.org/manual/5.1/manual.html#2.2
|
||||||
function read(self, stream)
|
function read(self, stream)
|
||||||
|
44
test.lua
44
test.lua
@ -228,9 +228,17 @@ for _ = 1, 1000 do
|
|||||||
assert(distance == min_distance)
|
assert(distance == min_distance)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function serializer_test(assert_preserves)
|
local function serializer_test(preserve)
|
||||||
-- TODO nan
|
local function assert_preserves(obj)
|
||||||
for _, constant in pairs{true, false, huge, -huge} do
|
local preserved = preserve(obj)
|
||||||
|
if obj ~= obj then
|
||||||
|
assert(preserved ~= preserved)
|
||||||
|
else
|
||||||
|
assert(table.equals_references(preserved, obj), luon:write_string(preserved))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- TODO proper deep table comparison with nan support
|
||||||
|
for _, constant in pairs{true, false, huge, -huge, 0/0} do
|
||||||
assert_preserves(constant)
|
assert_preserves(constant)
|
||||||
end
|
end
|
||||||
-- Strings
|
-- Strings
|
||||||
@ -265,37 +273,27 @@ local function serializer_test(assert_preserves)
|
|||||||
assert_preserves(a)
|
assert_preserves(a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- luon
|
||||||
|
do
|
||||||
|
serializer_test(function(object)
|
||||||
|
return luon:read_string(luon:write_string(object))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- bluon
|
-- bluon
|
||||||
do
|
do
|
||||||
local bluon = bluon
|
-- TODO 1.1496387980481e-07 fails due to precision issues
|
||||||
serializer_test(function(object)
|
serializer_test(function(object)
|
||||||
local rope = table.rope{}
|
local rope = table.rope{}
|
||||||
local written, read, input
|
local written, read, input
|
||||||
local _, err = pcall(function()
|
|
||||||
bluon:write(object, rope)
|
bluon:write(object, rope)
|
||||||
written = rope:to_text()
|
written = rope:to_text()
|
||||||
input = text.inputstream(written)
|
input = text.inputstream(written)
|
||||||
read = bluon:read(input)
|
read = bluon:read(input)
|
||||||
local remaining = input:read(1000)
|
local remaining = input:read(1)
|
||||||
assert(not remaining)
|
assert(not remaining)
|
||||||
|
return read
|
||||||
end)
|
end)
|
||||||
assertdump(table.equals_references(object, read) and not err, {
|
|
||||||
object = object,
|
|
||||||
read = read,
|
|
||||||
written = written and text.hexdump(written),
|
|
||||||
err = err
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- luon
|
|
||||||
do
|
|
||||||
serializer_test(function(object)
|
|
||||||
local serialized = luon:write_string(object)
|
|
||||||
assert(table.equals_references(object, luon:read_string(serialized)), serialized)
|
|
||||||
end)
|
|
||||||
local nan = luon:read_string(luon:write_string(0/0))
|
|
||||||
assert(nan ~= nan)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not _G.minetest then return end
|
if not _G.minetest then return end
|
||||||
|
Loading…
Reference in New Issue
Block a user