UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

23 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShapedArrayExecutor = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const strip = (matcher, matchContext) => matcher['_case:matcher:children'].map((expectedChild, index) => matchContext.descendAndStrip(expectedChild, (0, case_plugin_base_1.addLocation)(`[${index}]`, matchContext))); const check = async (matcher, matchContext, actual) => (0, case_plugin_base_1.combineResults)(Array.isArray(actual) ? (0, case_plugin_base_1.combineResults)(actual.length >= matcher['_case:matcher:children'].length ? (await Promise.all(matcher['_case:matcher:children'] .map((expectedChild, index) => matchContext.descendAndCheck(expectedChild, (0, case_plugin_base_1.addLocation)(`[${index}]`, matchContext), actual[index])) .flat())).flat() : (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `Array has different lengths - expected at least '${matcher['_case:matcher:children'].length}' elements, but found only '${actual.length} elements`, actual, matchContext)), matcher['_case:matcher:children'].length === 0 && actual.length !== 0 ? (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `Expected an empty array, but instead found ${actual.length} elements`, actual, matchContext)) : (0, case_plugin_base_1.makeNoErrorResult)()) : (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `'${typeof actual}' is not an array`, actual, matchContext))); exports.ShapedArrayExecutor = { describe: (matcher, context) => `an array shaped like [${matcher['_case:matcher:children'] .map((child, index) => context.descendAndDescribe(child, (0, case_plugin_base_1.addLocation)(`[${index}]`, context))) .join(',')}]`, check, strip, validate: (matcher, matchContext) => Promise.all(matcher['_case:matcher:children'].map((childMatcher, index) => matchContext.descendAndValidate(childMatcher, (0, case_plugin_base_1.addLocation)(`[${index}]`, matchContext)))).then(() => { }), }; //# sourceMappingURL=ShapedArrayExecutor.js.map