aboutsummaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
Diffstat (limited to 'elf')
-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