opencode/packages/codemode-rust/conformance/cases/std-string-extras.js
kommander 7dd5025216 feat(codemode): add String normalize, raw, isWellFormed and toWellFormed
normalize uses the unicode-normalization crate (pure Rust, the standard
NFC/NFD/NFKC/NFKD tables); the stripped embed example grows from 3047304
to 3178872 bytes. Program strings are UTF-8, so isWellFormed is always
true and toWellFormed returns its receiver. repeat and padStart report the
reference's limit errors.
2026-11-18 18:56:09 +01:00

10 lines
683 B
JavaScript

const out = []
out.push("\u0041\u030A".normalize(), "Å".normalize("NFD").length, "fi".normalize("NFKC"), "fi".normalize("NFKD"), "abc".normalize("NFC"))
try { "a".normalize("nope") } catch (e) { out.push(e.name, e.message) }
out.push("abc".isWellFormed(), "abc".toWellFormed())
out.push(String.raw({ raw: ["x", "y", "z"] }, 1), String.raw({ raw: { length: 2, 0: "p", 1: "q" } }, { toString() { return "!" } }))
try { String.raw({}) } catch (e) { out.push(e.name, e.message) }
try { "a".repeat(-1) } catch (e) { out.push(e.name, e.message) }
try { "a".padStart(2 ** 25) } catch (e) { out.push(e.name, e.message) }
out.push("a".split(undefined, 0), "a".split(undefined))
return out