lua: tonumber(s, base) for bases 2-36 +3 tests; math.lua past assert #21
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:
@@ -1538,12 +1538,50 @@
|
||||
(else (lua-to-display v)))))
|
||||
(else (lua-to-display v)))))
|
||||
|
||||
(define
|
||||
lua-parse-int-base
|
||||
(fn (s base)
|
||||
(let ((trimmed (trim s)) (neg false) (i 0) (n 0) (valid false))
|
||||
(begin
|
||||
(when (and (> (len trimmed) 0) (= (char-at trimmed 0) "-"))
|
||||
(begin (set! neg true) (set! i 1)))
|
||||
(when (and (> (len trimmed) i) (= (char-at trimmed i) "+"))
|
||||
(set! i (+ i 1)))
|
||||
(define
|
||||
pi-loop
|
||||
(fn ()
|
||||
(when (< i (len trimmed))
|
||||
(let ((c (char-at trimmed i)))
|
||||
(let ((d (cond
|
||||
((and (>= c "0") (<= c "9")) (- (char-code c) (char-code "0")))
|
||||
((and (>= c "a") (<= c "z")) (+ 10 (- (char-code c) (char-code "a"))))
|
||||
((and (>= c "A") (<= c "Z")) (+ 10 (- (char-code c) (char-code "A"))))
|
||||
(else -1))))
|
||||
(cond
|
||||
((or (< d 0) (>= d base)) (set! i (len trimmed)))
|
||||
(else
|
||||
(begin
|
||||
(set! n (+ (* n base) d))
|
||||
(set! valid true)
|
||||
(set! i (+ i 1))
|
||||
(pi-loop)))))))))
|
||||
(pi-loop)
|
||||
(cond
|
||||
((not valid) nil)
|
||||
((< i (len trimmed)) nil)
|
||||
(neg (- 0 n))
|
||||
(else n))))))
|
||||
|
||||
(define
|
||||
lua-tonumber
|
||||
(fn (&rest args)
|
||||
(let ((v (first args))
|
||||
(base (if (> (len args) 1) (nth args 1) nil)))
|
||||
(cond
|
||||
((not (= base nil))
|
||||
(cond
|
||||
((= (type-of v) "string") (lua-parse-int-base v base))
|
||||
(else nil)))
|
||||
((= (type-of v) "number") v)
|
||||
((= (type-of v) "string") (lua-to-number v))
|
||||
(else nil)))))
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"totals": {
|
||||
"pass": 1,
|
||||
"fail": 12,
|
||||
"timeout": 3,
|
||||
"fail": 11,
|
||||
"timeout": 4,
|
||||
"skip": 8,
|
||||
"total": 24,
|
||||
"runnable": 16,
|
||||
@@ -11,11 +11,15 @@
|
||||
"top_failure_modes": [
|
||||
[
|
||||
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
8
|
||||
6
|
||||
],
|
||||
[
|
||||
"timeout",
|
||||
3
|
||||
4
|
||||
],
|
||||
[
|
||||
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
|
||||
2
|
||||
],
|
||||
[
|
||||
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
|
||||
@@ -28,10 +32,6 @@
|
||||
[
|
||||
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
|
||||
1
|
||||
],
|
||||
[
|
||||
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
|
||||
1
|
||||
]
|
||||
],
|
||||
"results": [
|
||||
@@ -51,19 +51,19 @@
|
||||
"name": "attrib.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
|
||||
"ms": 6137
|
||||
"ms": 6133
|
||||
},
|
||||
{
|
||||
"name": "big.lua",
|
||||
"status": "timeout",
|
||||
"reason": "per-test timeout",
|
||||
"ms": 8008
|
||||
"ms": 8007
|
||||
},
|
||||
{
|
||||
"name": "calls.lua",
|
||||
"status": "fail",
|
||||
"reason": "undefined symbol: fat\\",
|
||||
"ms": 4744
|
||||
"ms": 5786
|
||||
},
|
||||
{
|
||||
"name": "checktable.lua",
|
||||
@@ -87,7 +87,7 @@
|
||||
"name": "constructs.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
|
||||
"ms": 6638
|
||||
"ms": 7418
|
||||
},
|
||||
{
|
||||
"name": "db.lua",
|
||||
@@ -99,13 +99,13 @@
|
||||
"name": "errors.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 3109
|
||||
"ms": 4168
|
||||
},
|
||||
{
|
||||
"name": "events.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 7069
|
||||
"ms": 7884
|
||||
},
|
||||
{
|
||||
"name": "files.lua",
|
||||
@@ -123,13 +123,13 @@
|
||||
"name": "literals.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 1866
|
||||
"ms": 1796
|
||||
},
|
||||
{
|
||||
"name": "locals.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
|
||||
"ms": 1612
|
||||
"ms": 1655
|
||||
},
|
||||
{
|
||||
"name": "main.lua",
|
||||
@@ -140,44 +140,44 @@
|
||||
{
|
||||
"name": "math.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 3983
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
|
||||
"ms": 5457
|
||||
},
|
||||
{
|
||||
"name": "nextvar.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 6968
|
||||
},
|
||||
{
|
||||
"name": "pm.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 5852
|
||||
},
|
||||
{
|
||||
"name": "sort.lua",
|
||||
"status": "timeout",
|
||||
"reason": "per-test timeout",
|
||||
"ms": 8007
|
||||
},
|
||||
{
|
||||
"name": "pm.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 6576
|
||||
},
|
||||
{
|
||||
"name": "sort.lua",
|
||||
"status": "timeout",
|
||||
"reason": "per-test timeout",
|
||||
"ms": 8008
|
||||
},
|
||||
{
|
||||
"name": "strings.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 3925
|
||||
"ms": 4708
|
||||
},
|
||||
{
|
||||
"name": "vararg.lua",
|
||||
"status": "fail",
|
||||
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
|
||||
"ms": 2195
|
||||
"ms": 2227
|
||||
},
|
||||
{
|
||||
"name": "verybig.lua",
|
||||
"status": "pass",
|
||||
"reason": "",
|
||||
"ms": 930
|
||||
"ms": 959
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
# Lua-on-SX conformance scoreboard
|
||||
|
||||
**Pass rate:** 1/16 runnable (6.2%)
|
||||
fail=12 timeout=3 skip=8 total=24
|
||||
fail=11 timeout=4 skip=8 total=24
|
||||
|
||||
## Top failure modes
|
||||
|
||||
- **8x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
|
||||
- **3x** timeout
|
||||
- **6x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
|
||||
- **4x** timeout
|
||||
- **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
|
||||
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\
|
||||
- **1x** undefined symbol: fat\
|
||||
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat
|
||||
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
|
||||
|
||||
## Per-test results
|
||||
|
||||
@@ -18,25 +18,25 @@ fail=12 timeout=3 skip=8 total=24
|
||||
|---|---|---|---:|
|
||||
| all.lua | skip | driver uses dofile to chain other tests | 0 |
|
||||
| api.lua | skip | requires testC (C debug library) | 0 |
|
||||
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6137 |
|
||||
| big.lua | timeout | per-test timeout | 8008 |
|
||||
| calls.lua | fail | undefined symbol: fat\ | 4744 |
|
||||
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6133 |
|
||||
| big.lua | timeout | per-test timeout | 8007 |
|
||||
| calls.lua | fail | undefined symbol: fat\ | 5786 |
|
||||
| checktable.lua | skip | internal debug helpers | 0 |
|
||||
| closure.lua | timeout | per-test timeout | 8008 |
|
||||
| code.lua | skip | bytecode inspection via debug library | 0 |
|
||||
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 6638 |
|
||||
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 7418 |
|
||||
| db.lua | skip | debug library | 0 |
|
||||
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3109 |
|
||||
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7069 |
|
||||
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4168 |
|
||||
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7884 |
|
||||
| files.lua | skip | io library | 0 |
|
||||
| gc.lua | skip | collectgarbage / finalisers | 0 |
|
||||
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1866 |
|
||||
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1612 |
|
||||
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1796 |
|
||||
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1655 |
|
||||
| main.lua | skip | standalone interpreter driver | 0 |
|
||||
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3983 |
|
||||
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6968 |
|
||||
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5852 |
|
||||
| sort.lua | timeout | per-test timeout | 8007 |
|
||||
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3925 |
|
||||
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2195 |
|
||||
| verybig.lua | pass | - | 930 |
|
||||
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 5457 |
|
||||
| nextvar.lua | timeout | per-test timeout | 8007 |
|
||||
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6576 |
|
||||
| sort.lua | timeout | per-test timeout | 8008 |
|
||||
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4708 |
|
||||
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2227 |
|
||||
| verybig.lua | pass | - | 959 |
|
||||
|
||||
@@ -978,6 +978,14 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1895)
|
||||
(eval "(lua-eval-ast \"if string.find(\\\"hello\\\", \\\"^wor\\\") then return 0 else return 1 end\")")
|
||||
|
||||
;; ── tonumber with base (Lua 5.1) ──────────────────────────────
|
||||
(epoch 1900)
|
||||
(eval "(lua-eval-ast \"return tonumber('1010', 2)\")")
|
||||
(epoch 1901)
|
||||
(eval "(lua-eval-ast \"return tonumber('FF', 16)\")")
|
||||
(epoch 1902)
|
||||
(eval "(lua-eval-ast \"if tonumber('99', 8) == nil then return 1 else return 0 end\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1482,6 +1490,11 @@ check 1893 "gsub %d → X" '"X + X = X:3"'
|
||||
check 1894 "find ^ anchor hit" '1'
|
||||
check 1895 "find ^ anchor miss" '1'
|
||||
|
||||
# ── tonumber with base ───────────────────────────────────────
|
||||
check 1900 "tonumber('1010', 2)" '10'
|
||||
check 1901 "tonumber('FF', 16)" '255'
|
||||
check 1902 "tonumber('99', 8) → nil" '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