-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.lua
67 lines (58 loc) · 1.61 KB
/
test.lua
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
58
59
60
61
62
63
64
65
66
67
describe("Luaflow tests", function()
local lib = require "luaflow_lib"
local concat = table.concat
local function test_file_path(s)
return "tests/" .. s
end
local function verify_flow(lua_src, flow_txt)
local ctx = lib.create_ctx()
local t = lib.parse(ctx, lua_src)
lib.visit_tree(ctx, t)
lib.adjust_ctx(ctx)
local flow = lib.get_root_flow(ctx, {}) -- use empty conf
flow[#flow + 1] = "\n"
assert.are.equal(flow_txt, concat(flow))
end
local function verify_flow_file(lua_file, flow_file)
local f = assert(io.open(test_file_path(flow_file)))
local txt = f:read("*a")
f:close()
local ctx = lib.create_ctx()
local t = lib.parse_file(ctx, test_file_path(lua_file))
lib.visit_tree(ctx, t)
lib.adjust_ctx(ctx)
local flow = lib.get_root_flow(ctx, {}) -- use empty conf
flow[#flow + 1] = "\n"
assert.are.equal(txt, concat(flow))
end
it("sanity", function()
verify_flow_file("sanity.lua", "sanity.txt")
end)
it("sanity2", function()
verify_flow([[
function
foo()
end
function main()
foo()
end
]],
"main\n foo\n")
end)
it("recursive", function()
verify_flow([[
function foo()
foo()
end
]],
"foo\n foo (recursive: see 1)\n")
end)
it("unamed function", function()
verify_flow([[
local function foo()
return function () end
end
]],
"foo\n")
end)
end)