You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ravi/tests/language/ravi_tests3.ravi

106 lines
1.2 KiB

-- These tests are for new backend
local compile = function(f)
if ravi.jit() then
assert(ravi.compile(f))
end
return true
end
local x = function() end
compile(x)
x = function() return 42 end
compile(x)
assert(x() == 42)
x = function() return 4.256 end
compile(x)
assert(x() == 4.256)
x = function() return 'hello' end
compile(x)
assert(x() == 'hello')
x = function()
local j
for i=1,10 do
for k = 0,5,5 do
j = k
end
end
return j
end
compile(x)
assert(x() == 5)
x = function()
local a,b = false, true
return a
end
compile(x)
assert(not x())
x = function()
local a
if 2 < 5 then
a = true
else
a = false
end
end
compile(x)
assert(not x())
local y
y = function()
return x()
end
compile(y)
assert(not y())
x = function()
print 'Good if this prints'
end
compile(x)
x()
x = function()
if 8 > 9 then
return 8
elseif 5 >= 4 then
return 5
else
return 9
end
end
compile(x)
assert(x() == 5)
x = function()
local j = -99
for i = 10,1,-1 do
j = i
end
return j
end
ravi.compile(x)
assert(x() == 1)
x = function()
local j = -9.9
for i = 10.5,1.5,-1.0 do
j = i
end
return j
end
ravi.compile(x)
assert(x() == 1.5)
print'Ok'