UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

52 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayStartsWith = exports.arrayContains = exports.arrayLength = exports.arrayEachEntryMatches = void 0; const case_entities_internal_1 = require("@contract-case/case-entities-internal"); const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const entities_1 = require("../../../entities"); /** * Matches an array where each element matches the provided matcher. * * @param matcher - The example object, array, primitive or matcher to match against */ const arrayEachEntryMatches = (matcher, example) => ({ '_case:matcher:type': case_entities_internal_1.ARRAY_EACH_ENTRY_MATCHES_TYPE, '_case:matcher:matcher': matcher, ...(example !== undefined ? { '_case:matcher:example': example } : {}), }); exports.arrayEachEntryMatches = arrayEachEntryMatches; /** * Matches an Array whose length is within a certain range. * * @param options - `ArrayLengthOptions { minLength?: number; maxLength?: number }` */ const arrayLength = (options) => { const matcher = (0, entities_1.coreArrayLengthMatcher)(options); if (matcher['_case:matcher:minLength'] === 0 && matcher['_case:matcher:maxLength'] !== 0) { throw new case_plugin_base_1.CaseConfigurationError("Can't create an arrayLength matcher with minimum size 0 and maximum size not 0. Use a raw empty array instead. See the documentation for details.", 'DONT_ADD_LOCATION'); // TODO write documentation for this } return matcher; }; exports.arrayLength = arrayLength; /** * Matches an Array which contains elements that match the given matchers. * * Note that two different matchers may be satisfied by the same item in the array. * * @param matchers - any number of matchers, each of which must be found inside the array. */ const arrayContains = (...matchers) => ({ '_case:matcher:type': case_entities_internal_1.ARRAY_CONTAINS_TYPE, '_case:matcher:matchers': matchers, }); exports.arrayContains = arrayContains; /** * Matches an Array which starts with the provided array * * @param matchers - An array of matchers that describes the start of the array */ const arrayStartsWith = (matchers) => (0, entities_1.coreShapedArrayMatcher)(matchers); exports.arrayStartsWith = arrayStartsWith; //# sourceMappingURL=arrays.js.map