From 9dea1c26b487ae723d99ba1e5e5887b09aec87dd Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 26 May 2024 13:06:12 -0300 Subject: Fix Lua 5.1 support and add tests --- testbc.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 testbc.lua (limited to 'testbc.lua') diff --git a/testbc.lua b/testbc.lua new file mode 100644 index 0000000..7b4a6e2 --- /dev/null +++ b/testbc.lua @@ -0,0 +1,29 @@ +local cratera = require "cratera" + +local function stream(filename, mode) + local file, err = io.open(filename, mode) + if not file then return nil, err end + return function() + local data, err = file:read(8192) + if not data then file:close() return nil, err end + return data + end +end + +-- load tests, streaming +local tests = assert(cratera.load(stream("tests.cratera", "rb"))) + +-- dump tests +local testsdump = string.dump(tests) + +-- check if cratera can load them +assert(cratera.load(testsdump))() + +-- output to a file +local file = io.open("testsdump.cratera", "wb") +assert(file:write(testsdump)) +assert(file:flush()) +assert(file:close()) + +-- load again, streaming, precompiled, and from a file +assert(cratera.load(stream("testsdump.cratera", "rb")))() -- cgit 1.4.1