more tests!

This commit is contained in:
Robin Wellner 2016-02-16 01:32:08 +01:00
parent 0d0bb54405
commit ba62015f30
2 changed files with 36 additions and 1 deletions

View File

@ -16,6 +16,8 @@ install:
- luarocks install luacov
- luarocks install luacov-coveralls
- luarocks install middleclass
- wget https://bitbucket.org/bartbes/slither/raw/bbd85db19b19d9d14470b4fa7b73029b6c070fb0/slither.lua
- wget https://raw.githubusercontent.com/vrld/hump/038bc9025f1cb850355f4b073357b087b8122da9/class.lua
script:
- luacheck --std max+busted bitser.lua spec

View File

@ -123,6 +123,32 @@ describe("bitser", function()
assert.are.equal(serdeser(bojack).__baseclass, Horse)
bitser.unregisterClass('Horse')
end)
it("serializes hump.class instances", function()
local class = require("class")
local Horse = bitser.registerClass('Horse', class{})
function Horse:init(name)
self.name = name
self[1] = 'instance can be sequence'
end
local bojack = Horse('Bojack Horseman')
test_serdeser(bojack)
assert.are.equal(getmetatable(serdeser(bojack)), Horse)
bitser.unregisterClass('Horse')
end)
it("serializes Slither instances", function()
local class = require("slither")
local Horse = class.private 'Horse' {
__attributes__ = {bitser.registerClass},
__init__ = function(self, name)
self.name = name
self[1] = 'instance can be sequence'
end
}
local bojack = Horse('Bojack Horseman')
test_serdeser(bojack)
assert.is_true(class.isinstance(serdeser(bojack), Horse))
bitser.unregisterClass('Horse')
end)
it("serializes big data", function()
local text = "this is a lot of nonsense, please disregard, we need a lot of data to get past 4 KiB (114 characters should do it)"
local t = {}
@ -154,4 +180,11 @@ describe("bitser", function()
it("cannot serialize unsupported class libraries without explicit deserializer", function()
assert.has_error(function() bitser.registerClass('Horse', {mane = 'majestic'}) end, "no deserializer given for unsupported class library")
end)
end)
it("cannot deserialize values from unassigned type bytes", function()
assert.has_error(function() bitser.loads("\251") end, "unsupported serialized type 251")
assert.has_error(function() bitser.loads("\252") end, "unsupported serialized type 252")
assert.has_error(function() bitser.loads("\253") end, "unsupported serialized type 253")
assert.has_error(function() bitser.loads("\254") end, "unsupported serialized type 254")
assert.has_error(function() bitser.loads("\255") end, "unsupported serialized type 255")
end)
end)