Skip to content

Commit

Permalink
[incubator-kie-drools-5938] [new-parser] Tests using wrong duration a… (
Browse files Browse the repository at this point in the history
apache#5969)

* [incubator-kie-drools-5938] [new-parser] Tests using wrong duration attribute format

* - Use explicit test value
  • Loading branch information
tkobayas committed Jun 11, 2024
1 parent 65cff36 commit 191ffce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5216,4 +5216,20 @@ void doubleAmpersandInfixAndInAccumulate() {
assertThat(accumulateFunction.getFunction()).isEqualTo("average");
assertThat(accumulateFunction.getParams()).containsExactly("$a + $b");
}

@Test
void durationChunk() {
final String text =
"rule R\n" +
" duration (wrong input) \n" +
"when\n" +
"then\n" +
"end";
RuleDescr rule = parseAndGetFirstRuleDescr(text);
assertThat(rule.getAttributes()).containsKey("duration");
assertThat(rule.getAttributes().get("duration").getType()).isEqualTo(AttributeDescr.Type.EXPRESSION);

// At the moment, the parser accepts any input and let the compile phase validate it.
assertThat(rule.getAttributes().get("duration").getValue()).isEqualTo("wrong input");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ attribute : name=( 'salience' | 'enabled' ) conditionalAttributeValue #expressio
| name=( 'agenda-group' | 'activation-group' | 'ruleflow-group' | 'date-effective' | 'date-expires' | 'dialect' ) DRL_STRING_LITERAL #stringAttribute
| name='calendars' DRL_STRING_LITERAL ( COMMA DRL_STRING_LITERAL )* #stringListAttribute
| name='timer' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
| name='duration' ( DECIMAL_LITERAL | TIME_INTERVAL | LPAREN TIME_INTERVAL RPAREN ) #durationAttribute
| name='duration' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
;

conditionalAttributeValue : ( LPAREN conditionalExpression RPAREN | conditionalExpression ) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,21 +514,6 @@ public AttributeDescr visitIntOrChunkAttribute(DRLParser.IntOrChunkAttributeCont
return attributeDescr;
}

@Override
public AttributeDescr visitDurationAttribute(DRLParser.DurationAttributeContext ctx) {
AttributeDescr attributeDescr = BaseDescrFactory.builder(new AttributeDescr(ctx.name.getText()))
.withParserRuleContext(ctx)
.build();
if (ctx.DECIMAL_LITERAL() != null) {
attributeDescr.setValue(ctx.DECIMAL_LITERAL().getText());
attributeDescr.setType(AttributeDescr.Type.NUMBER);
} else {
attributeDescr.setValue(unescapeJava(safeStripStringDelimiters(ctx.TIME_INTERVAL().getText())));
attributeDescr.setType(AttributeDescr.Type.EXPRESSION);
}
return attributeDescr;
}

/**
* entry point for LHS
*/
Expand Down

0 comments on commit 191ffce

Please sign in to comment.