Skip to content

Commit

Permalink
Enable time literal (apache#5800)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurloc authored and tkobayas committed Oct 2, 2024
1 parent 5001305 commit bcfe8fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3749,9 +3749,12 @@ void lhsPatternAnnotation() {
"then\n" +
"end\n";
PackageDescr packageDescr = parser.parse(text);
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse();

RuleDescr ruleDescr = packageDescr.getRules().get(0);
PatternDescr patternDescr = (PatternDescr) ruleDescr.getLhs().getDescrs().get(0);
AnnotationDescr annotationDescr = patternDescr.getAnnotations().iterator().next();

assertThat(annotationDescr.getName()).isEqualTo("watch");
assertThat(annotationDescr.getSingleValueAsString()).isEqualTo("!*, age");
}
Expand All @@ -3770,4 +3773,24 @@ void fromNew() {
FromDescr fromDescr = (FromDescr) patternDescr.getSource();
assertThat(fromDescr.getDataSource().toString()).isEqualTo("new Person(\"John\", 30)");
}

@Test
public void expiresWithTimeLiteralValue() {
String text = "package org.drools\n" +
"declare StockFact\n" +
" @role( value = event )\n" +
" @expires( value = 2s, policy = TIME_SOFT )\n" +
"end";

PackageDescr packageDescr = parser.parse(text);
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse();

AnnotationDescr annotationDescr = packageDescr
.getTypeDeclarations().get(0)
.getAnnotation("expires");

assertThat(annotationDescr.getSingleValueAsString()).isEqualTo("2s");
assertThat(annotationDescr.getValueAsString("value")).isEqualTo("2s");
assertThat(annotationDescr.getValueAsString("policy")).isEqualTo("TIME_SOFT");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ drlLiteral
| BOOL_LITERAL
| NULL_LITERAL
| TEXT_BLOCK // Java17
| TIME_INTERVAL
;

inlineListExpression
Expand Down

0 comments on commit bcfe8fe

Please sign in to comment.