@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
41 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AndCombinationMatcher = void 0;
const case_plugin_base_1 = require("@contract-case/case-plugin-base");
const strip = (matcher, matchContext) => {
const firstStrippedResult = matcher['_case:matcher:children']
.map((additionalMatcher, index) => {
try {
return matchContext.descendAndStrip(additionalMatcher, (0, case_plugin_base_1.addLocation)(`:and[${index}]`, matchContext));
}
catch (e) {
if (e instanceof case_plugin_base_1.StripUnsupportedError) {
matchContext.logger.deepMaintainerDebug(`AndCombinationMatcher is ignoring StripUnsupportedError from ${(0, case_plugin_base_1.isCaseNode)(additionalMatcher)
? additionalMatcher['_case:matcher:type']
: additionalMatcher}`);
return e;
}
throw e;
}
})
.find((item) => !(item instanceof case_plugin_base_1.StripUnsupportedError));
if (firstStrippedResult === undefined ||
firstStrippedResult instanceof case_plugin_base_1.StripUnsupportedError // This check isn't necessary, but the compiler now knows that it's not returning an error
) {
matchContext.logger.maintainerDebug(`AndCombinationMatcher had no matchers that supported strip`);
throw new case_plugin_base_1.StripUnsupportedError(matcher, matchContext);
}
return firstStrippedResult;
};
const check = async (matcher, matchContext, actual) => (await Promise.all(matcher['_case:matcher:children']
.map((expectedChild, index) => matchContext.descendAndCheck(expectedChild, (0, case_plugin_base_1.addLocation)(`:and[${index}]`, matchContext), actual))
.flat())).flat();
exports.AndCombinationMatcher = {
describe: (matcher, matchContext) => `${matcher['_case:matcher:children']
.map((child, index) => matchContext.descendAndDescribe(child, (0, case_plugin_base_1.addLocation)(`:and[${index}]`, matchContext)))
.join(' / ')}`,
check,
strip,
validate: (matcher, matchContext) => Promise.resolve().then(() => Promise.all(matcher['_case:matcher:children'].map((child, index) => matchContext.descendAndValidate(child, (0, case_plugin_base_1.addLocation)(`:and[${index}]`, matchContext)))).then(() => { })),
};
//# sourceMappingURL=AndCombinationMatcher.js.map