Skip to content

Commit

Permalink
tests: test literal negative step in 'for'
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Oct 17, 2017
1 parent 0e6f921 commit 450b658
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion spec/coder_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Titan code generator ", function()
assert.truthy(ok, err)
end)

it("tests literals in 'for'", function()
it("tests postive literals in 'for'", function()
local code = [[
function forstep(): integer
local v: integer = 0
Expand All @@ -142,6 +142,26 @@ describe("Titan code generator ", function()
assert.truthy(ok, err)
end)

it("tests negative literals in 'for'", function()
local code = [[
function forstep(): integer
local v: integer = 0
for i = 10, 1, -2 do
v = v + i
end
return v
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", "x = titan_test.forstep();assert(x==30)")
assert.truthy(ok, err)
end)

it("tests nil element in 'not'", function()
local code = [[
function testset(t: {integer}, i: integer, v: integer): integer
Expand Down

0 comments on commit 450b658

Please sign in to comment.