UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

20 lines (19 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrayLengthExecutor = void 0; const errors_1 = require("../../entities/errors"); const results_1 = require("../../entities/results"); const types_1 = require("../../entities/types"); const strip = (matcher, matchContext) => { throw new errors_1.StripUnsupportedError(matcher, matchContext); }; const check = (matcher, matchContext, actual) => Array.isArray(actual) ? (0, results_1.combineResults)((0, results_1.errorWhen)(matcher['case:matcher:maxLength'] !== types_1.ARRAY_LENGTH_PARAMETER_INFINITE && actual.length > matcher['case:matcher:maxLength'], (0, results_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, results_1.errorWhen)(actual.length < matcher['case:matcher:minLength'], (0, results_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, results_1.combineResults)((0, results_1.makeResults)((0, results_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, };