Aktueller Stand

This commit is contained in:
2026-01-23 01:33:35 +01:00
parent 082dc5e110
commit 2766dd12c5
10109 changed files with 1578841 additions and 77685 deletions

View File

@@ -0,0 +1,83 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncProperty = void 0;
const PreconditionFailure_1 = require("../precondition/PreconditionFailure");
const IRawProperty_1 = require("./IRawProperty");
const GlobalParameters_1 = require("../runner/configuration/GlobalParameters");
const Stream_1 = require("../../stream/Stream");
const NoUndefinedAsContext_1 = require("../../arbitrary/_internals/helpers/NoUndefinedAsContext");
const globals_1 = require("../../utils/globals");
class AsyncProperty {
constructor(arb, predicate) {
this.arb = arb;
this.predicate = predicate;
const { asyncBeforeEach, asyncAfterEach, beforeEach, afterEach } = (0, GlobalParameters_1.readConfigureGlobal)() || {};
if (asyncBeforeEach !== undefined && beforeEach !== undefined) {
throw (0, globals_1.Error)('Global "asyncBeforeEach" and "beforeEach" parameters can\'t be set at the same time when running async properties');
}
if (asyncAfterEach !== undefined && afterEach !== undefined) {
throw (0, globals_1.Error)('Global "asyncAfterEach" and "afterEach" parameters can\'t be set at the same time when running async properties');
}
this.beforeEachHook = asyncBeforeEach || beforeEach || AsyncProperty.dummyHook;
this.afterEachHook = asyncAfterEach || afterEach || AsyncProperty.dummyHook;
}
isAsync() {
return true;
}
generate(mrng, runId) {
const value = this.arb.generate(mrng, runId != null ? (0, IRawProperty_1.runIdToFrequency)(runId) : undefined);
return (0, NoUndefinedAsContext_1.noUndefinedAsContext)(value);
}
shrink(value) {
if (value.context === undefined && !this.arb.canShrinkWithoutContext(value.value_)) {
return Stream_1.Stream.nil();
}
const safeContext = value.context !== NoUndefinedAsContext_1.UndefinedContextPlaceholder ? value.context : undefined;
return this.arb.shrink(value.value_, safeContext).map(NoUndefinedAsContext_1.noUndefinedAsContext);
}
async runBeforeEach() {
await this.beforeEachHook();
}
async runAfterEach() {
await this.afterEachHook();
}
async run(v, dontRunHook) {
if (!dontRunHook) {
await this.beforeEachHook();
}
try {
const output = await this.predicate(v);
return output == null || output === true
? null
: {
error: new globals_1.Error('Property failed by returning false'),
errorMessage: 'Error: Property failed by returning false',
};
}
catch (err) {
if (PreconditionFailure_1.PreconditionFailure.isFailure(err))
return err;
if (err instanceof globals_1.Error && err.stack) {
return { error: err, errorMessage: err.stack };
}
return { error: err, errorMessage: (0, globals_1.String)(err) };
}
finally {
if (!dontRunHook) {
await this.afterEachHook();
}
}
}
beforeEach(hookFunction) {
const previousBeforeEachHook = this.beforeEachHook;
this.beforeEachHook = () => hookFunction(previousBeforeEachHook);
return this;
}
afterEach(hookFunction) {
const previousAfterEachHook = this.afterEachHook;
this.afterEachHook = () => hookFunction(previousAfterEachHook);
return this;
}
}
exports.AsyncProperty = AsyncProperty;
AsyncProperty.dummyHook = () => { };

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.asyncProperty = asyncProperty;
const Arbitrary_1 = require("../arbitrary/definition/Arbitrary");
const tuple_1 = require("../../arbitrary/tuple");
const AsyncProperty_generic_1 = require("./AsyncProperty.generic");
const AlwaysShrinkableArbitrary_1 = require("../../arbitrary/_internals/AlwaysShrinkableArbitrary");
const globals_1 = require("../../utils/globals");
function asyncProperty(...args) {
if (args.length < 2) {
throw new Error('asyncProperty expects at least two parameters');
}
const arbs = (0, globals_1.safeSlice)(args, 0, args.length - 1);
const p = args[args.length - 1];
(0, globals_1.safeForEach)(arbs, Arbitrary_1.assertIsArbitrary);
const mappedArbs = (0, globals_1.safeMap)(arbs, (arb) => new AlwaysShrinkableArbitrary_1.AlwaysShrinkableArbitrary(arb));
return new AsyncProperty_generic_1.AsyncProperty((0, tuple_1.tuple)(...mappedArbs), (t) => p(...t));
}

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runIdToFrequency = runIdToFrequency;
const safeMathLog = Math.log;
function runIdToFrequency(runId) {
return 2 + ~~(safeMathLog(runId + 1) * 0.4342944819032518);
}

