-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[incubator-kie-drools-5792] [new-parser] improve drools-drl-parser-tests #5855
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
import org.drools.drl.ast.descr.ConstraintConnectiveDescr; | ||
import org.drools.drl.ast.descr.RelationalExprDescr; | ||
import org.drools.drl.parser.DrlExprParser; | ||
import org.drools.drl.parser.DrlExprParserFactory; | ||
import org.drools.drl.parser.DrlParser; | ||
import org.drools.drl.parser.DroolsParserException; | ||
import org.drools.drl.parser.impl.Operator; | ||
import org.junit.jupiter.api.AfterEach; | ||
|
@@ -49,17 +51,17 @@ public class DRLExprParserTest { | |
DrlExprParser parser; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
this.parser = new Drl6ExprParserAntlr4(LanguageLevelOption.DRL6); | ||
public void setUp() { | ||
this.parser = DrlExprParserFactory.getDrlExprParser(LanguageLevelOption.DRL6); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() throws Exception { | ||
public void tearDown() { | ||
this.parser = null; | ||
} | ||
|
||
@Test | ||
public void testSimpleExpression() throws Exception { | ||
public void testSimpleExpression() { | ||
String source = "a > b"; | ||
ConstraintConnectiveDescr result = parser.parse( source ); | ||
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse(); | ||
|
@@ -387,13 +389,26 @@ public void testMismatchedInput() { | |
assertThat(parser.hasErrors()).isTrue(); | ||
assertThat(parser.getErrors()).hasSize(1); | ||
DroolsParserException exception = parser.getErrors().get(0); | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 102"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(1); | ||
assertThat(exception.getOffset()).isEqualTo(1); | ||
assertThat(exception.getMessage()) | ||
.startsWithIgnoringCase("[ERR 102] Line 1:1 mismatched input '<EOF>' expecting ") | ||
.contains("TIME_INTERVAL", "DRL_STRING_LITERAL", "?/", "boolean", "byte", "char", "double", "float", "int", "long", "new", "short", "super", "DECIMAL_LITERAL", "HEX_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL", "STRING_LITERAL", "null", "(", "[", ".", "<", "!", "~", "++", "--", "+", "-", "*", "/", "IDENTIFIER"); | ||
|
||
// Backward Compatibility Notes: | ||
// Antlr4 gives a different error code/message from antlr3 for this case. | ||
// Backward compatibility doesn't seem to be required in this case. | ||
Comment on lines
+393
to
+395
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I leave A) The difference comes from Antrl3 and 4, so we cannot change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please give us one or more examples of B)? In which cases the old parser is wrong? This would help us to focus this discussion and decide if it makes sense to pollute the new parser to accommodate the weird behaviors of the old one (I hope not). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mariofusco Sure, commented below. Probably it's easier to look in https://github.com/apache/incubator-kie-drools/pull/5855/files |
||
if (DrlParser.ANTLR4_PARSER_ENABLED) { | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 102"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(1); | ||
assertThat(exception.getOffset()).isEqualTo(1); | ||
assertThat(exception.getMessage()) | ||
.startsWithIgnoringCase("[ERR 102] Line 1:1 mismatched input '<EOF>' expecting ") | ||
.contains("TIME_INTERVAL", "DRL_STRING_LITERAL", "?/", "boolean", "byte", "char", "double", "float", "int", "long", "new", "short", "super", "DECIMAL_LITERAL", "HEX_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL", "STRING_LITERAL", "null", "(", "[", ".", "<", "!", "~", "++", "--", "+", "-", "*", "/", "IDENTIFIER"); | ||
} else { | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 101"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(1); | ||
assertThat(exception.getOffset()).isEqualTo(1); | ||
assertThat(exception.getMessage()) | ||
.isEqualToIgnoringCase("[ERR 101] Line 1:1 no viable alternative at input '<eof>'"); | ||
} | ||
} | ||
|
||
@Test | ||
|
@@ -403,26 +418,48 @@ public void testExtraneousInput() { | |
assertThat(parser.hasErrors()).isTrue(); | ||
assertThat(parser.getErrors()).hasSize(1); | ||
DroolsParserException exception = parser.getErrors().get(0); | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 109"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(3); | ||
assertThat(exception.getOffset()).isEqualTo(3); | ||
assertThat(exception.getMessage()) | ||
.startsWithIgnoringCase("[ERR 109] Line 1:3 extraneous input ';' expecting ") | ||
.contains("TIME_INTERVAL", "DRL_STRING_LITERAL", "?/", "boolean", "byte", "char", "double", "float", "int", "long", "new", "short", "super", "DECIMAL_LITERAL", "HEX_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL", "STRING_LITERAL", "null", "(", "[", ".", "<", "!", "~", "++", "--", "+", "-", "*", "/", "IDENTIFIER"); | ||
|
||
// Backward Compatibility Notes: | ||
// Antlr4 gives a different error code/message from antlr3 for this case. | ||
// Backward compatibility doesn't seem to be required in this case. | ||
if (DrlParser.ANTLR4_PARSER_ENABLED) { | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 109"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(3); | ||
assertThat(exception.getOffset()).isEqualTo(3); | ||
assertThat(exception.getMessage()) | ||
.startsWithIgnoringCase("[ERR 109] Line 1:3 extraneous input ';' expecting ") | ||
.contains("TIME_INTERVAL", "DRL_STRING_LITERAL", "?/", "boolean", "byte", "char", "double", "float", "int", "long", "new", "short", "super", "DECIMAL_LITERAL", "HEX_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL", "STRING_LITERAL", "null", "(", "[", ".", "<", "!", "~", "++", "--", "+", "-", "*", "/", "IDENTIFIER"); | ||
} else { | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 101"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(3); | ||
assertThat(exception.getOffset()).isEqualTo(3); | ||
assertThat(exception.getMessage()) | ||
.isEqualToIgnoringCase("[ERR 101] Line 1:3 no viable alternative at input ';'"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNoViableAlt() { | ||
String source = "x.int"; | ||
parser.parse(source); | ||
assertThat(parser.hasErrors()).isTrue(); | ||
assertThat(parser.getErrors()).hasSize(1); | ||
DroolsParserException exception = parser.getErrors().get(0); | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 101"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(2); | ||
assertThat(exception.getOffset()).isEqualTo(2); | ||
assertThat(exception.getMessage()) | ||
.isEqualToIgnoringCase("[ERR 101] Line 1:2 no viable alternative at input '.int'"); | ||
|
||
// Backward Compatibility Notes: | ||
// Old expr parser (DRL6Expressions) allows this expression because it's too tolerant (fail at runtime anyway). | ||
// Backward compatibility doesn't seem to be required in this case. (But we may align with the old tolerant behavior.) | ||
if (DrlParser.ANTLR4_PARSER_ENABLED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Old parser allows |
||
assertThat(parser.hasErrors()).isTrue(); | ||
assertThat(parser.getErrors()).hasSize(1); | ||
DroolsParserException exception = parser.getErrors().get(0); | ||
assertThat(exception.getErrorCode()).isEqualTo("ERR 101"); | ||
assertThat(exception.getLineNumber()).isEqualTo(1); | ||
assertThat(exception.getColumn()).isEqualTo(2); | ||
assertThat(exception.getOffset()).isEqualTo(2); | ||
assertThat(exception.getMessage()) | ||
.isEqualToIgnoringCase("[ERR 101] Line 1:2 no viable alternative at input '.int'"); | ||
} else { | ||
assertThat(parser.hasErrors()).isFalse(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we can run old and new parser for the
drools-drl-parser-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand. Does this run the new tests (that we keep on adding to on this feature branch) against both the new and the old parser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurloc Yes, in
drools-drl-parser-tests
, surefire runs twice withdrools.drl.antlr4.parser.enabled
=true
andfalse
. You would see: