lua: generic for-in; ipairs/pairs/next; arity-tolerant fns +9 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -681,6 +681,35 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 911)
|
||||
(eval "(lua-eval-ast \"local function f() return 99 end local function handler(e) return e end local ok, v = xpcall(f, handler) return v\")")
|
||||
|
||||
;; ── Phase 4: generic `for … in …` ──────────────────────────────
|
||||
;; ipairs over array
|
||||
(epoch 950)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} local sum = 0 for i, v in ipairs(t) do sum = sum + v end return sum\")")
|
||||
(epoch 951)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} local last = 0 for i, v in ipairs(t) do last = i end return last\")")
|
||||
(epoch 952)
|
||||
(eval "(lua-eval-ast \"local t = {} local count = 0 for i, v in ipairs(t) do count = count + 1 end return count\")")
|
||||
(epoch 953)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, nil, 4} local c = 0 for i, v in ipairs(t) do c = c + 1 end return c\")")
|
||||
|
||||
;; pairs over hash
|
||||
(epoch 960)
|
||||
(eval "(lua-eval-ast \"local t = {a = 1, b = 2, c = 3} local sum = 0 for k, v in pairs(t) do sum = sum + v end return sum\")")
|
||||
(epoch 961)
|
||||
(eval "(lua-eval-ast \"local t = {x = 1, y = 2, z = 3} local n = 0 for k, v in pairs(t) do n = n + 1 end return n\")")
|
||||
|
||||
;; custom stateful iterator (if-else-return, works around early-return limit)
|
||||
(epoch 970)
|
||||
(eval "(lua-eval-ast \"local function range(n) local i = 0 return function() i = i + 1 if i > n then return nil else return i end end end local c = 0 for x in range(5) do c = c + x end return c\")")
|
||||
|
||||
;; 3-value iterator form (f, s, var)
|
||||
(epoch 971)
|
||||
(eval "(lua-eval-ast \"local function step(max, i) if i >= max then return nil else return i + 1, (i + 1) * (i + 1) end end local sum = 0 for i, v in step, 4, 0 do sum = sum + v end return sum\")")
|
||||
|
||||
;; pairs ignores __meta key
|
||||
(epoch 980)
|
||||
(eval "(lua-eval-ast \"local t = setmetatable({x = 1, y = 2}, {}) local n = 0 for k in pairs(t) do n = n + 1 end return n\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1022,6 +1051,17 @@ check 906 "nested pcall" '"outer:inner"'
|
||||
check 910 "xpcall invokes handler" '"H:raw"'
|
||||
check 911 "xpcall ok path" '99'
|
||||
|
||||
# ── Phase 4: generic `for … in …` ─────────────────────────────
|
||||
check 950 "ipairs sum" '60'
|
||||
check 951 "ipairs last index" '3'
|
||||
check 952 "ipairs empty → 0" '0'
|
||||
check 953 "ipairs stops at nil" '2'
|
||||
check 960 "pairs hash sum" '6'
|
||||
check 961 "pairs hash count" '3'
|
||||
check 970 "stateful closure iter" '15'
|
||||
check 971 "3-value iterator form" '30'
|
||||
check 980 "pairs skips __meta" '2'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL Lua-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user