more testing and lint stuff

This commit is contained in:
Robin Wellner 2016-02-15 14:34:52 +01:00
parent 3c51639de7
commit 5d27470cce
4 changed files with 25 additions and 3 deletions

View File

@ -15,6 +15,7 @@ install:
- luarocks install busted - luarocks install busted
- luarocks install luacov - luarocks install luacov
- luarocks install luacov-coveralls - luarocks install luacov-coveralls
- luarocks install middleclass
script: script:
- luacheck --std max+busted bitser.lua spec - luacheck --std max+busted bitser.lua spec

View File

@ -1,5 +1,7 @@
# bitser # bitser
[![Build Status](https://travis-ci.org/gvx/bitser.svg?branch=master)](https://travis-ci.org/gvx/bitser)
Serializes and deserializes Lua values with LuaJIT. Serializes and deserializes Lua values with LuaJIT.
local bitser = require 'bitser' local bitser = require 'bitser'

View File

@ -77,7 +77,7 @@ local class_deserialize_registry = {}
local serialize_value local serialize_value
local function write_number(value, buffer, seen) local function write_number(value, buffer, _)
if floor(value) == value and value >= -2147483648 and value <= 2147483647 then if floor(value) == value and value >= -2147483648 and value <= 2147483647 then
if value >= -27 and value <= 100 then if value >= -27 and value <= 100 then
--small int --small int
@ -110,11 +110,11 @@ local function write_string(value, buffer, seen)
Buffer_write_string(buffer, value) Buffer_write_string(buffer, value)
end end
local function write_nil(value, buffer, seen) local function write_nil(_, buffer, _)
Buffer_write_byte(buffer, 247) Buffer_write_byte(buffer, 247)
end end
local function write_boolean(value, buffer, seen) local function write_boolean(value, buffer, _)
Buffer_write_byte(buffer, value and 249 or 248) Buffer_write_byte(buffer, value and 249 or 248)
end end

View File

@ -73,4 +73,23 @@ describe("bitser", function()
bitser.unregister(tostring(i)) bitser.unregister(tostring(i))
end end
end) end)
it("serializes deeply nested tables", function()
local max = 1000
local t = {}
for _ = 1, max do
t.t = {}
t = t.t
end
test_serdeser(t)
end)
it("serializes MiddleClass instances", function()
local class = require("middleclass")
local Horse = class('Horse')
function Horse:initialize(name)
self.name = name
end
local bojack = Horse('Bojack Horseman')
test_serdeser(bojack)
assert.is_true(serdeser(bojack):isInstanceOf(Horse))
end)
end) end)