fast-check
Advanced tools
Comparing version 3.22.0 to 3.23.0
@@ -0,1 +1,37 @@ | ||
# 3.23.0 | ||
_Extend usages of string-units and increased performance_ | ||
[[Code](https://github.com/dubzzz/fast-check/tree/v3.23.0)][[Diff](https://github.com/dubzzz/fast-check/compare/v3.22.0...v3.23.0)] | ||
## Features | ||
- ([PR#5366](https://github.com/dubzzz/fast-check/pull/5366)) Add support for string-`unit` on `object`/`anything` arbitrary | ||
- ([PR#5367](https://github.com/dubzzz/fast-check/pull/5367)) Add support for string-`unit` on `json` arbitrary | ||
- ([PR#5390](https://github.com/dubzzz/fast-check/pull/5390)) Add back strong unmapping capabilities to `string` | ||
## Fixes | ||
- ([PR#5327](https://github.com/dubzzz/fast-check/pull/5327)) Bug: Resist even more to external poisoning for `string` | ||
- ([PR#5368](https://github.com/dubzzz/fast-check/pull/5368)) Bug: Better support for poisoning on `stringMatching` | ||
- ([PR#5344](https://github.com/dubzzz/fast-check/pull/5344)) CI: Adapt some tests for Node v23 | ||
- ([PR#5346](https://github.com/dubzzz/fast-check/pull/5346)) CI: Drop usages of `it.concurrent` due to Node 23 failing | ||
- ([PR#5363](https://github.com/dubzzz/fast-check/pull/5363)) CI: Move to Vitest for `examples/` | ||
- ([PR#5391](https://github.com/dubzzz/fast-check/pull/5391)) CI: Preview builds using `pkg.pr.new` | ||
- ([PR#5392](https://github.com/dubzzz/fast-check/pull/5392)) CI: Connect custom templates to `pkg.pr.new` previews | ||
- ([PR#5394](https://github.com/dubzzz/fast-check/pull/5394)) CI: Install dependencies before building changesets | ||
- ([PR#5396](https://github.com/dubzzz/fast-check/pull/5396)) CI: Proper commit name on changelogs | ||
- ([PR#5393](https://github.com/dubzzz/fast-check/pull/5393)) Clean: Drop unused `examples/jest.setup.js` | ||
- ([PR#5249](https://github.com/dubzzz/fast-check/pull/5249)) Doc: Release note for fast-check 3.22.0 | ||
- ([PR#5369](https://github.com/dubzzz/fast-check/pull/5369)) Doc: Typo fix in model-based-testing.md | ||
- ([PR#5370](https://github.com/dubzzz/fast-check/pull/5370)) Doc: Add new contributor jamesbvaughan | ||
- ([PR#5383](https://github.com/dubzzz/fast-check/pull/5383)) Doc: Properly indent code snippets for the documentation | ||
- ([PR#5372](https://github.com/dubzzz/fast-check/pull/5372)) Performance: Faster `canShrinkWithoutContext` for constants | ||
- ([PR#5386](https://github.com/dubzzz/fast-check/pull/5386)) Performance: Faster generate process for `mapToConstant` | ||
- ([PR#5387](https://github.com/dubzzz/fast-check/pull/5387)) Performance: Faster tokenizer of strings | ||
- ([PR#5388](https://github.com/dubzzz/fast-check/pull/5388)) Performance: Faster initialization of `string` with faster slices | ||
- ([PR#5389](https://github.com/dubzzz/fast-check/pull/5389)) Performance: Faster initialization of `string` with pre-cached slices | ||
- ([PR#5371](https://github.com/dubzzz/fast-check/pull/5371)) Test: Add extra set of tests for `constant*` | ||
--- | ||
# 3.22.0 | ||
@@ -2,0 +38,0 @@ |
@@ -8,2 +8,3 @@ "use strict"; | ||
const symbols_1 = require("../../check/symbols"); | ||
const globals_1 = require("../../utils/globals"); | ||
const safeObjectIs = Object.is; | ||
@@ -24,8 +25,9 @@ class ConstantArbitrary extends Arbitrary_1.Arbitrary { | ||
canShrinkWithoutContext(value) { | ||
for (let idx = 0; idx !== this.values.length; ++idx) { | ||
if (safeObjectIs(this.values[idx], value)) { | ||
return true; | ||
} | ||
if (this.values.length === 1) { | ||
return safeObjectIs(this.values[0], value); | ||
} | ||
return false; | ||
if (this.fastValues === undefined) { | ||
this.fastValues = new FastConstantValuesLookup(this.values); | ||
} | ||
return this.fastValues.has(value); | ||
} | ||
@@ -40,1 +42,27 @@ shrink(value, context) { | ||
exports.ConstantArbitrary = ConstantArbitrary; | ||
class FastConstantValuesLookup { | ||
constructor(values) { | ||
this.values = values; | ||
this.fastValues = new globals_1.Set(this.values); | ||
let hasMinusZero = false; | ||
let hasPlusZero = false; | ||
if ((0, globals_1.safeHas)(this.fastValues, 0)) { | ||
for (let idx = 0; idx !== this.values.length; ++idx) { | ||
const value = this.values[idx]; | ||
hasMinusZero = hasMinusZero || safeObjectIs(value, -0); | ||
hasPlusZero = hasPlusZero || safeObjectIs(value, 0); | ||
} | ||
} | ||
this.hasMinusZero = hasMinusZero; | ||
this.hasPlusZero = hasPlusZero; | ||
} | ||
has(value) { | ||
if (value === 0) { | ||
if (safeObjectIs(value, 0)) { | ||
return this.hasPlusZero; | ||
} | ||
return this.hasMinusZero; | ||
} | ||
return (0, globals_1.safeHas)(this.fastValues, value); | ||
} | ||
} |
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.intersectGraphemeRanges = intersectGraphemeRanges; | ||
const globals_1 = require("../../../utils/globals"); | ||
const safeStringFromCodePoint = String.fromCodePoint; | ||
@@ -42,6 +43,6 @@ const safeMathMin = Math.min; | ||
min = lastMergedRange[0]; | ||
mergedRanges.pop(); | ||
(0, globals_1.safePop)(mergedRanges); | ||
} | ||
} | ||
mergedRanges.push(min === max ? [min] : [min, max]); | ||
(0, globals_1.safePush)(mergedRanges, min === max ? [min] : [min, max]); | ||
if (rangeAMax <= max) { | ||
@@ -48,0 +49,0 @@ cursorA += 1; |
@@ -31,4 +31,4 @@ "use strict"; | ||
} | ||
const stringArbitrary = settings.withUnicodeString ? fullUnicodeString_1.fullUnicodeString : string_1.string; | ||
const valueConstraints = { size: settings.size }; | ||
const stringArbitrary = 'stringUnit' in settings ? string_1.string : settings.withUnicodeString ? fullUnicodeString_1.fullUnicodeString : string_1.string; | ||
const valueConstraints = { size: settings.size, unit: settings.stringUnit }; | ||
return { | ||
@@ -35,0 +35,0 @@ key: orDefault(settings.key, stringArbitrary(valueConstraints)), |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSlicesForStringLegacy = createSlicesForStringLegacy; | ||
exports.createSlicesForString = createSlicesForString; | ||
const globals_1 = require("../../../utils/globals"); | ||
const PatternsToString_1 = require("../mappers/PatternsToString"); | ||
const MaxLengthFromMinLength_1 = require("./MaxLengthFromMinLength"); | ||
const TokenizeString_1 = require("./TokenizeString"); | ||
const dangerousStrings = [ | ||
@@ -29,3 +33,3 @@ '__defineGetter__', | ||
]; | ||
function computeCandidateString(dangerous, charArbitrary, stringSplitter) { | ||
function computeCandidateStringLegacy(dangerous, charArbitrary, stringSplitter) { | ||
let candidate; | ||
@@ -45,6 +49,6 @@ try { | ||
} | ||
function createSlicesForString(charArbitrary, stringSplitter) { | ||
function createSlicesForStringLegacy(charArbitrary, stringSplitter) { | ||
const slicesForString = []; | ||
for (const dangerous of dangerousStrings) { | ||
const candidate = computeCandidateString(dangerous, charArbitrary, stringSplitter); | ||
const candidate = computeCandidateStringLegacy(dangerous, charArbitrary, stringSplitter); | ||
if (candidate !== undefined) { | ||
@@ -56,1 +60,26 @@ (0, globals_1.safePush)(slicesForString, candidate); | ||
} | ||
const slicesPerArbitrary = new WeakMap(); | ||
function createSlicesForStringNoConstraints(charArbitrary) { | ||
const slicesForString = []; | ||
for (const dangerous of dangerousStrings) { | ||
const candidate = (0, TokenizeString_1.tokenizeString)(charArbitrary, dangerous, 0, MaxLengthFromMinLength_1.MaxLengthUpperBound); | ||
if (candidate !== undefined) { | ||
(0, globals_1.safePush)(slicesForString, candidate); | ||
} | ||
} | ||
return slicesForString; | ||
} | ||
function createSlicesForString(charArbitrary, constraints) { | ||
let slices = (0, globals_1.safeGet)(slicesPerArbitrary, charArbitrary); | ||
if (slices === undefined) { | ||
slices = createSlicesForStringNoConstraints(charArbitrary); | ||
(0, globals_1.safeSet)(slicesPerArbitrary, charArbitrary, slices); | ||
} | ||
const slicesForConstraints = []; | ||
for (const slice of slices) { | ||
if ((0, PatternsToString_1.patternsToStringUnmapperIsValidLength)(slice, constraints)) { | ||
(0, globals_1.safePush)(slicesForConstraints, slice); | ||
} | ||
} | ||
return slicesForConstraints; | ||
} |
@@ -5,10 +5,34 @@ "use strict"; | ||
exports.indexToMappedConstantUnmapperFor = indexToMappedConstantUnmapperFor; | ||
const globals_1 = require("../../../utils/globals"); | ||
const safeObjectIs = Object.is; | ||
function buildDichotomyEntries(entries) { | ||
let currentFrom = 0; | ||
const dichotomyEntries = []; | ||
for (const entry of entries) { | ||
const from = currentFrom; | ||
currentFrom = from + entry.num; | ||
const to = currentFrom - 1; | ||
dichotomyEntries.push({ from, to, entry }); | ||
} | ||
return dichotomyEntries; | ||
} | ||
function findDichotomyEntry(dichotomyEntries, choiceIndex) { | ||
let min = 0; | ||
let max = dichotomyEntries.length; | ||
while (max - min > 1) { | ||
const mid = ~~((min + max) / 2); | ||
if (choiceIndex < dichotomyEntries[mid].from) { | ||
max = mid; | ||
} | ||
else { | ||
min = mid; | ||
} | ||
} | ||
return dichotomyEntries[min]; | ||
} | ||
function indexToMappedConstantMapperFor(entries) { | ||
const dichotomyEntries = buildDichotomyEntries(entries); | ||
return function indexToMappedConstantMapper(choiceIndex) { | ||
let idx = -1; | ||
let numSkips = 0; | ||
while (choiceIndex >= numSkips) { | ||
numSkips += entries[++idx].num; | ||
} | ||
return entries[idx].build(choiceIndex - numSkips + entries[idx].num); | ||
const dichotomyEntry = findDichotomyEntry(dichotomyEntries, choiceIndex); | ||
return dichotomyEntry.entry.build(choiceIndex - dichotomyEntry.from); | ||
}; | ||
@@ -40,5 +64,5 @@ } | ||
} | ||
const choiceIndex = Object.is(value, -0) ? reverseMapping.negativeZeroIndex : reverseMapping.mapping.get(value); | ||
const choiceIndex = safeObjectIs(value, -0) ? reverseMapping.negativeZeroIndex : reverseMapping.mapping.get(value); | ||
if (choiceIndex === undefined) { | ||
throw new Error('Unknown value encountered cannot be built using this mapToConstant'); | ||
throw new globals_1.Error('Unknown value encountered cannot be built using this mapToConstant'); | ||
} | ||
@@ -45,0 +69,0 @@ return choiceIndex; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.patternsToStringMapper = patternsToStringMapper; | ||
exports.patternsToStringUnmapperIsValidLength = patternsToStringUnmapperIsValidLength; | ||
exports.patternsToStringUnmapperFor = patternsToStringUnmapperFor; | ||
const MaxLengthFromMinLength_1 = require("../helpers/MaxLengthFromMinLength"); | ||
const globals_1 = require("../../../utils/globals"); | ||
const TokenizeString_1 = require("../helpers/TokenizeString"); | ||
function patternsToStringMapper(tab) { | ||
return (0, globals_1.safeJoin)(tab, ''); | ||
} | ||
function minLengthFrom(constraints) { | ||
return constraints.minLength !== undefined ? constraints.minLength : 0; | ||
} | ||
function maxLengthFrom(constraints) { | ||
return constraints.maxLength !== undefined ? constraints.maxLength : MaxLengthFromMinLength_1.MaxLengthUpperBound; | ||
} | ||
function patternsToStringUnmapperIsValidLength(tokens, constraints) { | ||
return minLengthFrom(constraints) <= tokens.length && tokens.length <= maxLengthFrom(constraints); | ||
} | ||
function patternsToStringUnmapperFor(patternsArb, constraints) { | ||
return function patternsToStringUnmapper(value) { | ||
if (typeof value !== 'string') { | ||
throw new Error('Unsupported value'); | ||
throw new globals_1.Error('Unsupported value'); | ||
} | ||
const minLength = constraints.minLength !== undefined ? constraints.minLength : 0; | ||
const maxLength = constraints.maxLength !== undefined ? constraints.maxLength : MaxLengthFromMinLength_1.MaxLengthUpperBound; | ||
if (value.length === 0) { | ||
if (minLength > 0) { | ||
throw new Error('Unable to unmap received string'); | ||
} | ||
return []; | ||
const tokens = (0, TokenizeString_1.tokenizeString)(patternsArb, value, minLengthFrom(constraints), maxLengthFrom(constraints)); | ||
if (tokens === undefined) { | ||
throw new globals_1.Error('Unable to unmap received string'); | ||
} | ||
const stack = [{ endIndexChunks: 0, nextStartIndex: 1, chunks: [] }]; | ||
while (stack.length > 0) { | ||
const last = (0, globals_1.safePop)(stack); | ||
for (let index = last.nextStartIndex; index <= value.length; ++index) { | ||
const chunk = (0, globals_1.safeSubstring)(value, last.endIndexChunks, index); | ||
if (patternsArb.canShrinkWithoutContext(chunk)) { | ||
const newChunks = [...last.chunks, chunk]; | ||
if (index === value.length) { | ||
if (newChunks.length < minLength || newChunks.length > maxLength) { | ||
break; | ||
} | ||
return newChunks; | ||
} | ||
(0, globals_1.safePush)(stack, { endIndexChunks: last.endIndexChunks, nextStartIndex: index + 1, chunks: last.chunks }); | ||
(0, globals_1.safePush)(stack, { endIndexChunks: index, nextStartIndex: index + 1, chunks: newChunks }); | ||
break; | ||
} | ||
} | ||
} | ||
throw new Error('Unable to unmap received string'); | ||
return tokens; | ||
}; | ||
} |
@@ -23,5 +23,4 @@ "use strict"; | ||
return value.constructor === globals_1.Boolean || value.constructor === globals_1.Number || value.constructor === globals_1.String | ||
? | ||
value.valueOf() | ||
? value.valueOf() | ||
: value; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringUnit = stringUnit; | ||
const globals_1 = require("../../utils/globals"); | ||
const mapToConstant_1 = require("../mapToConstant"); | ||
@@ -26,3 +27,3 @@ const GraphemeRanges_1 = require("./data/GraphemeRanges"); | ||
for (const range of ranges) { | ||
entries.push((0, GraphemeRangesHelpers_1.convertGraphemeRangeToMapToConstantEntry)(range)); | ||
(0, globals_1.safePush)(entries, (0, GraphemeRangesHelpers_1.convertGraphemeRangeToMapToConstantEntry)(range)); | ||
} | ||
@@ -33,5 +34,5 @@ if (type === 'grapheme') { | ||
const rawEntry = (0, GraphemeRangesHelpers_1.convertGraphemeRangeToMapToConstantEntry)(range); | ||
entries.push({ | ||
(0, globals_1.safePush)(entries, { | ||
num: rawEntry.num, | ||
build: (idInGroup) => rawEntry.build(idInGroup).normalize('NFD'), | ||
build: (idInGroup) => (0, globals_1.safeNormalize)(rawEntry.build(idInGroup), 'NFD'), | ||
}); | ||
@@ -38,0 +39,0 @@ } |
@@ -11,3 +11,3 @@ "use strict"; | ||
const charArbitrary = (0, ascii_1.ascii)(); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -14,0 +14,0 @@ experimentalCustomSlices, |
@@ -22,3 +22,3 @@ "use strict"; | ||
const charArbitrary = (0, base64_1.base64)(); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const enrichedConstraints = { | ||
@@ -25,0 +25,0 @@ minLength, |
@@ -11,3 +11,3 @@ "use strict"; | ||
const charArbitrary = (0, fullUnicode_1.fullUnicode)(); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -14,0 +14,0 @@ experimentalCustomSlices, |
@@ -11,3 +11,3 @@ "use strict"; | ||
const charArbitrary = (0, hexa_1.hexa)(); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -14,0 +14,0 @@ experimentalCustomSlices, |
@@ -10,4 +10,8 @@ "use strict"; | ||
const noUnicodeString = constraints.noUnicodeString === undefined || constraints.noUnicodeString === true; | ||
const stringArbitrary = noUnicodeString ? (0, string_1.string)() : (0, fullUnicodeString_1.fullUnicodeString)(); | ||
const stringArbitrary = 'stringUnit' in constraints | ||
? (0, string_1.string)({ unit: constraints.stringUnit }) | ||
: noUnicodeString | ||
? (0, string_1.string)() | ||
: (0, fullUnicodeString_1.fullUnicodeString)(); | ||
return (0, anything_1.anything)((0, JsonConstraintsBuilder_1.jsonConstraintsBuilder)(stringArbitrary, constraints)); | ||
} |
@@ -6,13 +6,14 @@ "use strict"; | ||
const IndexToMappedConstant_1 = require("./_internals/mappers/IndexToMappedConstant"); | ||
const globals_1 = require("../utils/globals"); | ||
function computeNumChoices(options) { | ||
if (options.length === 0) | ||
throw new Error(`fc.mapToConstant expects at least one option`); | ||
throw new globals_1.Error(`fc.mapToConstant expects at least one option`); | ||
let numChoices = 0; | ||
for (let idx = 0; idx !== options.length; ++idx) { | ||
if (options[idx].num < 0) | ||
throw new Error(`fc.mapToConstant expects all options to have a number of entries greater or equal to zero`); | ||
throw new globals_1.Error(`fc.mapToConstant expects all options to have a number of entries greater or equal to zero`); | ||
numChoices += options[idx].num; | ||
} | ||
if (numChoices === 0) | ||
throw new Error(`fc.mapToConstant expects at least one choice among options`); | ||
throw new globals_1.Error(`fc.mapToConstant expects at least one choice among options`); | ||
return numChoices; | ||
@@ -19,0 +20,0 @@ } |
@@ -30,3 +30,3 @@ "use strict"; | ||
const unmapper = (0, PatternsToString_1.patternsToStringUnmapperFor)(charArbitrary, constraints); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, unmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, constraints); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -33,0 +33,0 @@ experimentalCustomSlices, |
@@ -11,3 +11,3 @@ "use strict"; | ||
const charArbitrary = (0, char16bits_1.char16bits)(); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, CharsToString_1.charsToStringUnmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArbitrary, CharsToString_1.charsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -14,0 +14,0 @@ experimentalCustomSlices, |
@@ -5,3 +5,2 @@ "use strict"; | ||
const globals_1 = require("../utils/globals"); | ||
const globals_2 = require("../utils/globals"); | ||
const stringify_1 = require("../utils/stringify"); | ||
@@ -26,3 +25,3 @@ const SanitizeRegexAst_1 = require("./_internals/helpers/SanitizeRegexAst"); | ||
function raiseUnsupportedASTNode(astNode) { | ||
return new globals_2.Error(`Unsupported AST node! Received: ${(0, stringify_1.stringify)(astNode)}`); | ||
return new globals_1.Error(`Unsupported AST node! Received: ${(0, stringify_1.stringify)(astNode)}`); | ||
} | ||
@@ -38,3 +37,3 @@ function toMatchingArbitrary(astNode, constraints, flags) { | ||
case '\\W': { | ||
return defaultChar.filter((c) => (0, globals_2.safeIndexOf)(wordChars, c) === -1); | ||
return defaultChar.filter((c) => (0, globals_1.safeIndexOf)(wordChars, c) === -1); | ||
} | ||
@@ -45,3 +44,3 @@ case '\\d': { | ||
case '\\D': { | ||
return defaultChar.filter((c) => (0, globals_2.safeIndexOf)(digitChars, c) === -1); | ||
return defaultChar.filter((c) => (0, globals_1.safeIndexOf)(digitChars, c) === -1); | ||
} | ||
@@ -52,11 +51,11 @@ case '\\s': { | ||
case '\\S': { | ||
return defaultChar.filter((c) => (0, globals_2.safeIndexOf)(spaceChars, c) === -1); | ||
return defaultChar.filter((c) => (0, globals_1.safeIndexOf)(spaceChars, c) === -1); | ||
} | ||
case '\\b': | ||
case '\\B': { | ||
throw new globals_2.Error(`Meta character ${astNode.value} not implemented yet!`); | ||
throw new globals_1.Error(`Meta character ${astNode.value} not implemented yet!`); | ||
} | ||
case '.': { | ||
const forbiddenChars = flags.dotAll ? terminatorChars : newLineAndTerminatorChars; | ||
return defaultChar.filter((c) => (0, globals_2.safeIndexOf)(forbiddenChars, c) === -1); | ||
return defaultChar.filter((c) => (0, globals_1.safeIndexOf)(forbiddenChars, c) === -1); | ||
} | ||
@@ -66,3 +65,3 @@ } | ||
if (astNode.symbol === undefined) { | ||
throw new globals_2.Error(`Unexpected undefined symbol received for non-meta Char! Received: ${(0, stringify_1.stringify)(astNode)}`); | ||
throw new globals_1.Error(`Unexpected undefined symbol received for non-meta Char! Received: ${(0, stringify_1.stringify)(astNode)}`); | ||
} | ||
@@ -92,13 +91,13 @@ return (0, constant_1.constant)(astNode.symbol); | ||
case 'Quantifier': { | ||
throw new globals_2.Error(`Wrongly defined AST tree, Quantifier nodes not supposed to be scanned!`); | ||
throw new globals_1.Error(`Wrongly defined AST tree, Quantifier nodes not supposed to be scanned!`); | ||
} | ||
case 'Alternative': { | ||
return (0, tuple_1.tuple)(...(0, globals_2.safeMap)(astNode.expressions, (n) => toMatchingArbitrary(n, constraints, flags))).map((vs) => (0, globals_1.safeJoin)(vs, '')); | ||
return (0, tuple_1.tuple)(...(0, globals_1.safeMap)(astNode.expressions, (n) => toMatchingArbitrary(n, constraints, flags))).map((vs) => (0, globals_1.safeJoin)(vs, '')); | ||
} | ||
case 'CharacterClass': | ||
if (astNode.negative) { | ||
const childrenArbitraries = (0, globals_2.safeMap)(astNode.expressions, (n) => toMatchingArbitrary(n, constraints, flags)); | ||
const childrenArbitraries = (0, globals_1.safeMap)(astNode.expressions, (n) => toMatchingArbitrary(n, constraints, flags)); | ||
return defaultChar.filter((c) => (0, globals_1.safeEvery)(childrenArbitraries, (arb) => !arb.canShrinkWithoutContext(c))); | ||
} | ||
return (0, oneof_1.oneof)(...(0, globals_2.safeMap)(astNode.expressions, (n) => toMatchingArbitrary(n, constraints, flags))); | ||
return (0, oneof_1.oneof)(...(0, globals_1.safeMap)(astNode.expressions, (n) => toMatchingArbitrary(n, constraints, flags))); | ||
case 'ClassRange': { | ||
@@ -109,6 +108,6 @@ const min = astNode.from.codePoint; | ||
if (typeof c !== 'string') | ||
throw new globals_2.Error('Invalid type'); | ||
throw new globals_1.Error('Invalid type'); | ||
if ([...c].length !== 1) | ||
throw new globals_2.Error('Invalid length'); | ||
return c.codePointAt(0); | ||
throw new globals_1.Error('Invalid length'); | ||
return (0, globals_1.safeCharCodeAt)(c, 0); | ||
}); | ||
@@ -130,4 +129,4 @@ } | ||
if (typeof value !== 'string' || value.length === 0) | ||
throw new globals_2.Error('Invalid type'); | ||
return [value.substring(0, value.length - 1), value[value.length - 1]]; | ||
throw new globals_1.Error('Invalid type'); | ||
return [(0, globals_1.safeSubstring)(value, 0, value.length - 1), value[value.length - 1]]; | ||
})); | ||
@@ -138,4 +137,4 @@ } | ||
if (typeof value !== 'string' || value.length === 0) | ||
throw new globals_2.Error('Invalid type'); | ||
return [value[0], value.substring(1)]; | ||
throw new globals_1.Error('Invalid type'); | ||
return [value[0], (0, globals_1.safeSubstring)(value, 1)]; | ||
})); | ||
@@ -146,6 +145,6 @@ } | ||
} | ||
throw new globals_2.Error(`Assertions of kind ${astNode.kind} not implemented yet!`); | ||
throw new globals_1.Error(`Assertions of kind ${astNode.kind} not implemented yet!`); | ||
} | ||
case 'Backreference': { | ||
throw new globals_2.Error(`Backreference nodes not implemented yet!`); | ||
throw new globals_1.Error(`Backreference nodes not implemented yet!`); | ||
} | ||
@@ -160,3 +159,3 @@ default: { | ||
if (flag !== 'd' && flag !== 'g' && flag !== 'm' && flag !== 's' && flag !== 'u') { | ||
throw new globals_2.Error(`Unable to use "stringMatching" against a regex using the flag ${flag}`); | ||
throw new globals_1.Error(`Unable to use "stringMatching" against a regex using the flag ${flag}`); | ||
} | ||
@@ -163,0 +162,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
const unmapper = (0, PatternsToString_1.patternsToStringUnmapperFor)(charArb, constraints); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArb, unmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArb, unmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -13,0 +13,0 @@ experimentalCustomSlices, |
@@ -11,3 +11,3 @@ "use strict"; | ||
const charArbitrary = (0, unicode_1.unicode)(); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForString)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const experimentalCustomSlices = (0, SlicesForStringBuilder_1.createSlicesForStringLegacy)(charArbitrary, CodePointsToString_1.codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -14,0 +14,0 @@ experimentalCustomSlices, |
@@ -5,2 +5,3 @@ import { Stream } from '../../stream/Stream.js'; | ||
import { cloneMethod, hasCloneMethod } from '../../check/symbols.js'; | ||
import { Set, safeHas } from '../../utils/globals.js'; | ||
const safeObjectIs = Object.is; | ||
@@ -21,8 +22,9 @@ export class ConstantArbitrary extends Arbitrary { | ||
canShrinkWithoutContext(value) { | ||
for (let idx = 0; idx !== this.values.length; ++idx) { | ||
if (safeObjectIs(this.values[idx], value)) { | ||
return true; | ||
} | ||
if (this.values.length === 1) { | ||
return safeObjectIs(this.values[0], value); | ||
} | ||
return false; | ||
if (this.fastValues === undefined) { | ||
this.fastValues = new FastConstantValuesLookup(this.values); | ||
} | ||
return this.fastValues.has(value); | ||
} | ||
@@ -36,1 +38,27 @@ shrink(value, context) { | ||
} | ||
class FastConstantValuesLookup { | ||
constructor(values) { | ||
this.values = values; | ||
this.fastValues = new Set(this.values); | ||
let hasMinusZero = false; | ||
let hasPlusZero = false; | ||
if (safeHas(this.fastValues, 0)) { | ||
for (let idx = 0; idx !== this.values.length; ++idx) { | ||
const value = this.values[idx]; | ||
hasMinusZero = hasMinusZero || safeObjectIs(value, -0); | ||
hasPlusZero = hasPlusZero || safeObjectIs(value, 0); | ||
} | ||
} | ||
this.hasMinusZero = hasMinusZero; | ||
this.hasPlusZero = hasPlusZero; | ||
} | ||
has(value) { | ||
if (value === 0) { | ||
if (safeObjectIs(value, 0)) { | ||
return this.hasPlusZero; | ||
} | ||
return this.hasMinusZero; | ||
} | ||
return safeHas(this.fastValues, value); | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
import { safePop, safePush } from '../../../utils/globals.js'; | ||
const safeStringFromCodePoint = String.fromCodePoint; | ||
@@ -37,6 +38,6 @@ const safeMathMin = Math.min; | ||
min = lastMergedRange[0]; | ||
mergedRanges.pop(); | ||
safePop(mergedRanges); | ||
} | ||
} | ||
mergedRanges.push(min === max ? [min] : [min, max]); | ||
safePush(mergedRanges, min === max ? [min] : [min, max]); | ||
if (rangeAMax <= max) { | ||
@@ -43,0 +44,0 @@ cursorA += 1; |
@@ -28,4 +28,4 @@ import { boolean } from '../../boolean.js'; | ||
} | ||
const stringArbitrary = settings.withUnicodeString ? fullUnicodeString : string; | ||
const valueConstraints = { size: settings.size }; | ||
const stringArbitrary = 'stringUnit' in settings ? string : settings.withUnicodeString ? fullUnicodeString : string; | ||
const valueConstraints = { size: settings.size, unit: settings.stringUnit }; | ||
return { | ||
@@ -32,0 +32,0 @@ key: orDefault(settings.key, stringArbitrary(valueConstraints)), |
@@ -1,2 +0,5 @@ | ||
import { safePush } from '../../../utils/globals.js'; | ||
import { safeGet, safePush, safeSet } from '../../../utils/globals.js'; | ||
import { patternsToStringUnmapperIsValidLength } from '../mappers/PatternsToString.js'; | ||
import { MaxLengthUpperBound } from './MaxLengthFromMinLength.js'; | ||
import { tokenizeString } from './TokenizeString.js'; | ||
const dangerousStrings = [ | ||
@@ -26,3 +29,3 @@ '__defineGetter__', | ||
]; | ||
function computeCandidateString(dangerous, charArbitrary, stringSplitter) { | ||
function computeCandidateStringLegacy(dangerous, charArbitrary, stringSplitter) { | ||
let candidate; | ||
@@ -42,6 +45,6 @@ try { | ||
} | ||
export function createSlicesForString(charArbitrary, stringSplitter) { | ||
export function createSlicesForStringLegacy(charArbitrary, stringSplitter) { | ||
const slicesForString = []; | ||
for (const dangerous of dangerousStrings) { | ||
const candidate = computeCandidateString(dangerous, charArbitrary, stringSplitter); | ||
const candidate = computeCandidateStringLegacy(dangerous, charArbitrary, stringSplitter); | ||
if (candidate !== undefined) { | ||
@@ -53,1 +56,26 @@ safePush(slicesForString, candidate); | ||
} | ||
const slicesPerArbitrary = new WeakMap(); | ||
function createSlicesForStringNoConstraints(charArbitrary) { | ||
const slicesForString = []; | ||
for (const dangerous of dangerousStrings) { | ||
const candidate = tokenizeString(charArbitrary, dangerous, 0, MaxLengthUpperBound); | ||
if (candidate !== undefined) { | ||
safePush(slicesForString, candidate); | ||
} | ||
} | ||
return slicesForString; | ||
} | ||
export function createSlicesForString(charArbitrary, constraints) { | ||
let slices = safeGet(slicesPerArbitrary, charArbitrary); | ||
if (slices === undefined) { | ||
slices = createSlicesForStringNoConstraints(charArbitrary); | ||
safeSet(slicesPerArbitrary, charArbitrary, slices); | ||
} | ||
const slicesForConstraints = []; | ||
for (const slice of slices) { | ||
if (patternsToStringUnmapperIsValidLength(slice, constraints)) { | ||
safePush(slicesForConstraints, slice); | ||
} | ||
} | ||
return slicesForConstraints; | ||
} |
@@ -0,9 +1,33 @@ | ||
import { Error } from '../../../utils/globals.js'; | ||
const safeObjectIs = Object.is; | ||
function buildDichotomyEntries(entries) { | ||
let currentFrom = 0; | ||
const dichotomyEntries = []; | ||
for (const entry of entries) { | ||
const from = currentFrom; | ||
currentFrom = from + entry.num; | ||
const to = currentFrom - 1; | ||
dichotomyEntries.push({ from, to, entry }); | ||
} | ||
return dichotomyEntries; | ||
} | ||
function findDichotomyEntry(dichotomyEntries, choiceIndex) { | ||
let min = 0; | ||
let max = dichotomyEntries.length; | ||
while (max - min > 1) { | ||
const mid = ~~((min + max) / 2); | ||
if (choiceIndex < dichotomyEntries[mid].from) { | ||
max = mid; | ||
} | ||
else { | ||
min = mid; | ||
} | ||
} | ||
return dichotomyEntries[min]; | ||
} | ||
export function indexToMappedConstantMapperFor(entries) { | ||
const dichotomyEntries = buildDichotomyEntries(entries); | ||
return function indexToMappedConstantMapper(choiceIndex) { | ||
let idx = -1; | ||
let numSkips = 0; | ||
while (choiceIndex >= numSkips) { | ||
numSkips += entries[++idx].num; | ||
} | ||
return entries[idx].build(choiceIndex - numSkips + entries[idx].num); | ||
const dichotomyEntry = findDichotomyEntry(dichotomyEntries, choiceIndex); | ||
return dichotomyEntry.entry.build(choiceIndex - dichotomyEntry.from); | ||
}; | ||
@@ -35,3 +59,3 @@ } | ||
} | ||
const choiceIndex = Object.is(value, -0) ? reverseMapping.negativeZeroIndex : reverseMapping.mapping.get(value); | ||
const choiceIndex = safeObjectIs(value, -0) ? reverseMapping.negativeZeroIndex : reverseMapping.mapping.get(value); | ||
if (choiceIndex === undefined) { | ||
@@ -38,0 +62,0 @@ throw new Error('Unknown value encountered cannot be built using this mapToConstant'); |
import { MaxLengthUpperBound } from '../helpers/MaxLengthFromMinLength.js'; | ||
import { safeJoin, safePop, safePush, safeSubstring } from '../../../utils/globals.js'; | ||
import { safeJoin, Error } from '../../../utils/globals.js'; | ||
import { tokenizeString } from '../helpers/TokenizeString.js'; | ||
export function patternsToStringMapper(tab) { | ||
return safeJoin(tab, ''); | ||
} | ||
function minLengthFrom(constraints) { | ||
return constraints.minLength !== undefined ? constraints.minLength : 0; | ||
} | ||
function maxLengthFrom(constraints) { | ||
return constraints.maxLength !== undefined ? constraints.maxLength : MaxLengthUpperBound; | ||
} | ||
export function patternsToStringUnmapperIsValidLength(tokens, constraints) { | ||
return minLengthFrom(constraints) <= tokens.length && tokens.length <= maxLengthFrom(constraints); | ||
} | ||
export function patternsToStringUnmapperFor(patternsArb, constraints) { | ||
@@ -11,31 +21,8 @@ return function patternsToStringUnmapper(value) { | ||
} | ||
const minLength = constraints.minLength !== undefined ? constraints.minLength : 0; | ||
const maxLength = constraints.maxLength !== undefined ? constraints.maxLength : MaxLengthUpperBound; | ||
if (value.length === 0) { | ||
if (minLength > 0) { | ||
throw new Error('Unable to unmap received string'); | ||
} | ||
return []; | ||
const tokens = tokenizeString(patternsArb, value, minLengthFrom(constraints), maxLengthFrom(constraints)); | ||
if (tokens === undefined) { | ||
throw new Error('Unable to unmap received string'); | ||
} | ||
const stack = [{ endIndexChunks: 0, nextStartIndex: 1, chunks: [] }]; | ||
while (stack.length > 0) { | ||
const last = safePop(stack); | ||
for (let index = last.nextStartIndex; index <= value.length; ++index) { | ||
const chunk = safeSubstring(value, last.endIndexChunks, index); | ||
if (patternsArb.canShrinkWithoutContext(chunk)) { | ||
const newChunks = [...last.chunks, chunk]; | ||
if (index === value.length) { | ||
if (newChunks.length < minLength || newChunks.length > maxLength) { | ||
break; | ||
} | ||
return newChunks; | ||
} | ||
safePush(stack, { endIndexChunks: last.endIndexChunks, nextStartIndex: index + 1, chunks: last.chunks }); | ||
safePush(stack, { endIndexChunks: index, nextStartIndex: index + 1, chunks: newChunks }); | ||
break; | ||
} | ||
} | ||
} | ||
throw new Error('Unable to unmap received string'); | ||
return tokens; | ||
}; | ||
} |
@@ -19,5 +19,4 @@ import { Boolean, Number, String } from '../../../utils/globals.js'; | ||
return value.constructor === Boolean || value.constructor === Number || value.constructor === String | ||
? | ||
value.valueOf() | ||
? value.valueOf() | ||
: value; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { safeNormalize, safePush } from '../../utils/globals.js'; | ||
import { mapToConstant } from '../mapToConstant.js'; | ||
@@ -23,3 +24,3 @@ import { asciiAlphabetRanges, autonomousDecomposableGraphemeRanges, autonomousGraphemeRanges, fullAlphabetRanges, } from './data/GraphemeRanges.js'; | ||
for (const range of ranges) { | ||
entries.push(convertGraphemeRangeToMapToConstantEntry(range)); | ||
safePush(entries, convertGraphemeRangeToMapToConstantEntry(range)); | ||
} | ||
@@ -30,5 +31,5 @@ if (type === 'grapheme') { | ||
const rawEntry = convertGraphemeRangeToMapToConstantEntry(range); | ||
entries.push({ | ||
safePush(entries, { | ||
num: rawEntry.num, | ||
build: (idInGroup) => rawEntry.build(idInGroup).normalize('NFD'), | ||
build: (idInGroup) => safeNormalize(rawEntry.build(idInGroup), 'NFD'), | ||
}); | ||
@@ -35,0 +36,0 @@ } |
import { array } from './array.js'; | ||
import { ascii } from './ascii.js'; | ||
import { codePointsToStringMapper, codePointsToStringUnmapper } from './_internals/mappers/CodePointsToString.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
const safeObjectAssign = Object.assign; | ||
export function asciiString(constraints = {}) { | ||
const charArbitrary = ascii(); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, codePointsToStringUnmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArbitrary, codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -10,0 +10,0 @@ experimentalCustomSlices, |
@@ -6,3 +6,3 @@ import { array } from './array.js'; | ||
import { stringToBase64Mapper, stringToBase64Unmapper } from './_internals/mappers/StringToBase64.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
function base64String(constraints = {}) { | ||
@@ -20,3 +20,3 @@ const { minLength: unscaledMinLength = 0, maxLength: unscaledMaxLength = MaxLengthUpperBound, size } = constraints; | ||
const charArbitrary = base64(); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, codePointsToStringUnmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArbitrary, codePointsToStringUnmapper); | ||
const enrichedConstraints = { | ||
@@ -23,0 +23,0 @@ minLength, |
import { array } from './array.js'; | ||
import { fullUnicode } from './fullUnicode.js'; | ||
import { codePointsToStringMapper, codePointsToStringUnmapper } from './_internals/mappers/CodePointsToString.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
const safeObjectAssign = Object.assign; | ||
export function fullUnicodeString(constraints = {}) { | ||
const charArbitrary = fullUnicode(); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, codePointsToStringUnmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArbitrary, codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -10,0 +10,0 @@ experimentalCustomSlices, |
import { array } from './array.js'; | ||
import { hexa } from './hexa.js'; | ||
import { codePointsToStringMapper, codePointsToStringUnmapper } from './_internals/mappers/CodePointsToString.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
const safeObjectAssign = Object.assign; | ||
function hexaString(constraints = {}) { | ||
const charArbitrary = hexa(); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, codePointsToStringUnmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArbitrary, codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -10,0 +10,0 @@ experimentalCustomSlices, |
@@ -7,4 +7,8 @@ import { string } from './string.js'; | ||
const noUnicodeString = constraints.noUnicodeString === undefined || constraints.noUnicodeString === true; | ||
const stringArbitrary = noUnicodeString ? string() : fullUnicodeString(); | ||
const stringArbitrary = 'stringUnit' in constraints | ||
? string({ unit: constraints.stringUnit }) | ||
: noUnicodeString | ||
? string() | ||
: fullUnicodeString(); | ||
return anything(jsonConstraintsBuilder(stringArbitrary, constraints)); | ||
} |
import { nat } from './nat.js'; | ||
import { indexToMappedConstantMapperFor, indexToMappedConstantUnmapperFor, } from './_internals/mappers/IndexToMappedConstant.js'; | ||
import { Error } from '../utils/globals.js'; | ||
function computeNumChoices(options) { | ||
@@ -4,0 +5,0 @@ if (options.length === 0) |
@@ -27,3 +27,3 @@ import { array } from './array.js'; | ||
const unmapper = patternsToStringUnmapperFor(charArbitrary, constraints); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, unmapper); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, constraints); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -30,0 +30,0 @@ experimentalCustomSlices, |
import { array } from './array.js'; | ||
import { char16bits } from './char16bits.js'; | ||
import { charsToStringMapper, charsToStringUnmapper } from './_internals/mappers/CharsToString.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
const safeObjectAssign = Object.assign; | ||
export function string16bits(constraints = {}) { | ||
const charArbitrary = char16bits(); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, charsToStringUnmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArbitrary, charsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -10,0 +10,0 @@ experimentalCustomSlices, |
@@ -1,3 +0,2 @@ | ||
import { safeEvery, safeJoin } from '../utils/globals.js'; | ||
import { Error, safeIndexOf, safeMap } from '../utils/globals.js'; | ||
import { safeCharCodeAt, safeEvery, safeJoin, safeSubstring, Error, safeIndexOf, safeMap } from '../utils/globals.js'; | ||
import { stringify } from '../utils/stringify.js'; | ||
@@ -102,3 +101,3 @@ import { addMissingDotStar } from './_internals/helpers/SanitizeRegexAst.js'; | ||
throw new Error('Invalid length'); | ||
return c.codePointAt(0); | ||
return safeCharCodeAt(c, 0); | ||
}); | ||
@@ -121,3 +120,3 @@ } | ||
throw new Error('Invalid type'); | ||
return [value.substring(0, value.length - 1), value[value.length - 1]]; | ||
return [safeSubstring(value, 0, value.length - 1), value[value.length - 1]]; | ||
})); | ||
@@ -129,3 +128,3 @@ } | ||
throw new Error('Invalid type'); | ||
return [value[0], value.substring(1)]; | ||
return [value[0], safeSubstring(value, 1)]; | ||
})); | ||
@@ -132,0 +131,0 @@ } |
import { array } from './array.js'; | ||
import { patternsToStringMapper, patternsToStringUnmapperFor } from './_internals/mappers/PatternsToString.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
const safeObjectAssign = Object.assign; | ||
export function stringOf(charArb, constraints = {}) { | ||
const unmapper = patternsToStringUnmapperFor(charArb, constraints); | ||
const experimentalCustomSlices = createSlicesForString(charArb, unmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArb, unmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -9,0 +9,0 @@ experimentalCustomSlices, |
import { array } from './array.js'; | ||
import { unicode } from './unicode.js'; | ||
import { codePointsToStringMapper, codePointsToStringUnmapper } from './_internals/mappers/CodePointsToString.js'; | ||
import { createSlicesForString } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
import { createSlicesForStringLegacy } from './_internals/helpers/SlicesForStringBuilder.js'; | ||
const safeObjectAssign = Object.assign; | ||
export function unicodeString(constraints = {}) { | ||
const charArbitrary = unicode(); | ||
const experimentalCustomSlices = createSlicesForString(charArbitrary, codePointsToStringUnmapper); | ||
const experimentalCustomSlices = createSlicesForStringLegacy(charArbitrary, codePointsToStringUnmapper); | ||
const enrichedConstraints = safeObjectAssign(safeObjectAssign({}, constraints), { | ||
@@ -10,0 +10,0 @@ experimentalCustomSlices, |
@@ -110,4 +110,4 @@ import { pre } from './check/precondition/Pre.js'; | ||
const __type = 'module'; | ||
const __version = '3.22.0'; | ||
const __commitHash = '4e04fda63d913c2b5b1ed604db12341b618b56c5'; | ||
const __version = '3.23.0'; | ||
const __commitHash = '7eb6ddd8c54813cf3f0d25c0cc17d58ad3b009e6'; | ||
export { __type, __version, __commitHash, sample, statistics, check, assert, pre, PreconditionFailure, property, asyncProperty, boolean, falsy, float, double, integer, nat, maxSafeInteger, maxSafeNat, bigIntN, bigUintN, bigInt, bigUint, char, ascii, char16bits, unicode, fullUnicode, hexa, base64, mixedCase, string, asciiString, string16bits, stringOf, unicodeString, fullUnicodeString, hexaString, base64String, stringMatching, limitShrink, lorem, constant, constantFrom, mapToConstant, option, oneof, clone, noBias, noShrink, shuffledSubarray, subarray, array, sparseArray, infiniteStream, uniqueArray, tuple, record, dictionary, anything, object, json, jsonValue, unicodeJson, unicodeJsonValue, letrec, memo, compareBooleanFunc, compareFunc, func, context, gen, date, ipV4, ipV4Extended, ipV6, domain, webAuthority, webSegment, webFragments, webPath, webQueryParameters, webUrl, emailAddress, ulid, uuid, uuidV, int8Array, uint8Array, uint8ClampedArray, int16Array, uint16Array, int32Array, uint32Array, float32Array, float64Array, bigInt64Array, bigUint64Array, asyncModelRun, modelRun, scheduledModelRun, commands, scheduler, schedulerFor, Arbitrary, Value, cloneMethod, cloneIfNeeded, hasCloneMethod, toStringMethod, hasToStringMethod, asyncToStringMethod, hasAsyncToStringMethod, getDepthContextFor, stringify, asyncStringify, defaultReportMessage, asyncDefaultReportMessage, hash, VerbosityLevel, configureGlobal, readConfigureGlobal, resetConfigureGlobal, ExecutionStatus, Random, Stream, stream, createDepthIdentifier, }; |
@@ -0,1 +1,2 @@ | ||
import type { StringConstraints } from '../../string.js'; | ||
import type { DepthSize } from './MaxLengthFromMinLength.js'; | ||
@@ -26,2 +27,3 @@ /** | ||
* Only generate instances having keys and values made of ascii strings (when true) | ||
* @deprecated Prefer using `stringUnit` to customize the kind of strings that will be generated by default. | ||
* @defaultValue true | ||
@@ -31,2 +33,8 @@ * @remarks Since 3.19.0 | ||
noUnicodeString?: boolean; | ||
/** | ||
* Replace the default unit for strings. | ||
* @defaultValue undefined | ||
* @remarks Since 3.23.0 | ||
*/ | ||
stringUnit?: StringConstraints['unit']; | ||
} | ||
@@ -33,0 +41,0 @@ /** |
import type { Arbitrary } from '../../../check/arbitrary/definition/Arbitrary.js'; | ||
import type { StringConstraints } from '../../string.js'; | ||
import type { DepthSize, SizeForArbitrary } from './MaxLengthFromMinLength.js'; | ||
@@ -101,2 +102,3 @@ /** | ||
* If you override key and/or values constraint, this flag will not apply to your override. | ||
* @deprecated Prefer using `stringUnit` to customize the kind of strings that will be generated by default. | ||
* @defaultValue false | ||
@@ -106,2 +108,8 @@ * @remarks Since 3.19.0 | ||
withUnicodeString?: boolean; | ||
/** | ||
* Replace the default unit for strings. | ||
* @defaultValue undefined | ||
* @remarks Since 3.23.0 | ||
*/ | ||
stringUnit?: StringConstraints['unit']; | ||
} |
@@ -11,3 +11,3 @@ import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js'; | ||
* | ||
* @deprecated Prefer using {@link json} with `noUnicodeString: false`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @deprecated Prefer using {@link json} with `stringUnit: "grapheme"`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @remarks Since 0.0.7 | ||
@@ -14,0 +14,0 @@ * @public |
@@ -14,3 +14,3 @@ import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js'; | ||
* | ||
* @deprecated Prefer using {@link jsonValue} with `noUnicodeString: false`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @deprecated Prefer using {@link jsonValue} with `stringUnit: "grapheme"`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @remarks Since 2.20.0 | ||
@@ -17,0 +17,0 @@ * @public |
@@ -178,3 +178,3 @@ import { pre } from './check/precondition/Pre.js'; | ||
/** | ||
* Version of fast-check used by your project (eg.: 3.22.0) | ||
* Version of fast-check used by your project (eg.: 3.23.0) | ||
* @remarks Since 1.22.0 | ||
@@ -185,3 +185,3 @@ * @public | ||
/** | ||
* Commit hash of the current code (eg.: 4e04fda63d913c2b5b1ed604db12341b618b56c5) | ||
* Commit hash of the current code (eg.: 7eb6ddd8c54813cf3f0d25c0cc17d58ad3b009e6) | ||
* @remarks Since 2.7.0 | ||
@@ -188,0 +188,0 @@ * @public |
@@ -55,2 +55,5 @@ declare const SArray: typeof Array; | ||
export declare function safeAdd<T>(instance: Set<T>, value: T): Set<T>; | ||
export declare function safeHas<T>(instance: Set<T>, value: T): boolean; | ||
export declare function safeSet<T extends object, U>(instance: WeakMap<T, U>, key: T, value: U): WeakMap<T, U>; | ||
export declare function safeGet<T extends object, U>(instance: WeakMap<T, U>, key: T): U | undefined; | ||
export declare function safeSplit(instance: string, ...args: [separator: string | RegExp, limit?: number | undefined]): string[]; | ||
@@ -64,2 +67,3 @@ export declare function safeStartsWith(instance: string, ...args: [searchString: string, position?: number | undefined]): boolean; | ||
export declare function safeCharCodeAt(instance: string, index: number): number; | ||
export declare function safeNormalize(instance: string, form: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): string; | ||
export declare function safeReplace(instance: string, pattern: RegExp | string, replacement: string): string; | ||
@@ -66,0 +70,0 @@ export declare function safeNumberToString(instance: number, ...args: [radix?: number | undefined]): string; |
@@ -238,2 +238,3 @@ import { safeApply } from './apply.js'; | ||
const untouchedAdd = Set.prototype.add; | ||
const untouchedHas = Set.prototype.has; | ||
function extractAdd(instance) { | ||
@@ -247,2 +248,10 @@ try { | ||
} | ||
function extractHas(instance) { | ||
try { | ||
return instance.has; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
export function safeAdd(instance, value) { | ||
@@ -254,2 +263,38 @@ if (extractAdd(instance) === untouchedAdd) { | ||
} | ||
export function safeHas(instance, value) { | ||
if (extractHas(instance) === untouchedHas) { | ||
return instance.has(value); | ||
} | ||
return safeApply(untouchedHas, instance, [value]); | ||
} | ||
const untouchedSet = WeakMap.prototype.set; | ||
const untouchedGet = WeakMap.prototype.get; | ||
function extractSet(instance) { | ||
try { | ||
return instance.set; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
function extractGet(instance) { | ||
try { | ||
return instance.get; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
export function safeSet(instance, key, value) { | ||
if (extractSet(instance) === untouchedSet) { | ||
return instance.set(key, value); | ||
} | ||
return safeApply(untouchedSet, instance, [key, value]); | ||
} | ||
export function safeGet(instance, key) { | ||
if (extractGet(instance) === untouchedGet) { | ||
return instance.get(key); | ||
} | ||
return safeApply(untouchedGet, instance, [key]); | ||
} | ||
const untouchedSplit = String.prototype.split; | ||
@@ -263,2 +308,3 @@ const untouchedStartsWith = String.prototype.startsWith; | ||
const untouchedCharCodeAt = String.prototype.charCodeAt; | ||
const untouchedNormalize = String.prototype.normalize; | ||
const untouchedReplace = String.prototype.replace; | ||
@@ -329,2 +375,10 @@ function extractSplit(instance) { | ||
} | ||
function extractNormalize(instance) { | ||
try { | ||
return instance.normalize; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
function extractReplace(instance) { | ||
@@ -386,2 +440,8 @@ try { | ||
} | ||
export function safeNormalize(instance, form) { | ||
if (extractNormalize(instance) === untouchedNormalize) { | ||
return instance.normalize(form); | ||
} | ||
return safeApply(untouchedNormalize, instance, [form]); | ||
} | ||
export function safeReplace(instance, pattern, replacement) { | ||
@@ -388,0 +448,0 @@ if (extractReplace(instance) === untouchedReplace) { |
@@ -241,5 +241,5 @@ "use strict"; | ||
exports.__type = __type; | ||
const __version = '3.22.0'; | ||
const __version = '3.23.0'; | ||
exports.__version = __version; | ||
const __commitHash = '4e04fda63d913c2b5b1ed604db12341b618b56c5'; | ||
const __commitHash = '7eb6ddd8c54813cf3f0d25c0cc17d58ad3b009e6'; | ||
exports.__commitHash = __commitHash; |
@@ -0,1 +1,2 @@ | ||
import type { StringConstraints } from '../../string.js'; | ||
import type { DepthSize } from './MaxLengthFromMinLength.js'; | ||
@@ -26,2 +27,3 @@ /** | ||
* Only generate instances having keys and values made of ascii strings (when true) | ||
* @deprecated Prefer using `stringUnit` to customize the kind of strings that will be generated by default. | ||
* @defaultValue true | ||
@@ -31,2 +33,8 @@ * @remarks Since 3.19.0 | ||
noUnicodeString?: boolean; | ||
/** | ||
* Replace the default unit for strings. | ||
* @defaultValue undefined | ||
* @remarks Since 3.23.0 | ||
*/ | ||
stringUnit?: StringConstraints['unit']; | ||
} | ||
@@ -33,0 +41,0 @@ /** |
import type { Arbitrary } from '../../../check/arbitrary/definition/Arbitrary.js'; | ||
import type { StringConstraints } from '../../string.js'; | ||
import type { DepthSize, SizeForArbitrary } from './MaxLengthFromMinLength.js'; | ||
@@ -101,2 +102,3 @@ /** | ||
* If you override key and/or values constraint, this flag will not apply to your override. | ||
* @deprecated Prefer using `stringUnit` to customize the kind of strings that will be generated by default. | ||
* @defaultValue false | ||
@@ -106,2 +108,8 @@ * @remarks Since 3.19.0 | ||
withUnicodeString?: boolean; | ||
/** | ||
* Replace the default unit for strings. | ||
* @defaultValue undefined | ||
* @remarks Since 3.23.0 | ||
*/ | ||
stringUnit?: StringConstraints['unit']; | ||
} |
@@ -11,3 +11,3 @@ import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js'; | ||
* | ||
* @deprecated Prefer using {@link json} with `noUnicodeString: false`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @deprecated Prefer using {@link json} with `stringUnit: "grapheme"`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @remarks Since 0.0.7 | ||
@@ -14,0 +14,0 @@ * @public |
@@ -14,3 +14,3 @@ import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js'; | ||
* | ||
* @deprecated Prefer using {@link jsonValue} with `noUnicodeString: false`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @deprecated Prefer using {@link jsonValue} with `stringUnit: "grapheme"`, it will generate even more unicode strings: includings some having characters outside of BMP plan | ||
* @remarks Since 2.20.0 | ||
@@ -17,0 +17,0 @@ * @public |
@@ -178,3 +178,3 @@ import { pre } from './check/precondition/Pre.js'; | ||
/** | ||
* Version of fast-check used by your project (eg.: 3.22.0) | ||
* Version of fast-check used by your project (eg.: 3.23.0) | ||
* @remarks Since 1.22.0 | ||
@@ -185,3 +185,3 @@ * @public | ||
/** | ||
* Commit hash of the current code (eg.: 4e04fda63d913c2b5b1ed604db12341b618b56c5) | ||
* Commit hash of the current code (eg.: 7eb6ddd8c54813cf3f0d25c0cc17d58ad3b009e6) | ||
* @remarks Since 2.7.0 | ||
@@ -188,0 +188,0 @@ * @public |
@@ -55,2 +55,5 @@ declare const SArray: typeof Array; | ||
export declare function safeAdd<T>(instance: Set<T>, value: T): Set<T>; | ||
export declare function safeHas<T>(instance: Set<T>, value: T): boolean; | ||
export declare function safeSet<T extends object, U>(instance: WeakMap<T, U>, key: T, value: U): WeakMap<T, U>; | ||
export declare function safeGet<T extends object, U>(instance: WeakMap<T, U>, key: T): U | undefined; | ||
export declare function safeSplit(instance: string, ...args: [separator: string | RegExp, limit?: number | undefined]): string[]; | ||
@@ -64,2 +67,3 @@ export declare function safeStartsWith(instance: string, ...args: [searchString: string, position?: number | undefined]): boolean; | ||
export declare function safeCharCodeAt(instance: string, index: number): number; | ||
export declare function safeNormalize(instance: string, form: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): string; | ||
export declare function safeReplace(instance: string, pattern: RegExp | string, replacement: string): string; | ||
@@ -66,0 +70,0 @@ export declare function safeNumberToString(instance: number, ...args: [radix?: number | undefined]): string; |
@@ -18,2 +18,5 @@ "use strict"; | ||
exports.safeAdd = safeAdd; | ||
exports.safeHas = safeHas; | ||
exports.safeSet = safeSet; | ||
exports.safeGet = safeGet; | ||
exports.safeSplit = safeSplit; | ||
@@ -27,2 +30,3 @@ exports.safeStartsWith = safeStartsWith; | ||
exports.safeCharCodeAt = safeCharCodeAt; | ||
exports.safeNormalize = safeNormalize; | ||
exports.safeReplace = safeReplace; | ||
@@ -269,2 +273,3 @@ exports.safeNumberToString = safeNumberToString; | ||
const untouchedAdd = Set.prototype.add; | ||
const untouchedHas = Set.prototype.has; | ||
function extractAdd(instance) { | ||
@@ -278,2 +283,10 @@ try { | ||
} | ||
function extractHas(instance) { | ||
try { | ||
return instance.has; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
function safeAdd(instance, value) { | ||
@@ -285,2 +298,38 @@ if (extractAdd(instance) === untouchedAdd) { | ||
} | ||
function safeHas(instance, value) { | ||
if (extractHas(instance) === untouchedHas) { | ||
return instance.has(value); | ||
} | ||
return (0, apply_1.safeApply)(untouchedHas, instance, [value]); | ||
} | ||
const untouchedSet = WeakMap.prototype.set; | ||
const untouchedGet = WeakMap.prototype.get; | ||
function extractSet(instance) { | ||
try { | ||
return instance.set; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
function extractGet(instance) { | ||
try { | ||
return instance.get; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
function safeSet(instance, key, value) { | ||
if (extractSet(instance) === untouchedSet) { | ||
return instance.set(key, value); | ||
} | ||
return (0, apply_1.safeApply)(untouchedSet, instance, [key, value]); | ||
} | ||
function safeGet(instance, key) { | ||
if (extractGet(instance) === untouchedGet) { | ||
return instance.get(key); | ||
} | ||
return (0, apply_1.safeApply)(untouchedGet, instance, [key]); | ||
} | ||
const untouchedSplit = String.prototype.split; | ||
@@ -294,2 +343,3 @@ const untouchedStartsWith = String.prototype.startsWith; | ||
const untouchedCharCodeAt = String.prototype.charCodeAt; | ||
const untouchedNormalize = String.prototype.normalize; | ||
const untouchedReplace = String.prototype.replace; | ||
@@ -360,2 +410,10 @@ function extractSplit(instance) { | ||
} | ||
function extractNormalize(instance) { | ||
try { | ||
return instance.normalize; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
function extractReplace(instance) { | ||
@@ -417,2 +475,8 @@ try { | ||
} | ||
function safeNormalize(instance, form) { | ||
if (extractNormalize(instance) === untouchedNormalize) { | ||
return instance.normalize(form); | ||
} | ||
return (0, apply_1.safeApply)(untouchedNormalize, instance, [form]); | ||
} | ||
function safeReplace(instance, pattern, replacement) { | ||
@@ -419,0 +483,0 @@ if (extractReplace(instance) === untouchedReplace) { |
{ | ||
"name": "fast-check", | ||
"version": "3.22.0", | ||
"version": "3.23.0", | ||
"description": "Property based testing framework for JavaScript (like QuickCheck)", | ||
@@ -63,6 +63,6 @@ "type": "commonjs", | ||
"@fast-check/expect-type": "0.2.0", | ||
"@fast-check/poisoning": "0.2.1", | ||
"@microsoft/api-extractor": "^7.47.7", | ||
"@fast-check/poisoning": "0.2.2", | ||
"@microsoft/api-extractor": "^7.47.11", | ||
"@types/node": "^20.14.15", | ||
"@vitest/coverage-v8": "^2.0.5", | ||
"@vitest/coverage-v8": "^2.1.3", | ||
"cross-env": "^7.0.3", | ||
@@ -72,6 +72,6 @@ "glob": "^11.0.0", | ||
"regexp-tree": "^0.1.27", | ||
"replace-in-file": "^8.1.0", | ||
"typedoc": "^0.26.6", | ||
"typescript": "~5.5.4", | ||
"vitest": "^2.0.5" | ||
"replace-in-file": "^8.2.0", | ||
"typedoc": "^0.26.10", | ||
"typescript": "~5.6.3", | ||
"vitest": "^2.1.3" | ||
}, | ||
@@ -78,0 +78,0 @@ "keywords": [ |
@@ -232,2 +232,3 @@ <h1 align="center"> | ||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nmay231"><img src="https://avatars.githubusercontent.com/u/35386821?v=4?s=100" width="100px;" alt="Noah"/><br /><sub><b>Noah</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=nmay231" title="Documentation">📖</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jamesbvaughan"><img src="https://avatars.githubusercontent.com/u/2906913?v=4?s=100" width="100px;" alt="James Vaughan"/><br /><sub><b>James Vaughan</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=jamesbvaughan" title="Documentation">📖</a></td> | ||
</tr> | ||
@@ -234,0 +235,0 @@ </tbody> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1315838
946
30894
251
2