Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197/** Property-based fuzz tests for the XML attribute coder in `./xml-coding.ts`. This is a cross-syntax transformer (raw text to double-quoted XML attribute value), so the boundary cases matter: the round-trip `unescapeXmlAttribute(escapeXmlAttribute(s)) === s` must hold for every string, including active delimiters, entity-shaped text, control characters, and astral code points; escaped output must never contain a raw attribute-breaking character; and `isDigitCodePoint` must agree with the ASCII `0`..`9` range. Only the unescape-after-escape direction round-trips: escaping is not surjective onto its own output (for example `'` decodes to `'`, which escaping leaves unchanged), so the reverse direction is not a property. Run plan and seed policy: see `../fuzz-budget.ts`. @module */
import { assert, asyncProperty, constantFrom, integer, oneof, string,} from 'fast-check';
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { fuzzRunPlan, } from '../fuzz-budget.ts';import { escapeXmlAttribute, isDigitCodePoint, unescapeXmlAttribute,} from './xml-coding.ts';
//region Constants and arbitraries
/** Run plan resolved once for every property in this file. */const RUN = fuzzRunPlan();
/** Characters escaping must never emit raw in a double-quoted attribute. */const ATTRIBUTE_BREAKING_CHARS = [ '"', '<', '>', '\n', '\r', '\t',] as const;
/** ASCII code point of the digit `0`. */const DIGIT_ZERO_CODE_POINT = 48;
/** ASCII code point of the digit `9`. */const DIGIT_NINE_CODE_POINT = 57;
/** Highest Unicode code point (`U+10FFFF`); upper bound for the digit-range property so the whole code space is sampled. */const MAX_UNICODE_CODE_POINT = 1_114_111;
/** Arbitrary text rich in characters that exercise the coder's branches: the escaped delimiters, entity punctuation, an apostrophe, control characters, a no-break space, and an astral code point. Unioned with the default string arbitrary for broader coverage. */const attributeTextArbitrary = oneof( string(), string({ unit: constantFrom( '&', '"', '<', '>', '\n', '\r', '\t', '\'', 'a', '#', ';', 'x', '0', ' ', '\u{1F600}', ), },),);
//endregion Constants and arbitraries
await describe({ name: '', children: [ //region Round-trip and delimiter safety
describe({ name: escapeXmlAttribute.name, children: [ it({ name: 'unescape after escape recovers the original string', timeout: RUN.timeout, fn: async () => { await assert( asyncProperty( attributeTextArbitrary, async function roundTrips(value,) { /** Escaped attribute text. */ const escaped = escapeXmlAttribute({ value, },); expect(unescapeXmlAttribute({ value: escaped, },),).toBe(value,); }, ), RUN.params, ); }, },),
it({ name: 'escaped output contains no raw attribute-breaking character', timeout: RUN.timeout, fn: async () => { await assert( asyncProperty( attributeTextArbitrary, async function noRawDelimiters(value,) { /** Escaped attribute text. */ const escaped = escapeXmlAttribute({ value, },); ATTRIBUTE_BREAKING_CHARS.forEach(function absent(delimiter,) { expect(escaped.includes(delimiter,),).toBe(false,); },); }, ), RUN.params, ); }, },), ], },),
//endregion Round-trip and delimiter safety
//region isDigitCodePoint
describe({ name: isDigitCodePoint.name, children: [ it({ name: 'agrees with the ASCII 0..9 range across code points', timeout: RUN.timeout, fn: async () => { await assert( asyncProperty( integer({ min: -10, max: MAX_UNICODE_CODE_POINT, },), async function matchesRange(codePoint,) { /** Whether the code point falls in the ASCII digit range. */ const inRange = (codePoint >= DIGIT_ZERO_CODE_POINT) && (codePoint <= DIGIT_NINE_CODE_POINT); expect(isDigitCodePoint({ codePoint, },),).toBe(inRange,); }, ), RUN.params, ); }, },), ], },),
//endregion isDigitCodePoint ],},);