View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IgnoreEqualValuesProperty = void 0;
const stringify_1 = require("../../utils/stringify");
const PreconditionFailure_1 = require("../precondition/PreconditionFailure");
function fromSyncCached(cachedValue) {
return cachedValue === null ? new PreconditionFailure_1.PreconditionFailure() : cachedValue;
}
function fromCached(...data) {
if (data[1])
return data[0].then(fromSyncCached);
return fromSyncCached(data[0]);
}
function fromCachedUnsafe(cachedValue, isAsync) {
return fromCached(cachedValue, isAsync);
}
class IgnoreEqualValuesProperty {
constructor(property, skipRuns) {
this.property = property;
this.skipRuns = skipRuns;
this.coveredCases = new Map();
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
this.runBeforeEach = () => this.property.runBeforeEach();
this.runAfterEach = () => this.property.runAfterEach();
}
}
isAsync() {
return this.property.isAsync();
}
generate(mrng, runId) {
return this.property.generate(mrng, runId);
}
shrink(value) {
return this.property.shrink(value);
}
run(v, dontRunHook) {
const stringifiedValue = (0, stringify_1.stringify)(v);
if (this.coveredCases.has(stringifiedValue)) {
const lastOutput = this.coveredCases.get(stringifiedValue);
if (!this.skipRuns) {
return lastOutput;
}
return fromCachedUnsafe(lastOutput, this.property.isAsync());
}
const out = this.property.run(v, dontRunHook);
this.coveredCases.set(stringifiedValue, out);
return out;
}
}
exports.IgnoreEqualValuesProperty = IgnoreEqualValuesProperty;

View File

@@ -0,0 +1,83 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Property = void 0;
const PreconditionFailure_1 = require("../precondition/PreconditionFailure");
const IRawProperty_1 = require("./IRawProperty");
const GlobalParameters_1 = require("../runner/configuration/GlobalParameters");
const Stream_1 = require("../../stream/Stream");
const NoUndefinedAsContext_1 = require("../../arbitrary/_internals/helpers/NoUndefinedAsContext");
const globals_1 = require("../../utils/globals");
class Property {
constructor(arb, predicate) {
this.arb = arb;
this.predicate = predicate;
const { beforeEach = Property.dummyHook, afterEach = Property.dummyHook, asyncBeforeEach, asyncAfterEach, } = (0, GlobalParameters_1.readConfigureGlobal)() || {};
if (asyncBeforeEach !== undefined) {
throw (0, globals_1.Error)('"asyncBeforeEach" can\'t be set when running synchronous properties');
}
if (asyncAfterEach !== undefined) {
throw (0, globals_1.Error)('"asyncAfterEach" can\'t be set when running synchronous properties');
}
this.beforeEachHook = beforeEach;
this.afterEachHook = afterEach;
}
isAsync() {
return false;
}
generate(mrng, runId) {
const value = this.arb.generate(mrng, runId != null ? (0, IRawProperty_1.runIdToFrequency)(runId) : undefined);
return (0, NoUndefinedAsContext_1.noUndefinedAsContext)(value);
}
shrink(value) {
if (value.context === undefined && !this.arb.canShrinkWithoutContext(value.value_)) {
return Stream_1.Stream.nil();
}
const safeContext = value.context !== NoUndefinedAsContext_1.UndefinedContextPlaceholder ? value.context : undefined;
return this.arb.shrink(value.value_, safeContext).map(NoUndefinedAsContext_1.noUndefinedAsContext);
}
runBeforeEach() {
this.beforeEachHook();
}
runAfterEach() {
this.afterEachHook();
}
run(v, dontRunHook) {
if (!dontRunHook) {
this.beforeEachHook();
}
try {
const output = this.predicate(v);
return output == null || output === true
? null
: {
error: new globals_1.Error('Property failed by returning false'),
errorMessage: 'Error: Property failed by returning false',
};
}
catch (err) {
if (PreconditionFailure_1.PreconditionFailure.isFailure(err))
return err;
if (err instanceof globals_1.Error && err.stack) {
return { error: err, errorMessage: err.stack };
}
return { error: err, errorMessage: (0, globals_1.String)(err) };
}
finally {
if (!dontRunHook) {
this.afterEachHook();
}
}
}
beforeEach(hookFunction) {
const previousBeforeEachHook = this.beforeEachHook;
this.beforeEachHook = () => hookFunction(previousBeforeEachHook);
return this;
}
afterEach(hookFunction) {
const previousAfterEachHook = this.afterEachHook;
this.afterEachHook = () => hookFunction(previousAfterEachHook);
return this;
}
}
exports.Property = Property;
Property.dummyHook = () => { };

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.property = property;
const Arbitrary_1 = require("../arbitrary/definition/Arbitrary");
const tuple_1 = require("../../arbitrary/tuple");
const Property_generic_1 = require("./Property.generic");
const AlwaysShrinkableArbitrary_1 = require("../../arbitrary/_internals/AlwaysShrinkableArbitrary");
const globals_1 = require("../../utils/globals");
function property(...args) {
if (args.length < 2) {
throw new Error('property expects at least two parameters');
}
const arbs = (0, globals_1.safeSlice)(args, 0, args.length - 1);
const p = args[args.length - 1];
(0, globals_1.safeForEach)(arbs, Arbitrary_1.assertIsArbitrary);
const mappedArbs = (0, globals_1.safeMap)(arbs, (arb) => new AlwaysShrinkableArbitrary_1.AlwaysShrinkableArbitrary(arb));
return new Property_generic_1.Property((0, tuple_1.tuple)(...mappedArbs), (t) => p(...t));
}

