arch-unit-ts
Version:
100 lines • 2.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DescribedPredicate = void 0;
const Assert_1 = require("../../error/domain/Assert");
class DescribedPredicate {
description;
constructor(description) {
this.description = description;
}
as(description) {
return new AsPredicate(this, description);
}
and(other) {
return new AndPredicate(this, other);
}
or(other) {
return new OrPredicate(this, other);
}
static not(predicate) {
return new NotPredicate(predicate);
}
onResultOf(function_) {
return new OnResultOfPredicate(this, function_);
}
static alwaysFalse() {
return new AlwaysFalsePredicate();
}
}
exports.DescribedPredicate = DescribedPredicate;
class AlwaysFalsePredicate extends DescribedPredicate {
constructor() {
super('always false');
}
test() {
return false;
}
}
class AsPredicate extends DescribedPredicate {
current;
constructor(current, description) {
Assert_1.Assert.notNullOrUndefined('current', current);
super(description);
this.current = current;
}
test(input) {
return this.current.test(input);
}
}
class AndPredicate extends DescribedPredicate {
current;
other;
constructor(current, other) {
Assert_1.Assert.notNullOrUndefined('current', current);
Assert_1.Assert.notNullOrUndefined('other', other);
super(current.description + ' and ' + other.description);
this.current = current;
this.other = other;
}
test(input) {
return this.current.test(input) && this.other.test(input);
}
}
class OrPredicate extends DescribedPredicate {
current;
other;
constructor(current, other) {
Assert_1.Assert.notNullOrUndefined('current', current);
Assert_1.Assert.notNullOrUndefined('other', other);
super(current.description + ' or ' + other.description);
this.current = current;
this.other = other;
}
test(input) {
return this.current.test(input) || this.other.test(input);
}
}
class NotPredicate extends DescribedPredicate {
predicate;
constructor(predicate) {
Assert_1.Assert.notNullOrUndefined('predicate', predicate);
super('not ' + predicate.description);
this.predicate = predicate;
}
test(input) {
return !this.predicate.test(input);
}
}
class OnResultOfPredicate extends DescribedPredicate {
current;
function_;
constructor(current, function_) {
super(current.description);
this.current = current;
this.function_ = function_;
}
test(input) {
return this.current.test(this.function_.apply(input));
}
}
//# sourceMappingURL=DescribedPredicate.js.map