aboutsummaryrefslogtreecommitdiff
path: root/elf/test.lua
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-11-08 18:07:21 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-11-08 18:07:21 +0530
commit9bf8cf708ef6aca2e0c2e5107157545f15a96273 (patch)
treeb9a671bc5be4936e2f1b3bb4e3bff2ea85a4586a /elf/test.lua
parent2a09c2c564a30af8a1bedf371a0ff6621e7f6300 (diff)
Start with some tests.
Diffstat (limited to 'elf/test.lua')
-rw-r--r--elf/test.lua42
1 files changed, 42 insertions, 0 deletions
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