Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unary operator possible in concatenated logic expressions #1098

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grammars/salesforceFormula.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ArithmeticOperator
/ "-"

LogicalTerm
= __ op:LogicalConcatenationOperator __ expr:LogicalCompareExpression {
= __ op:LogicalConcatenationOperator __ expr:(LogicalCompareExpression / UnaryExpression) {
return [op, expr];
}

Expand Down
45 changes: 45 additions & 0 deletions test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,23 @@ export const testBuildAst = (handler) => {
expect(handler('TRUE && FALSE')).to.deep.equal(expected);
});

it('simple not', () => {
const expected = {
type: 'callExpression',
id: 'not',
arguments: [
{
type: 'literal',
value: true,
dataType: 'checkbox',
options: {},
},
],
};

expect(handler('!TRUE')).to.deep.equal(expected);
});

it('default precedence', () => {
const expected = {
type: 'callExpression',
Expand Down Expand Up @@ -1164,6 +1181,34 @@ export const testBuildAst = (handler) => {
};
expect(handler('!FALSE')).to.deep.equal(expected);
});

it('NOT in concatenation literal', () => {
const expected = {
type: 'callExpression',
id: 'or',
arguments: [
{
type: 'literal',
value: true,
dataType: 'checkbox',
options: {},
},
{
type: 'callExpression',
id: 'not',
arguments: [
{
type: 'literal',
value: false,
dataType: 'checkbox',
options: {},
},
],
},
],
};
expect(handler('TRUE || !FALSE')).to.deep.equal(expected);
});
});

context('binary', () => {
Expand Down