1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
|