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