lua: extend patterns to match/gmatch/gsub; gsub with string/function/table repl +6 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:
@@ -964,6 +964,20 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1881)
|
||||
(eval "(lua-eval-ast \"local function f() return 10, 20 end return (f()) + 1\")")
|
||||
|
||||
;; ── Lua patterns in match/gmatch/gsub ────────────────────────
|
||||
(epoch 1890)
|
||||
(eval "(lua-eval-ast \"return string.match(\\\"hello123world\\\", \\\"%d+\\\")\")")
|
||||
(epoch 1891)
|
||||
(eval "(lua-eval-ast \"return string.match(\\\"name=bob\\\", \\\"%a+\\\")\")")
|
||||
(epoch 1892)
|
||||
(eval "(lua-eval-ast \"local c = 0 for w in string.gmatch(\\\"a b c d\\\", \\\"%a\\\") do c = c + 1 end return c\")")
|
||||
(epoch 1893)
|
||||
(eval "(lua-eval-ast \"local r, n = string.gsub(\\\"1 + 2 = 3\\\", \\\"%d\\\", \\\"X\\\") return r .. \\\":\\\" .. n\")")
|
||||
(epoch 1894)
|
||||
(eval "(lua-eval-ast \"if string.find(\\\"hello\\\", \\\"^hel\\\") then return 1 else return 0 end\")")
|
||||
(epoch 1895)
|
||||
(eval "(lua-eval-ast \"if string.find(\\\"hello\\\", \\\"^wor\\\") then return 0 else return 1 end\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1460,6 +1474,14 @@ check 1870 "a:add():add():add().x chain" '60'
|
||||
check 1880 "(f()) scalar coerce" '1'
|
||||
check 1881 "(f()) + 1 scalar" '11'
|
||||
|
||||
# ── Lua patterns in match/gmatch/gsub ────────────────────────
|
||||
check 1890 "match %d+" '"123"'
|
||||
check 1891 "match %a+" '"name"'
|
||||
check 1892 "gmatch %a count" '4'
|
||||
check 1893 "gsub %d → X" '"X + X = X:3"'
|
||||
check 1894 "find ^ anchor hit" '1'
|
||||
check 1895 "find ^ anchor miss" '1'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL Lua-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user