UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

22 lines (21 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringPrefixMatcher = void 0; const entities_1 = require("../../entities"); const context_1 = require("../../entities/context"); const results_1 = require("../../entities/results"); const check = async (matcher, matchContext, actual) => { if (typeof actual !== 'string') { return (0, results_1.makeResults)((0, results_1.matchingError)(matcher, `'${typeof actual}' is not a string`, actual, matchContext)); } return actual.startsWith(matcher['case:matcher:prefix']) ? matchContext.descendAndCheck(matcher['case:matcher:suffix'], (0, context_1.addLocation)(':prefix', matchContext), actual.slice(matcher['case:matcher:prefix'].length)) : (0, results_1.makeResults)((0, results_1.matchingError)(matcher, `The string '${actual}' did not start with the expected prefix '${matcher['case:matcher:prefix']}'`, actual, matchContext)); }; exports.StringPrefixMatcher = { describe: (matcher, matchContext) => `"${matcher['case:matcher:prefix']}${matchContext .descendAndDescribe(matcher['case:matcher:suffix'], (0, context_1.addLocation)(':prefix', matchContext)) .replace(/^"+|"+$/g, '')}"`, check, strip: (matcher, matchContext) => `${matcher['case:matcher:prefix']}${(0, entities_1.mustResolveToString)(matcher['case:matcher:suffix'], (0, context_1.addLocation)(':prefix', matchContext))}`, };