UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

26 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringSuffixMatcher = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const check = async (matcher, matchContext, actual) => { if (typeof actual !== 'string') { return (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `'${typeof actual}' is not a string`, actual, matchContext)); } return actual.endsWith(matcher['_case:matcher:suffix']) ? matchContext.descendAndCheck(matcher['_case:matcher:prefix'], (0, case_plugin_base_1.addLocation)(':suffix', matchContext), actual.substring(0, actual.length - matcher['_case:matcher:suffix'].length)) : (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `The string '${actual}' did not end with the expected suffix '${matcher['_case:matcher:suffix']}'`, actual, matchContext)); }; exports.StringSuffixMatcher = { describe: (matcher, matchContext) => `"${matchContext .descendAndDescribe(matcher['_case:matcher:prefix'], (0, case_plugin_base_1.addLocation)(':suffix', matchContext)) .replace(/^"+|"+$/g, '')}${matcher['_case:matcher:suffix']}"`, check, strip: (matcher, matchContext) => `${(0, case_plugin_base_1.mustResolveToString)(matcher['_case:matcher:prefix'], (0, case_plugin_base_1.addLocation)(':prefix', matchContext))}${matcher['_case:matcher:suffix']}`, validate: (matcher, matchContext) => Promise.resolve().then(() => { if (typeof matcher['_case:matcher:suffix'] !== 'string') { throw new case_plugin_base_1.CaseConfigurationError(`Expected a string for the suffix, but got '${typeof matcher['_case:matcher:suffix']}' instead. Did you put the arguments the wrong way around for the suffix matcher?`, matchContext); } return matchContext.descendAndValidate(matcher['_case:matcher:prefix'], (0, case_plugin_base_1.addLocation)(':suffix', matchContext)); }), }; //# sourceMappingURL=StringSuffixMatcher.js.map