lua: table library (insert/remove/concat/sort/unpack) +13 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:
@@ -804,6 +804,34 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1261)
|
||||
(eval "(lua-eval-ast \"local r = math.random(5, 10) return r >= 5 and r <= 10\")")
|
||||
|
||||
;; ── Phase 6: table library ────────────────────────────────────
|
||||
(epoch 1300)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3} table.insert(t, 4) return #t\")")
|
||||
(epoch 1301)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3} table.insert(t, 4) return t[4]\")")
|
||||
(epoch 1302)
|
||||
(eval "(lua-eval-ast \"local t = {10, 30} table.insert(t, 2, 20) return t[2]\")")
|
||||
(epoch 1303)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} table.insert(t, 1, 5) return t[1] * 100 + t[2]\")")
|
||||
(epoch 1310)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3} local v = table.remove(t) return v * 10 + #t\")")
|
||||
(epoch 1311)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} table.remove(t, 1) return t[1] * 10 + t[2]\")")
|
||||
(epoch 1320)
|
||||
(eval "(lua-eval-ast \"local t = {\\\"a\\\", \\\"b\\\", \\\"c\\\"} return table.concat(t)\")")
|
||||
(epoch 1321)
|
||||
(eval "(lua-eval-ast \"local t = {\\\"a\\\", \\\"b\\\", \\\"c\\\"} return table.concat(t, \\\"-\\\")\")")
|
||||
(epoch 1322)
|
||||
(eval "(lua-eval-ast \"local t = {1, 2, 3, 4} return table.concat(t, \\\",\\\", 2, 3)\")")
|
||||
(epoch 1330)
|
||||
(eval "(lua-eval-ast \"local t = {3, 1, 4, 1, 5, 9, 2, 6} table.sort(t) return t[1] * 100 + t[8]\")")
|
||||
(epoch 1331)
|
||||
(eval "(lua-eval-ast \"local t = {3, 1, 2} table.sort(t, function(a, b) return a > b end) return t[1] * 100 + t[3]\")")
|
||||
(epoch 1340)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30} local a, b, c = unpack(t) return a + b + c\")")
|
||||
(epoch 1341)
|
||||
(eval "(lua-eval-ast \"local t = {10, 20, 30, 40} local a, b = table.unpack(t, 2, 3) return a + b\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1206,6 +1234,21 @@ check 1251 "math.modf(3.5) int part" '3'
|
||||
check 1260 "math.random(n) in range" 'true'
|
||||
check 1261 "math.random(m,n) in range" 'true'
|
||||
|
||||
# ── Phase 6: table library ────────────────────────────────────
|
||||
check 1300 "table.insert append → #t" '4'
|
||||
check 1301 "table.insert value" '4'
|
||||
check 1302 "table.insert(t,pos,v) mid" '20'
|
||||
check 1303 "table.insert(t,1,v) prepend" '510'
|
||||
check 1310 "table.remove() last" '33'
|
||||
check 1311 "table.remove(t,1) shift" '230'
|
||||
check 1320 "table.concat no sep" '"abc"'
|
||||
check 1321 "table.concat with sep" '"a-b-c"'
|
||||
check 1322 "table.concat range" '"2,3"'
|
||||
check 1330 "table.sort asc" '109'
|
||||
check 1331 "table.sort desc via cmp" '301'
|
||||
check 1340 "unpack global" '60'
|
||||
check 1341 "table.unpack(t,i,j)" '50'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL Lua-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user