diff --git a/bluon.lua b/bluon.lua index 77459a0..fea3bcc 100644 --- a/bluon.lua +++ b/bluon.lua @@ -217,7 +217,7 @@ function write(self, object, stream) return end if object % 1 == 0 then - uint_with_type(object > 0 and type_ranges.number_constant or type_ranges.number_positive, object > 0 and object or -object) + uint_with_type(object > 0 and type_ranges.number_constant or type_ranges.number_negative, object > 0 and object or -object) return end float(object) @@ -337,11 +337,11 @@ function read(self, stream) end type = type:byte() if type <= type_ranges.number then - if type <= type_ranges.number_positive then + if type <= type_ranges.number_negative then return uint(type - type_ranges.number_constant) end - if type <= type_ranges.number_negative then - return -uint(type - type_ranges.number_positive) + if type <= type_ranges.number_positive then + return -uint(type - type_ranges.number_negative) end return float(type == type_ranges.number) end diff --git a/test.lua b/test.lua index d81eaca..e49b375 100644 --- a/test.lua +++ b/test.lua @@ -134,20 +134,27 @@ do written = rope:to_text() input = modlib.text.inputstream(written) read = bluon:read(input) + local remaining = input:read(1000) + assert(not remaining) end) -- TODO assertdump - local remaining = input:read(69) - assert(not remaining, remaining and modlib.text.hexdump(remaining)) - assert(modlib.table.equals_references(object, read), dump{object = object, read = read, written = written and modlib.text.hexdump(written), err = err}) + assert(modlib.table.equals_references(object, read) and not err, dump{ + object = object, + read = read, + written = written and modlib.text.hexdump(written), + err = err + }) end for _, constant in pairs{true, false, math.huge, -math.huge} do assert_preserves(constant) end - for i = 1, 69 do - assert_preserves(table.concat(modlib.table.repetition("x", i))) + for i = 1, 1000 do + assert_preserves(table.concat(modlib.table.repetition(string.char(i % 256), i))) end for _ = 1, 1000 do - assert_preserves(math.random(2^-50, 2^50)) + local int = math.random(-2^50, 2^50) + assert(int % 1 == 0) + assert_preserves(int) assert_preserves((math.random() - 0.5) * 2^math.random(-20, 20)) end assert_preserves{hello = "world", welt = "hallo"}