Skip to content

Commit e0d17d2

Browse files
junhyeokhishamhm
authored andcommitted
macro: test generic for with multiple control variables
1 parent 52e2dfe commit e0d17d2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

spec/lang/macro/for_control_var_spec.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,26 @@ describe('macro body for-loop control variables', function()
6363
out = out:gsub("^%s+", ""):gsub("%s+$", "")
6464
assert.same("print('hi'); print('hi')", out)
6565
end)
66+
it('handles a generic for with multiple control variables', function()
67+
local code = [[
68+
local macro pairs2!(x: Expression)
69+
local out = block('statements')
70+
for k, v in pairs({ a = 1, b = 2 }) do
71+
k = k .. '!'
72+
v = v + 10
73+
table.insert(out, `$x`)
74+
end
75+
return out
76+
end
77+
78+
pairs2!(print('hi'))
79+
]]
80+
local ast, errs = tl.parse(code)
81+
assert.same({}, errs)
82+
local out, err = lua_generator.generate(ast, '5.4')
83+
assert.is_nil(err)
84+
out = out:gsub("^%s+", ""):gsub("%s+$", "")
85+
assert.same("print('hi'); print('hi')", out)
86+
end)
87+
6688
end)

0 commit comments

Comments
 (0)