File

spec/util_serialization_spec.lua @ 9364:62f9127ab493

mod_scansion_record: Open a related file for header entries Since It's tricky to go back and insert data at the beginning of a file, but `cat blah.sch blah.scs` ought to be fine for now.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Sep 2018 14:36:34 +0200
parent 9343:e767da06399d
child 9480:006a71a83e6a
line wrap: on
line source

local serialization = require "util.serialization";

describe("util.serialization", function ()
	describe("serialize", function ()
		it("makes a string", function ()
			assert.is_string(serialization.serialize({}));
			assert.is_string(serialization.serialize(nil));
			assert.is_string(serialization.serialize(1));
			assert.is_string(serialization.serialize(true));
			assert.is_string(serialization.serialize(function () end));
		end);

		it("roundtrips", function ()
			local function test(data)
				local serialized = serialization.serialize(data);
				assert.is_string(serialized);
				local deserialized, err = serialization.deserialize(serialized);
				assert.same(data, deserialized, err);
			end

			test({});
			test({hello="world"});
			test("foobar")
			test("\0\1\2\3");
			test("nödåtgärd");
			test({1,2,3,4});
			test({foo={[100]={{"bar"},{baz=1}}}});
		end);
	end);
end);