Skip to content

Commit

Permalink
Fix not bug (#1144)
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Bayer <[email protected]>

Co-authored-by: Steven Bayer <[email protected]>
  • Loading branch information
sbayer55 and sbayer55 authored Mar 7, 2022
1 parent 890e026 commit 818d9cb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ setInitializer
;

unaryNotOperatorExpression
: unaryOperator conditionalExpression
: unaryOperator parenthesesExpression
| unaryOperator primary
;

unaryOperator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,56 @@ void testValidJsonPointerCharacterSet() {
assertThat(expression, isExpression(isJsonPointerUnaryTree()));
assertThat(errorListener.isErrorFound(), is(false));
}

@Test
void testNotOperationOrder() {
final ParserRuleContext expression = parseExpression("not false or true");

final DiagnosingMatcher<ParseTree> lhs = isParseTree(
CONDITIONAL_EXPRESSION,
EQUALITY_OPERATOR_EXPRESSION,
REGEX_OPERATOR_EXPRESSION,
RELATIONAL_OPERATOR_EXPRESSION,
SET_OPERATOR_EXPRESSION,
UNARY_OPERATOR_EXPRESSION,
UNARY_NOT_OPERATOR_EXPRESSION
).withChildrenMatching(
isOperator(UNARY_OPERATOR),
isUnaryTree()
);
final DiagnosingMatcher<ParseTree> rhs = isUnaryTree();

assertThat(expression, isExpression(hasContext(
CONDITIONAL_EXPRESSION,
lhs,
isOperator(CONDITIONAL_OPERATOR),
rhs
)));
assertThat(errorListener.isErrorFound(), is(false));
}

@Test
void testNotPriorityOperationOrder() {
final ParserRuleContext expression = parseExpression("not (false or true)");

final DiagnosingMatcher<ParseTree> parenthesesExpression = isParenthesesExpression(hasContext(
CONDITIONAL_EXPRESSION,
isUnaryTree(),
isOperator(CONDITIONAL_OPERATOR),
isUnaryTree()
));

final DiagnosingMatcher<ParseTree> not = isParseTree(
CONDITIONAL_EXPRESSION,
EQUALITY_OPERATOR_EXPRESSION,
REGEX_OPERATOR_EXPRESSION,
RELATIONAL_OPERATOR_EXPRESSION,
SET_OPERATOR_EXPRESSION,
UNARY_OPERATOR_EXPRESSION,
UNARY_NOT_OPERATOR_EXPRESSION
).withChildrenMatching(isOperator(UNARY_OPERATOR), parenthesesExpression);

assertThat(expression, isExpression(not));
assertThat(errorListener.isErrorFound(), is(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public abstract class GrammarTest {
DataPrepperExpressionParser.SetOperatorExpressionContext.class;
protected static final Class<? extends ParseTree> UNARY_OPERATOR_EXPRESSION =
DataPrepperExpressionParser.UnaryOperatorExpressionContext.class;
protected static final Class<? extends ParseTree> UNARY_NOT_OPERATOR_EXPRESSION =
DataPrepperExpressionParser.UnaryNotOperatorExpressionContext.class;
protected static final Class<? extends ParseTree> UNARY_OPERATOR =
DataPrepperExpressionParser.UnaryOperatorContext.class;
protected static final Class<? extends ParseTree> PARENTHESES_EXPRESSION = DataPrepperExpressionParser.ParenthesesExpressionContext.class;
//endregion

Expand Down

0 comments on commit 818d9cb

Please sign in to comment.