UNPKG

assertthat

Version:
26 lines (25 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertSetIsNotContainingAnyOfIterable = 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 defekt_1 = require("defekt"); const assertSetIsNotContainingAnyOfIterable = function (actual, iterable) { const dispelledActual = (0, dispel_1.dispel)(actual); const dispelledExpected = (0, dispel_1.dispel)(iterable); const setFromExpected = new Set(dispelledExpected); const diff = (0, compareSets_1.compareSets)(dispelledActual, setFromExpected); if (!(0, EqualDiff_1.isEqualDiff)(diff) && diff.equal.size === 0) { return (0, defekt_1.value)(); } return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The set contains one or more of the items in the iterable.', actual: (0, prettyPrint_1.prettyPrint)(dispelledActual), expected: `To not contain any of:\n${(0, prettyPrint_1.prettyPrint)(dispelledExpected)}`, diff: `These items are contained, but should not be:\n${(0, prettyPrint_1.prettyPrint)((0, EqualDiff_1.isEqualDiff)(diff) ? setFromExpected : diff.equal)}` })); }; exports.assertSetIsNotContainingAnyOfIterable = assertSetIsNotContainingAnyOfIterable;