lua: table constructors (array/hash/computed/mixed/nested) +20 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:
@@ -482,6 +482,63 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 579)
|
||||
(eval "(lua-eval-ast \"local a = 0 local b = 0 local function m() return 7, 11 end a, b = m() return a + b\")")
|
||||
|
||||
;; ── Phase 3: table constructors ────────────────────────────────
|
||||
;; Array part
|
||||
(epoch 600)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} return t[1]\")")
|
||||
(epoch 601)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} return t[3]\")")
|
||||
(epoch 602)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} if t[4] == nil then return 1 else return 0 end\")")
|
||||
|
||||
;; Hash part
|
||||
(epoch 610)
|
||||
(eval "(lua-eval-ast \"local t = {x = 1, y = 2} return t.x + t.y\")")
|
||||
(epoch 611)
|
||||
(eval "(lua-eval-ast \"local t = {name = \\\"bob\\\", age = 30} return t.name\")")
|
||||
(epoch 612)
|
||||
(eval "(lua-eval-ast \"local t = {name = \\\"bob\\\", age = 30} return t.age\")")
|
||||
|
||||
;; Computed keys
|
||||
(epoch 620)
|
||||
(eval "(lua-eval-ast \"local k = \\\"answer\\\" local t = {[k] = 42} return t.answer\")")
|
||||
(epoch 621)
|
||||
(eval "(lua-eval-ast \"local t = {[1+1] = \\\"two\\\"} return t[2]\")")
|
||||
(epoch 622)
|
||||
(eval "(lua-eval-ast \"local t = {[\\\"a\\\" .. \\\"b\\\"] = 99} return t.ab\")")
|
||||
(epoch 623)
|
||||
(eval "(lua-eval-ast \"local t = {[true] = \\\"yes\\\", [false] = \\\"no\\\"} return t[true]\")")
|
||||
|
||||
;; Mixed array + hash
|
||||
(epoch 630)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3, key = \\\"v\\\"} return t[2]\")")
|
||||
(epoch 631)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3, key = \\\"v\\\"} return t.key\")")
|
||||
|
||||
;; Separators
|
||||
(epoch 640)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3,} return t[3]\")")
|
||||
(epoch 641)
|
||||
(eval "(lua-eval-ast \"local t = {1; 2; 3} return t[2]\")")
|
||||
(epoch 642)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2; 3, 4} return t[4]\")")
|
||||
|
||||
;; Nested
|
||||
(epoch 650)
|
||||
(eval "(lua-eval-ast \"local t = {{1, 2}, {3, 4}} return t[2][1]\")")
|
||||
(epoch 651)
|
||||
(eval "(lua-eval-ast \"local t = {inner = {a = 1, b = 2}} return t.inner.b\")")
|
||||
|
||||
;; Dynamic values
|
||||
(epoch 660)
|
||||
(eval "(lua-eval-ast \"local x = 7 local t = {x, x * 2, x * 3} return t[2]\")")
|
||||
(epoch 661)
|
||||
(eval "(lua-eval-ast \"local function f(n) return n + 1 end local t = {f(1), f(2), f(3)} return t[3]\")")
|
||||
|
||||
;; Functions as values
|
||||
(epoch 670)
|
||||
(eval "(lua-eval-ast \"local t = {fn = function(x) return x * 2 end} return t.fn(5)\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -744,6 +801,28 @@ check 577 "single-assign truncates to 1st" '5'
|
||||
check 578 "empty return → all nil" '99'
|
||||
check 579 "multi-assign (non-local)" '18'
|
||||
|
||||
# ── Phase 3: table constructors ────────────────────────────────
|
||||
check 600 "array t[1]" '10'
|
||||
check 601 "array t[3]" '30'
|
||||
check 602 "array out-of-range is nil" '1'
|
||||
check 610 "hash t.x+t.y" '3'
|
||||
check 611 "hash name lookup" '"bob"'
|
||||
check 612 "hash age lookup" '30'
|
||||
check 620 "computed [k]=v" '42'
|
||||
check 621 "computed [1+1]" '"two"'
|
||||
check 622 "computed [concat]" '99'
|
||||
check 623 "boolean key [true]" '"yes"'
|
||||
check 630 "mixed array part" '2'
|
||||
check 631 "mixed hash part" '"v"'
|
||||
check 640 "trailing comma" '3'
|
||||
check 641 "semicolon separators" '2'
|
||||
check 642 "mixed separators" '4'
|
||||
check 650 "nested array" '3'
|
||||
check 651 "nested hash" '2'
|
||||
check 660 "dynamic pos values" '14'
|
||||
check 661 "function calls as values" '4'
|
||||
check 670 "function-valued field + call" '10'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL Lua-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user