From a6f46413c0cf18819693488385ed82bdac8cf998 Mon Sep 17 00:00:00 2001 From: Ian Farmer Date: Thu, 6 Dec 2007 19:16:56 +0000 Subject: [PATCH] Added 'loops' test case. This script tests the generic for loop using a Lua closure as the iterator function, which is currently broken. --- src/test/java/org/luaj/vm/LuaJTest.java | 4 ++++ src/test/res/loops.lua | 22 ++++++++++++++++++++++ src/test/res/loops.luac | Bin 0 -> 684 bytes 3 files changed, 26 insertions(+) create mode 100644 src/test/res/loops.lua create mode 100644 src/test/res/loops.luac diff --git a/src/test/java/org/luaj/vm/LuaJTest.java b/src/test/java/org/luaj/vm/LuaJTest.java index 452538e0..6c277f96 100644 --- a/src/test/java/org/luaj/vm/LuaJTest.java +++ b/src/test/java/org/luaj/vm/LuaJTest.java @@ -74,6 +74,10 @@ public class LuaJTest extends TestCase { runTest( "errors" ); } + public void testLoops() throws IOException, InterruptedException { + runTest( "loops" ); + } + public void testMathLib() throws IOException, InterruptedException { runTest( "mathlib" ); } diff --git a/src/test/res/loops.lua b/src/test/res/loops.lua new file mode 100644 index 00000000..431374c8 --- /dev/null +++ b/src/test/res/loops.lua @@ -0,0 +1,22 @@ +-- This script tests the "generic" for loop with a script iterator. + +local function stuff() + local function i(o) + if o.counter > 3 then + return nil + else + local v = o.counter + o.counter = v + 1 + return v + end + end + return i, { counter=1 } +end + +local function testfor() + for x in stuff() do + print(x) + end +end + +testfor() diff --git a/src/test/res/loops.luac b/src/test/res/loops.luac new file mode 100644 index 0000000000000000000000000000000000000000..c7cbe1a9a3e8e43b4b99667f4ec1fdae3101b79f GIT binary patch literal 684 zcmZutOG*Pl5UtKkV&V@K83cnUxX_JPNQ>agjTZK8lLtxG&oxq6=eYH$|NyZmkpb5MBaLy5YQd`PN>};Ax$3 zibU}HP5hgqasR~ep|u~2SIpsmG!&Vbx^$ThiMTFC3MVZFb{Qy%cHr(s%Zc_rLF+qI z7~>_Gizol(=Q03Kj@7B+zv_L>7uaINlV!Ub;E*k-ZLk8@LMaqY7(l|Zczcnp)r~Ck z`FHORxD<}YjA@A2xwQiX#{hox*p