Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Fix precedence of negation vs comparison #70

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ expression
: expression '.' chainedExpression # chainExpression
| expression bracketSpecifier # bracketedExpression
| bracketSpecifier # bracketExpression
| expression COMPARATOR expression # comparisonExpression
| '!' expression # notExpression
| expression COMPARATOR expression # comparisonExpression
| expression '&&' expression # andExpression
| expression '||' expression # orExpression
| identifier # identifierExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ protected boolean internalEquals(Object o) {
return negated.equals(other.negated);
}

@Override
protected String internalToString() {
return negated.toString();
}

@Override
protected int internalHashCode() {
return 17 + 31 * negated.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,17 @@ public void negatedSelectionExpression() {
assertThat(actual, is(expected));
}

@Test
public void negatedComparison() {
Expression<Object> expected = Comparison(
"==",
Negate(Property("foo")),
JsonLiteral("false")
);
Expression<Object> actual = compile("!foo == `false`");
assertThat(actual, is(expected));
}

@Test
public void bareJsonLiteralExpression() {
Expression<Object> expected = JsonLiteral("{}");
Expand Down