Add new test case for stack handling.

This commit is contained in:
Ian Farmer
2008-01-16 06:07:59 +00:00
parent 8570761928
commit 1cddbe97a2
2 changed files with 51 additions and 1 deletions

View File

@@ -131,8 +131,12 @@ public class LuaJTest extends TestCase {
runTest( "simplemetatables" );
}
public void testStack() throws IOException, InterruptedException {
runTest( "stack" );
}
public void testStrLib() throws IOException, InterruptedException {
runTest( "strlib" );
runTest( "strlib" );
}
public void testTable() throws IOException, InterruptedException {

46
src/test/res/stack.lua Normal file
View File

@@ -0,0 +1,46 @@
-- This test case computes and outputs the sums of the first n
-- integers for n from 1 to 100 in the most ridiculous way possible.
-- The point is to exercise code related to varargs & argument passing
-- in the hopes of detecting bug(s) in stack resizing code.
local function upto(n)
local t = {}
for i = 1, n do
t[i] = i
end
return unpack(t)
end
local function map(f, ...)
local args = { ... }
local result = {}
local i = 1
while args[i] do
result[i] = f(args[i])
i = i + 1
end
return unpack(result)
end
local function join(sep, ...)
return table.concat({ ... }, sep)
end
local i = 1
local j = 1
while i < 200 do
local params = join(", ", map(function(x) return("x"..x) end, upto(i)))
local body = join(" + ", map(function(x) return("x"..x) end, upto(i)))
local func = "function f(" .. params .. ")\n return(" .. body .. ")\nend"
local args = join(", ", map(function(x) return tostring(x) end, upto(i)))
local chunk = func .. "\nreturn f( " .. args .. " )"
local co = coroutine.create(assert(loadstring(chunk, "test #"..i)))
print(coroutine.resume(co))
i = i + j
j = j + 1
end