Fixed parse errors not showing up on calculations

This commit is contained in:
Stefan Zermatten
2021-09-27 16:39:44 +02:00
parent 111040e789
commit 85e8756d1d
3 changed files with 27 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ import clean from '../../utility/cleanProp.testFn.js';
export default function(){
const computation = buildComputationFromProps(testProperties);
const hasLink = computation.dependencyGraph.hasLink;
const prop = (id) => computation.propsById[id];
assert.isTrue(
!!hasLink('childId', 'spellListId'),
'Ancestor references of parent in inline calculations should create dependency'
@@ -21,6 +23,10 @@ export default function(){
!!hasLink('grandchildId', 'wisdom'),
'Variable references create dependencies even if the attributes don\'t exist'
);
assert.equal(
prop('strengthId').baseValue.errors.length, 1,
'Parse errors should be added to calculation errors'
);
}
var testProperties = [
@@ -49,6 +55,9 @@ var testProperties = [
_id: 'strengthId',
type: 'attribute',
variableName: 'strength',
baseValue: {
calculation: '15 + ',
},
ancestors: [{id: 'charId'}],
}),
];

View File

@@ -24,7 +24,11 @@ function evaluateCalculation(calculation, scope){
} else {
calculation.value = NaN;
}
calculation.errors = context.errors;
if (calculation.errors){
calculation.errors = [...calculation.errors, ...context.errors]
} else {
calculation.errors = context.errors
}
}
function embedInlineCalculations(inlineCalcObj){

View File

@@ -13,6 +13,10 @@ export default function(){
assert.equal(prop('strengthId').modifier, 1);
assert.equal(prop('referencesDexId').value, 4);
assert.equal(prop('hitDiceId').constitutionMod, 5);
assert.equal(
prop('parseErrorId').baseValue.errors.length, 1,
'Parse errors should be added to calculation errors'
);
}
var testProperties = [
@@ -74,4 +78,13 @@ var testProperties = [
calculation: '4'
},
}),
clean({
_id: 'parseErrorId',
variableName: 'parseError',
type: 'attribute',
attributeType: 'ability',
baseValue: {
calculation: '12 +'
},
}),
];