yurloc commented on code in PR #5778:
URL: 
https://github.com/apache/incubator-kie-drools/pull/5778#discussion_r1521568679


##########
drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/DRLExprParserTest.java:
##########
@@ -325,4 +326,50 @@ public void testKeyword_instanceof() {
         assertThat(left.getExpression()).isEqualTo("a");
         assertThat(right.getExpression()).isEqualTo("A");
     }
+
+    @Test
+    public void testMismatchedInput() {
+        String source = "+";
+        parser.parse(source);
+        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");
+    }
+
+    @Test
+    public void testExtraneousInput() {
+        String source = "a +; b";
+        parser.parse(source);
+        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");
+    }
+    @Test
+    public void testNoViableAlt() {
+        String source = "a~a";

Review Comment:
   I confess that I discovered this by chance. I'm not sure why this causes the 
`NoViableAltException` but I couldn't come up with anything better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to