UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

37 lines 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrayLengthExecutor = 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 strip = (matcher, matchContext) => { throw new case_plugin_base_1.StripUnsupportedError(matcher, matchContext); }; const check = (matcher, matchContext, actual) => Array.isArray(actual) ? (0, case_plugin_base_1.combineResults)((0, case_plugin_base_1.errorWhen)(matcher['_case:matcher:maxLength'] !== case_entities_internal_1.ARRAY_LENGTH_PARAMETER_INFINITE && actual.length > matcher['_case:matcher:maxLength'], (0, case_plugin_base_1.matchingError)(matcher, `Array length of '${actual.length}' is over the maximum length of ${matcher['_case:matcher:maxLength']}`, actual, matchContext, `Array length <= ${matcher['_case:matcher:maxLength']}`)), (0, case_plugin_base_1.errorWhen)(actual.length < matcher['_case:matcher:minLength'], (0, case_plugin_base_1.matchingError)(matcher, `Array length of '${actual.length}' is under the minimum length of ${matcher['_case:matcher:minLength']}`, actual, matchContext, `Array length >= ${matcher['_case:matcher:minLength']}`))) : (0, case_plugin_base_1.combineResults)((0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `'${typeof actual}' is not an array`, actual, matchContext, `An array`))); exports.ArrayLengthExecutor = { describe: (matcher) => `an array of length min: ${matcher['_case:matcher:minLength']}, max: ${matcher['_case:matcher:maxLength']};`, check, strip, validate: (matcher, matchContext) => Promise.resolve().then(() => { if ((matcher['_case:matcher:maxLength'] !== case_entities_internal_1.ARRAY_LENGTH_PARAMETER_INFINITE && matcher['_case:matcher:maxLength'] < 0) || Number.isNaN(matcher['_case:matcher:maxLength'])) { // we don't actually bother to check whether it's an integer, // because if someone sets it to 5.4, // then we'll still respect the max length throw new case_plugin_base_1.CaseConfigurationError(`Array maximum length was set to the invalid value '${matcher['_case:matcher:maxLength']}'. It must be a positive integer`, matchContext); } if (matcher['_case:matcher:minLength'] < 0 || Number.isNaN(matcher['_case:matcher:minLength'])) { // we don't actually bother to check whether it's an integer, // because if someone sets it to 5.4, // then we'll still respect the max length throw new case_plugin_base_1.CaseConfigurationError(`Array minimum length was set to the invalid value '${matcher['_case:matcher:minLength']}'. It must be a positive integer`, matchContext); } }), }; //# sourceMappingURL=ArrayLengthExecutor.js.map