From 191ffce86f898f6c592abf5d4f8ed52c04a99bfc Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Mon, 27 May 2024 10:29:29 +0900 Subject: [PATCH] =?UTF-8?q?[incubator-kie-drools-5938]=20[new-parser]=20Te?= =?UTF-8?q?sts=20using=20wrong=20duration=20a=E2=80=A6=20(#5969)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [incubator-kie-drools-5938] [new-parser] Tests using wrong duration attribute format * - Use explicit test value --- .../drl/parser/antlr4/MiscDRLParserTest.java | 16 ++++++++++++++++ .../org/drools/drl/parser/antlr4/DRLParser.g4 | 2 +- .../drools/drl/parser/antlr4/DRLVisitorImpl.java | 15 --------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java index e81bfb21f0c..ab2f7070606 100644 --- a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java +++ b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java @@ -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"); + } } diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 index 251f73f2508..cf1afb97862 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 @@ -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 ) ; diff --git a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java index 4e6192ecad6..39aa5e930e8 100644 --- a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java +++ b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java @@ -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 */