@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
43 lines • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextVariableMatcher = void 0;
const case_plugin_base_1 = require("@contract-case/case-plugin-base");
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 case_plugin_base_1.CaseConfigurationError(`The variable '${matcher['_case:matcher:variableName']}' was undefined, which is not a valid variable value`, matchContext);
}
return matchContext.descendAndCheck(value, (0, case_plugin_base_1.addLocation)(`:stateVariable[${matcher['_case:matcher:variableName']}]`, matchContext), actual);
}
return matchContext.descendAndCheck(matchContext.lookupVariable(matcher['_case:matcher:variableName']), (0, case_plugin_base_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 case_plugin_base_1.CaseConfigurationError(`The variable '${matcher['_case:matcher:variableName']}' was undefined, which is not a valid variable value`, matchContext);
}
return matchContext.descendAndStrip(value, (0, case_plugin_base_1.addLocation)(`:stateVariable[${matcher['_case:matcher:variableName']}]`, matchContext));
}
return matchContext.descendAndStrip(matchContext.lookupVariable(matcher['_case:matcher:variableName']), (0, case_plugin_base_1.addLocation)(`:contractVariable[${matcher['_case:matcher:variableName']}]`, matchContext));
};
exports.ContextVariableMatcher = {
describe: (matcher) => `{{${matcher['_case:matcher:variableName']}}}`,
check,
strip,
validate: (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 case_plugin_base_1.CaseConfigurationError(`The variable '${matcher['_case:matcher:variableName']}' was undefined, which is not a valid variable value`, matchContext);
}
return matchContext.descendAndValidate(value, (0, case_plugin_base_1.addLocation)(`:stateVariable[${matcher['_case:matcher:variableName']}]`, matchContext));
}
return matchContext.descendAndValidate(matchContext.lookupVariable(matcher['_case:matcher:variableName']), (0, case_plugin_base_1.addLocation)(`:contractVariable[${matcher['_case:matcher:variableName']}]`, matchContext));
},
};
//# sourceMappingURL=ContextVariableMatcher.js.map