Skip to content

Commit

Permalink
Additional tests cases for precedence and associativity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Szabó Miklós committed May 27, 2021
1 parent 8cb7ce5 commit 77c30b8
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,55 @@ public void testParseAndBuildForXOR() throws JSQLParserException {
assertDeparse(select, statement);
assertEqualsObjectTree(parsed, select);
}

@Test
public void testParseAndBuildForXORComplexCondition() throws JSQLParserException {
String statement = "SELECT * FROM tab1 AS t1 WHERE " +
"a AND b OR c XOR d";

Statement parsed = TestUtils.assertSqlCanBeParsedAndDeparsed(statement);

Table t1 = new Table("tab1").withAlias(new Alias("t1", true));

XorExpression where = new XorExpression()
.withLeftExpression(
new OrExpression()
.withLeftExpression(
new AndExpression()
.withLeftExpression(new Column("a"))
.withRightExpression(new Column("b"))
)
.withRightExpression(new Column("c")))
.withRightExpression(new Column("d")
);

Select select = new Select().withSelectBody(new PlainSelect().addSelectItems(new AllColumns()).withFromItem(t1)
.withWhere(where));

assertDeparse(select, statement);
assertEqualsObjectTree(select, parsed);
}

@Test
public void testParseAndBuildForXORs() throws JSQLParserException {
String statement = "SELECT * FROM tab1 AS t1 WHERE " +
"a XOR b XOR c";

Statement parsed = TestUtils.assertSqlCanBeParsedAndDeparsed(statement);

Table t1 = new Table("tab1").withAlias(new Alias("t1", true));

XorExpression where = new XorExpression()
.withLeftExpression(
new XorExpression()
.withLeftExpression(new Column("a"))
.withRightExpression(new Column("b")))
.withRightExpression(new Column("c"));

Select select = new Select().withSelectBody(new PlainSelect().addSelectItems(new AllColumns()).withFromItem(t1)
.withWhere(where));

assertDeparse(select, statement);
assertEqualsObjectTree(select, parsed);
}
}

0 comments on commit 77c30b8

Please sign in to comment.