UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

33 lines (32 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextVariableMatcher = void 0; const entities_1 = require("../../entities"); const context_1 = require("../../entities/context"); const check = (matcher, matchContext, actual) => { if (matcher['case:matcher:variableName'] in matchContext['case:currentRun:context:variables']) { const value = matchContext['case:currentRun:context:variables'][matcher['case:matcher:variableName']]; if (value === undefined) { throw new entities_1.CaseConfigurationError(`The variable '${matcher['case:matcher:variableName']}' was undefined, which is not a valid variable value`, matchContext); } return matchContext.descendAndCheck(value, (0, context_1.addLocation)(`:stateVariable[${matcher['case:matcher:variableName']}]`, matchContext), actual); } return matchContext.descendAndCheck(matchContext.lookupVariable(matcher['case:matcher:variableName']), (0, context_1.addLocation)(`:contractVariable[${matcher['case:matcher:variableName']}]`, matchContext), actual); }; const strip = (matcher, matchContext) => { if (matcher['case:matcher:variableName'] in matchContext['case:currentRun:context:variables']) { const value = matchContext['case:currentRun:context:variables'][matcher['case:matcher:variableName']]; if (value === undefined) { throw new entities_1.CaseConfigurationError(`The variable '${matcher['case:matcher:variableName']}' was undefined, which is not a valid variable value`, matchContext); } return matchContext.descendAndStrip(value, (0, context_1.addLocation)(`:stateVariable[${matcher['case:matcher:variableName']}]`, matchContext)); } return matchContext.descendAndStrip(matchContext.lookupVariable(matcher['case:matcher:variableName']), (0, context_1.addLocation)(`:contractVariable[${matcher['case:matcher:variableName']}]`, matchContext)); }; exports.ContextVariableMatcher = { describe: (matcher) => `{{${matcher['case:matcher:variableName']}}}`, check, strip, };