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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
function test(description, func)
io.write(description .. ': ')
local result, msg = pcall(func)
if result == true then
print("OK")
else
print("FAIL")
print(debug.traceback(msg))
print()
end
end
local b = require 'generate-binding'
test("extract function name from signature", function()
local name = b.ExtractFunctionName("int some_name(void *qqq);")
assert(name == "some_name")
name = b.ExtractFunctionName("float quitGame(int a, int b, int c, int** m);")
assert(name == "quitGame")
name = b.ExtractFunctionName("void startGame ();")
assert(name == "startGame")
end)
test("extract function type from signature", function()
local ftype = b.ExtractFunctionType("int some_ftype(void *qqq);")
assert(ftype == "int")
ftype = b.ExtractFunctionType("float quitGame(int a, int b, int c, int** m);")
assert(ftype == "float")
ftype = b.ExtractFunctionType("void startGame ();")
assert(ftype == "void")
end)
test("extract arguments from signature", function()
local args = b.ExtractFunctionArgs("int some_args(void *qqq);")
assert(args ~= nil)
assert(#args == 1)
assert(args[1].type == "void *")
assert(args[1].name == "qqq")
args = b.ExtractFunctionArgs("float quitGame(int a, int b, int c, int** m);")
assert(#args == 4)
assert(args[1].type == "int")
assert(args[1].name == "a")
assert(args[2].type == "int")
assert(args[2].name == "b")
assert(args[3].type == "int")
assert(args[3].name == "c")
assert(args[4].type == "int **")
assert(args[4].name == "m")
args = b.ExtractFunctionArgs("void startGame ();")
assert(#args == 0)
end)
|