View File

@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SkipAfterProperty = void 0;
const PreconditionFailure_1 = require("../precondition/PreconditionFailure");
function interruptAfter(timeMs, setTimeoutSafe, clearTimeoutSafe) {
let timeoutHandle = null;
const promise = new Promise((resolve) => {
timeoutHandle = setTimeoutSafe(() => {
const preconditionFailure = new PreconditionFailure_1.PreconditionFailure(true);
resolve(preconditionFailure);
}, timeMs);
});
return {
clear: () => clearTimeoutSafe(timeoutHandle),
promise,
};
}
class SkipAfterProperty {
constructor(property, getTime, timeLimit, interruptExecution, setTimeoutSafe, clearTimeoutSafe) {
this.property = property;
this.getTime = getTime;
this.interruptExecution = interruptExecution;
this.setTimeoutSafe = setTimeoutSafe;
this.clearTimeoutSafe = clearTimeoutSafe;
this.skipAfterTime = this.getTime() + timeLimit;
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
this.runBeforeEach = () => this.property.runBeforeEach();
this.runAfterEach = () => this.property.runAfterEach();
}
}
isAsync() {
return this.property.isAsync();
}
generate(mrng, runId) {
return this.property.generate(mrng, runId);
}
shrink(value) {
return this.property.shrink(value);
}
run(v, dontRunHook) {
const remainingTime = this.skipAfterTime - this.getTime();
if (remainingTime <= 0) {
const preconditionFailure = new PreconditionFailure_1.PreconditionFailure(this.interruptExecution);
if (this.isAsync()) {
return Promise.resolve(preconditionFailure);
}
else {
return preconditionFailure;
}
}
if (this.interruptExecution && this.isAsync()) {
const t = interruptAfter(remainingTime, this.setTimeoutSafe, this.clearTimeoutSafe);
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]);
propRun.then(t.clear, t.clear);
return propRun;
}
return this.property.run(v, dontRunHook);
}
}
exports.SkipAfterProperty = SkipAfterProperty;

View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeoutProperty = void 0;
const globals_1 = require("../../utils/globals");
const timeoutAfter = (timeMs, setTimeoutSafe, clearTimeoutSafe) => {
let timeoutHandle = null;
const promise = new Promise((resolve) => {
timeoutHandle = setTimeoutSafe(() => {
resolve({
error: new globals_1.Error(`Property timeout: exceeded limit of ${timeMs} milliseconds`),
errorMessage: `Property timeout: exceeded limit of ${timeMs} milliseconds`,
});
}, timeMs);
});
return {
clear: () => clearTimeoutSafe(timeoutHandle),
promise,
};
};
class TimeoutProperty {
constructor(property, timeMs, setTimeoutSafe, clearTimeoutSafe) {
this.property = property;
this.timeMs = timeMs;
this.setTimeoutSafe = setTimeoutSafe;
this.clearTimeoutSafe = clearTimeoutSafe;
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
this.runBeforeEach = () => Promise.resolve(this.property.runBeforeEach());
this.runAfterEach = () => Promise.resolve(this.property.runAfterEach());
}
}
isAsync() {
return true;
}
generate(mrng, runId) {
return this.property.generate(mrng, runId);
}
shrink(value) {
return this.property.shrink(value);
}
async run(v, dontRunHook) {
const t = timeoutAfter(this.timeMs, this.setTimeoutSafe, this.clearTimeoutSafe);
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]);
propRun.then(t.clear, t.clear);
return propRun;
}
}
exports.TimeoutProperty = TimeoutProperty;

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnbiasedProperty = void 0;
class UnbiasedProperty {
constructor(property) {
this.property = property;
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
this.runBeforeEach = () => this.property.runBeforeEach();
this.runAfterEach = () => this.property.runAfterEach();
}
}
isAsync() {
return this.property.isAsync();
}
generate(mrng, _runId) {
return this.property.generate(mrng, undefined);
}
shrink(value) {
return this.property.shrink(value);
}
run(v, dontRunHook) {
return this.property.run(v, dontRunHook);
}
}
exports.UnbiasedProperty = UnbiasedProperty;