From 9bf8cf708ef6aca2e0c2e5107157545f15a96273 Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Sun, 8 Nov 2026 18:07:21 +0530 Subject: Start with some tests. --- elf/test.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 elf/test.lua (limited to 'elf/test.lua') diff --git a/elf/test.lua b/elf/test.lua new file mode 100644 index 0000000..000d795 --- /dev/null +++ b/elf/test.lua @@ -0,0 +1,42 @@ +local fmt = require("elf.fmt") +local ec = require("elf.constants") + +local nfail = 0 +local function test(name, fn) + local ok, err = pcall(fn) + if not ok then + nfail = nfail + 1 + print("fail: " .. name .. ": " .. err) + end +end + +test("fmt.endian big", function () + assert(fmt.endian(ec.Endian.big) == ">", "invalid format string") +end) + +test("fmt.endian little", function () + assert(fmt.endian(ec.Endian.little) == "<", "invalid format string") +end) + +test("fmt.word 64", function () + assert(fmt.word(ec.Class.bit64) == "I8", "invalid format string") +end) + +test("fmt.word 32", function () + assert(fmt.word(ec.Class.bit32) == "I4", "invalid format string") +end) + +test("fmt.endian", function () + local ok = pcall(function () fmt.endian(42) end) + assert(not ok, "invalid input accepted") +end) + +test("fmt.word", function () + local ok = pcall(function () fmt.word(42) end) + assert(not ok, "invalid input accepted") +end) + +if nfail > 0 then + print(("%d %s failed"):format(nfail, (nfail == 1) and "test" or "tests")) + os.exit(1) +end -- cgit v1.3