js-on-sx: String.prototype extensions + Object/Array builtins
Strings: includes, startsWith, endsWith, trim, trimStart, trimEnd, repeat, padStart, padEnd, toString, valueOf. Object: keys, values, entries, assign, freeze (no-op). Array: isArray, of. All wired into js-global. 17 new unit tests. 357/359 unit (+17), 148/148 slice unchanged.
This commit is contained in:
@@ -899,6 +899,44 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1310)
|
||||
(eval "(js-eval \"var sum = 0; for (var i = 1; i <= 5; i++) sum = sum + i; sum\")")
|
||||
|
||||
;; ── Phase 11.strings: extended String.prototype methods ─────────
|
||||
(epoch 1400)
|
||||
(eval "(js-eval \"'hello world'.includes('world')\")")
|
||||
(epoch 1401)
|
||||
(eval "(js-eval \"'hello world'.includes('xyz')\")")
|
||||
(epoch 1402)
|
||||
(eval "(js-eval \"'hello'.startsWith('hel')\")")
|
||||
(epoch 1403)
|
||||
(eval "(js-eval \"'hello'.startsWith('llo')\")")
|
||||
(epoch 1404)
|
||||
(eval "(js-eval \"'hello'.endsWith('llo')\")")
|
||||
(epoch 1405)
|
||||
(eval "(js-eval \"'hello'.endsWith('hel')\")")
|
||||
(epoch 1406)
|
||||
(eval "(js-eval \"' hi '.trim()\")")
|
||||
(epoch 1407)
|
||||
(eval "(js-eval \"'abc'.repeat(3)\")")
|
||||
(epoch 1408)
|
||||
(eval "(js-eval \"'5'.padStart(3, '0')\")")
|
||||
(epoch 1409)
|
||||
(eval "(js-eval \"'5'.padEnd(3, 'x')\")")
|
||||
(epoch 1410)
|
||||
(eval "(js-eval \"'hello'.toString()\")")
|
||||
|
||||
;; ── Phase 11.object: Object builtin ─────────────────────────────
|
||||
(epoch 1500)
|
||||
(eval "(js-eval \"Object.keys({a:1, b:2}).length\")")
|
||||
(epoch 1501)
|
||||
(eval "(js-eval \"Object.values({a:1, b:2}).length\")")
|
||||
(epoch 1502)
|
||||
(eval "(js-eval \"var o = Object.assign({a:1}, {b:2}); o.a + o.b\")")
|
||||
(epoch 1503)
|
||||
(eval "(js-eval \"Array.isArray([1,2])\")")
|
||||
(epoch 1504)
|
||||
(eval "(js-eval \"Array.isArray('abc')\")")
|
||||
(epoch 1505)
|
||||
(eval "(js-eval \"Array.of(1,2,3).length\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1377,6 +1415,27 @@ check 1308 "a[1]++" '3'
|
||||
check 1309 "for-loop x++" '8'
|
||||
check 1310 "for-loop accumulator" '15'
|
||||
|
||||
# ── Phase 11.strings: extended String.prototype ─────────────────
|
||||
check 1400 "includes match" 'true'
|
||||
check 1401 "includes no match" 'false'
|
||||
check 1402 "startsWith match" 'true'
|
||||
check 1403 "startsWith no match" 'false'
|
||||
check 1404 "endsWith match" 'true'
|
||||
check 1405 "endsWith no match" 'false'
|
||||
check 1406 "trim whitespace" '"hi"'
|
||||
check 1407 "repeat 3x" '"abcabcabc"'
|
||||
check 1408 "padStart 0s" '"005"'
|
||||
check 1409 "padEnd x" '"5xx"'
|
||||
check 1410 "toString self" '"hello"'
|
||||
|
||||
# ── Phase 11.object: Object + Array ─────────────────────────────
|
||||
check 1500 "Object.keys count" '2'
|
||||
check 1501 "Object.values.length" '2'
|
||||
check 1502 "Object.assign merge" '3'
|
||||
check 1503 "Array.isArray yes" 'true'
|
||||
check 1504 "Array.isArray no" 'false'
|
||||
check 1505 "Array.of length" '3'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user