assertthat
Version:
assertthat provides fluent TDD.
34 lines (33 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertSetIsAtMostSet = void 0;
const errors_1 = require("../../errors");
const compareSets_1 = require("../../comparisons/forSets/compareSets");
const dispel_1 = require("../../dispel/dispel");
const EqualDiff_1 = require("../../diffs/EqualDiff");
const prettyPrint_1 = require("../../prettyPrint/typeAware/prettyPrint");
const prettyPrintDiff_1 = require("../../prettyPrint/typeAware/prettyPrintDiff");
const defekt_1 = require("defekt");
const assertSetIsAtMostSet = function (actual, expected) {
const dispelledActual = (0, dispel_1.dispel)(actual);
const dispelledExpected = (0, dispel_1.dispel)(expected);
const diff = (0, compareSets_1.compareSets)(dispelledActual, dispelledExpected);
if ((0, EqualDiff_1.isEqualDiff)(diff)) {
return (0, defekt_1.value)();
}
if (diff.additions.size === 0) {
return (0, defekt_1.value)();
}
const cleanedDiff = {
...diff,
omissions: new Set(),
equal: new Set()
};
return (0, defekt_1.error)(new errors_1.AssertionFailed({
message: 'The actual set is not entirely contained in the expected set.',
actual: (0, prettyPrint_1.prettyPrint)(dispelledActual),
expected: `To be entirely contained in:\n${(0, prettyPrint_1.prettyPrint)(dispelledExpected)}`,
diff: `The following sub-set shows relevant changes between actual and expected:\n${(0, prettyPrintDiff_1.prettyPrintDiff)(cleanedDiff)}`
}));
};
exports.assertSetIsAtMostSet = assertSetIsAtMostSet;