js-on-sx: String replace/search/match + Array.from
String: replace, search, match now work with either string or regex arg. Regex path uses js-string-index-of on source (case-adjusted when ignoreCase set). Array.from(iter, mapFn?) normalizes via js-iterable-to-list and optionally applies mapFn. Fixed dict-set! on list bug in js-regex-stub-exec — just omit the index/input metadata, spec-breaking but tests that just check [0] work. 407/409 unit (+8), 148/148 slice unchanged.
This commit is contained in:
@@ -1035,6 +1035,24 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 2202)
|
||||
(eval "(js-eval \"var s=''; for (var c of 'abc') s=s+c; s\")")
|
||||
|
||||
;; ── Phase 11.strings2: replace/search/match + Array.from ───────
|
||||
(epoch 2300)
|
||||
(eval "(js-eval \"'hello world'.replace('world', 'JS')\")")
|
||||
(epoch 2301)
|
||||
(eval "(js-eval \"'hello'.replace(/l/, 'L')\")")
|
||||
(epoch 2302)
|
||||
(eval "(js-eval \"'hello'.search('ll')\")")
|
||||
(epoch 2303)
|
||||
(eval "(js-eval \"'hello'.search(/ll/)\")")
|
||||
(epoch 2304)
|
||||
(eval "(js-eval \"'hello'.match('ll')[0]\")")
|
||||
(epoch 2305)
|
||||
(eval "(js-eval \"Array.from([1,2,3]).length\")")
|
||||
(epoch 2306)
|
||||
(eval "(js-eval \"Array.from('abc').length\")")
|
||||
(epoch 2307)
|
||||
(eval "(js-eval \"Array.from([1,2,3], (x)=>x*2).join(',')\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
|
||||
@@ -1591,6 +1609,16 @@ check 2200 "for-of array" '6'
|
||||
check 2201 "for-in object keys count" '2'
|
||||
check 2202 "for-of string" '"abc"'
|
||||
|
||||
# ── Phase 11.strings2 ─────────────────────────────────────────
|
||||
check 2300 "replace string" '"hello JS"'
|
||||
check 2301 "replace regex" '"heLlo"'
|
||||
check 2302 "search string" '2'
|
||||
check 2303 "search regex" '2'
|
||||
check 2304 "match string" '"ll"'
|
||||
check 2305 "Array.from array" '3'
|
||||
check 2306 "Array.from string" '3'
|
||||
check 2307 "Array.from w/ map" '"2,4,6"'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user