From ba62015f308f71d0139d9afb697211c7c250c793 Mon Sep 17 00:00:00 2001 From: Robin Wellner Date: Tue, 16 Feb 2016 01:32:08 +0100 Subject: [PATCH] more tests! --- .travis.yml | 2 ++ spec/bitser_spec.lua | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0c5e25a..0180937 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/spec/bitser_spec.lua b/spec/bitser_spec.lua index d305b7b..33fccae 100644 --- a/spec/bitser_spec.lua +++ b/spec/bitser_spec.lua @@ -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) \ No newline at end of file + 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)