Skip to content

Commit

Permalink
tests: add test for 'elseif' generation
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Oct 17, 2017
1 parent 0c1e3ab commit 0ec8521
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/coder_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,28 @@ describe("Titan code generator ", function()
assert.truthy(ok, err)
end)

it("generates code for 'elseif'", function()
local code = [[
function getval(a: integer): integer
if a == 1 then
return 10
elseif a == 2 then
return 20
else
return 30
end
end
]]
local ast, err = parser.parse(code)
assert.truthy(ast, err)
local ok, err = checker.check(ast, code, "test.titan")
assert.truthy(ok, err)
local ok, err = generate(ast, "titan_test")
assert.truthy(ok, err)
local ok, err = call("titan_test", "assert(titan_test.getval(1) == 10);assert(titan_test.getval(2) == 20);assert(titan_test.getval(3) == 30)")
assert.truthy(ok, err)
end)

pending("handles coercion to integer", function()
local code = [[
function fn(): integer
Expand Down

3 comments on commit 0ec8521

@mascarenhas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the new tests, @hishamhm! By the way, as the .so that Titan generates can now be loaded in stock Lua we do not need to spawn a separate interpreter, which will make writing the tests a little nicer, and also lead to better error messages when tests inevitably break. We can use package.loadlib to load the .so directly.

@hishamhm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were breaking in my system because I have a different minor version installed system-wide, so I changed the tests to lua/src/lua

@mascarenhas
Copy link
Member

@mascarenhas mascarenhas commented on 0ec8521 Oct 18, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.