Skip to content

Commit

Permalink
Improve Test Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Jul 11, 2021
1 parent 57ed8f9 commit e386eae
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,21 @@ public void visit(TimezoneExpression expr) {

@Override
public void visit(JsonAggregateFunction expression) {
expression.accept(this);
Expression expr = expression.getExpression();
if (expr!=null) {
expr.accept(this);
}

expr = expression.getFilterExpression();
if (expr!=null) {
expr.accept(this);
}
}

@Override
public void visit(JsonFunction expression) {
expression.accept(this);
for (JsonFunctionExpression expr: expression.getExpressions()) {
expr.getExpression().accept(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,26 @@ public void testAtTimeZoneExpression() throws JSQLParserException {
ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter();
expr.accept(adapter);
}

@Test
public void testJsonFunction() throws JSQLParserException {
ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter();
CCJSqlParserUtil
.parseExpression("JSON_OBJECT( KEY foo VALUE bar, KEY foo VALUE bar)")
.accept(adapter);
CCJSqlParserUtil
.parseExpression("JSON_ARRAY( (SELECT * from dual) )")
.accept(adapter);
}

@Test
public void testJsonAggregateFunction() throws JSQLParserException {
ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter();
CCJSqlParserUtil
.parseExpression("JSON_OBJECTAGG( KEY foo VALUE bar NULL ON NULL WITH UNIQUE KEYS ) FILTER( WHERE name = 'Raj' ) OVER( PARTITION BY name )")
.accept(adapter);
CCJSqlParserUtil
.parseExpression("JSON_ARRAYAGG( a FORMAT JSON ABSENT ON NULL ) FILTER( WHERE name = 'Raj' ) OVER( PARTITION BY name )")
.accept(adapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ public void testObjectBuilder() throws JSQLParserException {
// this should work because we compare based on KEY only
Assert.assertEquals(keyValuePair1, keyValuePair2);

// this must fail because all the properties are considered
// this must fail because all the properties are considered
Assert.assertFalse(Objects.equals(keyValuePair1.toString(), keyValuePair2.toString()));

JsonKeyValuePair keyValuePair3 = new JsonKeyValuePair("foo", "bar", false, false).withUsingKeyKeyword(false).withUsingValueKeyword(false).withUsingFormatJson(false);
Assert.assertNotNull(keyValuePair3 );
Assert.assertEquals(keyValuePair3, keyValuePair3);
Assert.assertFalse(Objects.equals( keyValuePair3, f));

Assert.assertTrue(keyValuePair3.hashCode()!=0);

f.add(keyValuePair2);
}

Expand Down

0 comments on commit e386eae

Please sign in to comment.