Skip to content

Commit

Permalink
Validation no fatal errors (#406)
Browse files Browse the repository at this point in the history
* Empty properties are not fatal errors anymore

* fix test
  • Loading branch information
joswarmer authored Nov 19, 2024
1 parent 7b2ad26 commit 9ae5c2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class NonOptionalsCheckerTemplate {
}

result += `if (modelelement.${prop.name} === null || modelelement.${prop.name} === undefined ${additionalStringCheck}) {
hasFatalError = true;
this.errorList.push(new ${Names.FreError}("Property '${prop.name}' must have a value", modelelement, ${locationdescription}, '${prop.name}', ${Names.FreErrorSeverity}.Error));
}
`;
Expand All @@ -95,9 +94,8 @@ export class NonOptionalsCheckerTemplate {
this.done.push(concept);
return `${commentBefore}
public execBefore${Names.classifier(concept)}(modelelement: ${Names.classifier(concept)}): boolean {
let hasFatalError: boolean = false;
${result}
return hasFatalError;
return false;
}`;
} else {
return ``;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ export class ReferenceCheckerTemplate {
result += `for (const referredElem of modelelement.${prop.name} ) {
if (referredElem.referred === null) {
this.makeErrorMessage(modelelement, referredElem, "${prop.name}", \`\${${locationdescription}}\`);
hasFatalError = true;
}
}`;
} else {
result += `if (!!modelelement.${prop.name} && modelelement.${prop.name}.referred === null) {
this.makeErrorMessage(modelelement, modelelement.${prop.name}, "${prop.name}", \`\${${locationdescription}}\`);
hasFatalError = true;
}`;
}
}
Expand All @@ -102,9 +100,8 @@ export class ReferenceCheckerTemplate {
* @param modelelement
*/
public execBefore${Names.classifier(concept)}(modelelement: ${Names.classifier(concept)}): boolean {
let hasFatalError: boolean = false;
${result}
return hasFatalError;
return false;
}`;
} else {
return ``;
Expand Down
20 changes: 15 additions & 5 deletions packages/test/src/demo/__tests__/checkValidator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FreNodeReference, FreError, AST } from "@freon4dsl/core";
import { FreNodeReference, FreError, AST, FreNode, isNullOrUndefined } from "@freon4dsl/core";
import { DemoEnvironment } from "../config/gen/DemoEnvironment.js";
import {
DemoModel,
Expand Down Expand Up @@ -216,10 +216,20 @@ describe("Testing Validator", () => {
// console.log(DemoEnvironment.getInstance().writer.writeToString(mm))
// );
errors = validator.validate(model, true);
// errors.forEach(e =>
// console.log(e.message + " => " + e.locationdescription + " of severity " + e.severity)
// );
errors.forEach(e =>
console.log(e.message + " => " + e.locationdescription + " prop: " + e.propertyName + " node: " + p(e.reportedOn) + " of severity " + e.severity)
);
// TODO check every one of the messages
expect(errors.length).toBe(23);
expect(errors.length).toBe(24);
});
});

function p(n: FreNode | FreNode[]): string {
if (isNullOrUndefined(n)) {
return "null-undefined"
} else if (Array.isArray(p)) {
return(n as FreNode[]).map(f => f.freId()).join(", ")
} else {
return (n as FreNode).freId()
}
}

0 comments on commit 9ae5c2b

Please sign in to comment.