Fix property chain orders of Operators in isDotExpression and isSomPredicate

This commit is contained in:
nmtigor 2022-09-21 17:20:23 +02:00
parent 2146d93609
commit 22cc9b7dc7
2 changed files with 13 additions and 4 deletions

View File

@ -661,14 +661,14 @@ class AstBinaryOperator extends Leaf {
} }
isDotExpression() { isDotExpression() {
return Operators.id.dot <= this.id && this.id <= Operators.id.dotHash; return Operators.dot.id <= this.id && this.id <= Operators.dotHash.id;
} }
isSomPredicate() { isSomPredicate() {
return ( return (
this.isDotExpression() || this.isDotExpression() ||
(Operators.id.lt <= this.id && (Operators.lt.id <= this.id &&
this.id <= Operators.id.or && this.id <= Operators.or.id &&
((this.left.isDotExpression() && this.right.isConstant()) || ((this.left.isDotExpression() && this.right.isConstant()) ||
(this.left.isConstant() && this.right.isDotExpression()) || (this.left.isConstant() && this.right.isDotExpression()) ||
(this.left.isDotExpression() && this.right.isDotExpression()))) (this.left.isDotExpression() && this.right.isDotExpression())))

View File

@ -266,7 +266,9 @@ describe("FormCalc expression parser", function () {
it("should parse basic expression with dots", function () { it("should parse basic expression with dots", function () {
const parser = new Parser("a.b.c.#d..e.f..g.*"); const parser = new Parser("a.b.c.#d..e.f..g.*");
expect(parser.parse().dump()[0]).toEqual({ const exprlist = parser.parse();
expect(exprlist.expressions[0].isDotExpression()).toEqual(true);
expect(exprlist.dump()[0]).toEqual({
operator: ".", operator: ".",
left: { id: "a" }, left: { id: "a" },
right: { right: {
@ -727,5 +729,12 @@ endfunc
); );
expect(() => parser.parse()).toThrow(new Error(Errors.if)); expect(() => parser.parse()).toThrow(new Error(Errors.if));
}); });
it("should parse som predicate", () => {
const parser = new Parser("a.b <= 3");
const expr = parser.parse().expressions[0];
expect(expr.isSomPredicate()).toEqual(true);
expect(expr.left.isSomPredicate()).toEqual(true);
});
}); });
}); });