Skip to content

Commit

Permalink
Test case fixes for AST changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KRVPerera committed Jun 14, 2020
1 parent 01d5aab commit 22b0b95
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ public void testAnnotOnExternal() {
private void assertAnnotationNameAndKeyValuePair(BLangAnnotationAttachment attachment, String annotName,
String fieldName, Object value) {
Assert.assertEquals(attachment.annotationName.getValue(), annotName);
BLangTypeConversionExpr expr = (BLangTypeConversionExpr) attachment.expr;
BLangExpression expression = ((BLangInvocation) expr.expr).expr;
BLangExpression expression = getActualExpressionFromAnnotationAttachmentExpr(attachment.expr);
Assert.assertEquals(expression.getKind(), NodeKind.RECORD_LITERAL_EXPR);

BLangRecordLiteral recordLiteral = (BLangRecordLiteral) expression;
Expand All @@ -259,6 +258,19 @@ private void assertAnnotationNameAndKeyValuePair(BLangAnnotationAttachment attac
Assert.assertEquals(((BLangLiteral) keyValuePair.getValue()).value, value);
}

private BLangExpression getActualExpressionFromAnnotationAttachmentExpr(BLangExpression expression) {
if (expression.getKind() == NodeKind.TYPE_CONVERSION_EXPR) {
BLangTypeConversionExpr expr = (BLangTypeConversionExpr) expression;
if (expr.getKind() == NodeKind.INVOCATION) {
return ((BLangInvocation) expr.expr).expr;
}
}
if (expression.getKind() == NodeKind.INVOCATION) {
return ((BLangInvocation) expression).expr;
}
return expression;
}

private String getKeyString(BLangRecordLiteral.BLangRecordKeyValueField keyValuePair) {
return keyValuePair.getKey() instanceof BLangSimpleVarRef ?
((BLangSimpleVarRef) keyValuePair.key.expr).variableName.value :
Expand All @@ -283,9 +295,10 @@ public void testAnnotsWithConstLists() {
Assert.assertEquals(attachments.size(), 1);
BLangAnnotationAttachment attachment = attachments.get(0);
Assert.assertEquals(attachment.annotationName.getValue(), "v1");
Assert.assertEquals(attachment.expr.getKind(), NodeKind.RECORD_LITERAL_EXPR);
BLangExpression annotationExpression = getActualExpressionFromAnnotationAttachmentExpr(attachment.expr);
Assert.assertEquals(annotationExpression.getKind(), NodeKind.RECORD_LITERAL_EXPR);

BLangRecordLiteral recordLiteral = (BLangRecordLiteral) attachment.expr;
BLangRecordLiteral recordLiteral = (BLangRecordLiteral) annotationExpression;
Assert.assertEquals(recordLiteral.getFields().size(), 2);

BLangRecordLiteral.BLangRecordKeyValueField keyValuePair =
Expand Down

0 comments on commit 22b0b95

Please sign in to comment.