Skip to content

Commit

Permalink
- drop half constraint
Browse files Browse the repository at this point in the history
- Disable drools-verifier test for DRL10
  • Loading branch information
tkobayas committed Jan 23, 2025
1 parent f9460d9 commit 86d1053
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -175,7 +176,7 @@ void bindingConstraint() {

@Test
void bindingWithRestrictions() {
String source = "$x : property > value && < 20";
String source = "$x : property > value && property < 20";
ConstraintConnectiveDescr result = parser.parse( source );
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.drools.drl.parser.antlr4;

import org.drools.drl.parser.DrlParser;

public class DRLParserTestBase {

protected static boolean isNewParser() {
return DrlParser.ANTLR4_PARSER_ENABLED;
}

protected static boolean isOldParser() {
return !DrlParser.ANTLR4_PARSER_ENABLED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.kie.internal.builder.conf.LanguageLevelOption;

import static org.assertj.core.api.Assertions.assertThat;

public class DescrDumperTest {
public class DescrDumperTest extends DRLParserTestBase {

private DescrDumper dumper;

Expand All @@ -47,6 +48,7 @@ void setUp() {
dumper = new DescrDumper();
}

@EnabledIf("isOldParser")
@Test
void dump() {
String input = "price > 10 && < 20 || == $val || == 30";
Expand Down Expand Up @@ -147,6 +149,7 @@ void dumpWithDateAttr() {
assertThat(result).isEqualTo(expected);
}

@EnabledIf("isOldParser")
@Test
void dumpComplex() {
String input = "a ( > 60 && < 70 ) || ( > 50 && < 55 ) && a3 == \"black\" || a == 40 && a3 == \"pink\" || a == 12 && a3 == \"yellow\" || a3 == \"blue\"";
Expand Down Expand Up @@ -220,6 +223,7 @@ void dumpBindings4() {
assertThat(result).isEqualTo(expected);
}

@EnabledIf("isOldParser")
@Test
void dumpBindingsWithRestriction() {
String input = "$x : age > 10 && < 20 || > 30";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
/*
* This test class is ported from org.drools.mvel.compiler.lang.RuleParserTest
*/
class MiscDRLParserTest {
class MiscDRLParserTest extends DRLParserTestBase {

private DrlParser parser;

Expand All @@ -95,14 +95,6 @@ void setUp() {
parser = ParserTestUtils.getParser();
}

private static boolean isNewParser() {
return DrlParser.ANTLR4_PARSER_ENABLED;
}

private static boolean isOldParser() {
return !DrlParser.ANTLR4_PARSER_ENABLED;
}

private String readResource(final String filename) {
Path path;
try {
Expand Down Expand Up @@ -881,6 +873,7 @@ void simpleRuleWithBindings() {
assertThat((String) rule.getConsequence()).isEqualToIgnoringWhitespace("if ( a == b ) { " + " assert( foo3 );" + "} else {" + " retract( foo4 );" + "}" + " System.out.println( a4 );");
}

@EnabledIf("isOldParser")
@Test
void multipleRestrictionsConstraint() {
RuleDescr rule = parseAndGetFirstRuleDescrFromFile("restrictions_test.drl");
Expand Down Expand Up @@ -2452,7 +2445,7 @@ void inOperator() {
assertThat(pattern.getConstraint().getDescrs()).hasSize(1);

ExprConstraintDescr fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertThat(fld.getExpression()).isEqualTo("age > 30 && < 40");
assertThat(fld.getExpression()).isEqualTo("age > 30 && age < 40");

// the second col, with 2 fields, the first with 2 restrictions, the
// second field with one
Expand Down Expand Up @@ -2486,7 +2479,7 @@ void notInOperator() {
assertThat(pattern.getConstraint().getDescrs()).hasSize(1);

ExprConstraintDescr fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertThat(fld.getExpression()).isEqualTo("age > 30 && < 40");
assertThat(fld.getExpression()).isEqualTo("age > 30 && age < 40");

// the second col, with 2 fields, the first with 2 restrictions, the
// second field with one
Expand Down Expand Up @@ -2536,6 +2529,7 @@ void constraintOrConnective() {
assertThat(fcd.getExpression()).isEqualToIgnoringWhitespace("age < 42 || location==\"atlanta\"");
}

@EnabledIf("isOldParser")
@Test
void restrictions() {
final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
Expand Down Expand Up @@ -2987,7 +2981,7 @@ void pluggableOperators() {
assertThat(eventE.getConstraint().getDescrs()).hasSize(1);

ExprConstraintDescr fcdE = (ExprConstraintDescr) eventE.getConstraint().getDescrs().get(0);
assertThat(fcdE.getExpression()).isEqualTo("this not before[1, 10] $b || after[1, 10] $c && this after[1, 5] $d");
assertThat(fcdE.getExpression()).isEqualTo("this not before[1, 10] $b || this after[1, 10] $c && this after[1, 5] $d");
}

@Test
Expand Down Expand Up @@ -3896,6 +3890,7 @@ void constraintOperators(String constraint) {
assertThat(exprConstraintDescr.getExpression()).isEqualToIgnoringWhitespace(constraint);
}

@EnabledIf("isOldParser")
@ParameterizedTest
@ValueSource(strings = {
"country matches \"[a-z]*\" || matches \"[A-Z]*\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
rule "AccumulateParserTest"
when
// below statement makes no sense, but is useful to test parsing recursiveness
$personList : ArrayList() from accumulate( Person( $age : age > 21 || < 10 ) from collect( People() from $town.getPeople() ),
$personList : ArrayList() from accumulate( Person( $age : age > 21 || age < 10 ) from collect( People() from $town.getPeople() ),
max( $age ) );
then
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

rule simple_rule
when
Person(age > 30 && < 40)
Person(age > 30 && age < 40)
Vehicle(type in ( "sedan", "wagon" ), age < 3)
then
consequence();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

rule simple_rule
when
Person(age > 30 && < 40)
Person(age > 30 && age < 40)
Vehicle(type not in ( "sedan", "wagon" ), age < 3)
then
consequence();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ when
$b : EventB( this after[1,10] $a || this not after[15,20] $a )
$c : EventC( this finishes $b )
$d : EventD( this not starts $a )
$e : EventE( this not before[1, 10] $b || after[1, 10] $c && this after[1, 5] $d )
$e : EventE( this not before[1, 10] $b || this after[1, 10] $c && this after[1, 5] $d )
then
end
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ locals [ BaseDescr lsd ]
$relationalExpression::lsd = $result;
}
}
( right=orRestriction
( right=singleRestriction
{ if( buildDescr ) {
$result = $right.result;
// TODO access lsd directly instead of through dynamic context here
Expand All @@ -581,36 +581,6 @@ locals [ BaseDescr lsd ]
)*
;

orRestriction returns [BaseDescr result]
: left=andRestriction { if( buildDescr ) { $result = $left.result; } }
( lop=OR args=fullAnnotation[null]? right=andRestriction
{ if( buildDescr ) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
descr.addOrMerge( $result );
descr.addOrMerge( $right.result );
if ( $ctx.args != null ) { descr.addAnnotation( $args.result ); }
$result = descr;
}
}
)*? EOF?
;

andRestriction returns [BaseDescr result]
: left=singleRestriction { if( buildDescr ) { $result = $left.result; } }
( lop=AND
{ if ( isNotEOF() ) helper.emit( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR ); }
args=fullAnnotation[null]?right=singleRestriction
{ if( buildDescr ) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newAnd();
descr.addOrMerge( $result );
descr.addOrMerge( $right.result );
if ( $ctx.args != null ) { descr.addAnnotation( $args.result ); }
$result = descr;
}
}
)*?
;

singleRestriction returns [BaseDescr result]
: op=operator
{ helper.emit( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT ); }
Expand All @@ -630,7 +600,6 @@ singleRestriction returns [BaseDescr result]
}
helper.emit( Location.LOCATION_LHS_INSIDE_CONDITION_END );
}
| LPAREN or=orRestriction RPAREN { $result = $or.result; }
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.drools.compiler.kie.builder.impl.InternalKieModule;
import org.drools.core.reteoo.EntryPointNode;
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.drl.parser.DrlParser;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.model.codegen.ExecutableModelProject;
import org.kie.api.KieServices;
Expand Down Expand Up @@ -212,4 +213,12 @@ protected ObjectTypeNode getObjectTypeNodeForClass( KieSession ksession, Class<?
}
return null;
}

protected static boolean isNewParser() {
return DrlParser.ANTLR4_PARSER_ENABLED;
}

protected static boolean isOldParser() {
return !DrlParser.ANTLR4_PARSER_ENABLED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.drools.model.codegen.execmodel.domain.Woman;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.definition.type.FactType;
Expand Down Expand Up @@ -145,6 +146,7 @@ public void testEqualityCheckOnNull(RUN_TYPE runType) {
assertThat(results.iterator().next().getValue()).isEqualTo("Mario");
}

@EnabledIf("isOldParser")
@ParameterizedTest
@MethodSource("parameters")
public void testOrWithFixedLeftOperand(RUN_TYPE runType) {
Expand Down Expand Up @@ -2095,6 +2097,7 @@ public void testNumericLimits(RUN_TYPE runType) {

}

@EnabledIf("isOldParser")
@ParameterizedTest
@MethodSource("parameters")
public void testMapAbbreviatedComparison(RUN_TYPE runType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

import org.drools.model.codegen.execmodel.domain.Address;
import org.drools.model.codegen.execmodel.domain.Person;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.runtime.KieSession;

import static org.assertj.core.api.Assertions.assertThat;

@EnabledIf("isOldParser")
public class HalfBinaryTest extends BaseModelTest {

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;

import org.drools.model.codegen.execmodel.domain.Person;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.builder.Message;
Expand Down Expand Up @@ -82,6 +83,7 @@ public void testStrNot(RUN_TYPE runType) {
assertThat(ksession.fireAllRules()).isEqualTo(2);
}

@EnabledIf("isOldParser")
@ParameterizedTest
@MethodSource("parameters")
public void testStrHalf(RUN_TYPE runType) {
Expand All @@ -100,6 +102,7 @@ public void testStrHalf(RUN_TYPE runType) {
assertThat(ksession.fireAllRules()).isEqualTo(3);
}

@EnabledIf("isOldParser")
@ParameterizedTest
@MethodSource("parameters")
public void testStrHalfOrAndAmpersand(RUN_TYPE runType) {
Expand All @@ -125,7 +128,7 @@ public void testRange(RUN_TYPE runType) {
"import " + Person.class.getCanonicalName() + "\n" +
"global java.util.List list\n" +
"rule R when\n" +
" Person( age > 30 && <= 40, $name : name )" +
" Person( age > 30 && age <= 40, $name : name )" +
"then\n" +
" list.add($name);" +
"end ";
Expand All @@ -152,7 +155,7 @@ public void testExcludedRange(RUN_TYPE runType) {
"import " + Person.class.getCanonicalName() + "\n" +
"global java.util.List list\n" +
"rule R when\n" +
" Person( age <= 30 || > 40, $name : name )" +
" Person( age <= 30 || age > 40, $name : name )" +
"then\n" +
" list.add($name);" +
"end ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.drools.model.codegen.execmodel.domain.MysteriousMan;
import org.drools.model.codegen.execmodel.domain.Person;
import org.drools.model.codegen.execmodel.domain.Result;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.runtime.KieSession;
Expand Down Expand Up @@ -253,6 +254,7 @@ public void testNullSafeDereferncingOnSecondField(RUN_TYPE runType) {
assertThat(results.get(0).getValue()).isEqualTo("John2");
}

@EnabledIf("isOldParser")
@ParameterizedTest
@MethodSource("parameters")
public void testNullSafeDereferncingWithOrHalfBinary(RUN_TYPE runType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<!--<logger name="org.drools.model.codegen.execmodel.generator.expressiontyper" level="debug"/>-->
<!-- <logger name="org.drools.model.codegen.execmodel" level="debug"/>-->
<logger name="org.drools.ancompiler" level="info"/>
<!-- <logger name="org.drools.drl.parser.DrlParser" level="debug"/>-->
<logger name="org.drools.drl.parser.DrlParser" level="debug"/>

<root level="warn">
<appender-ref ref="consoleAppender" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void testMapCoreAliasing( ) {
"\n" +
"rule Log \n" +
"when \n" +
" $p : PersonMap( name == \"john\", age > 10 && < 35 )\n" +
" $p : PersonMap( name == \"john\", age > 10 && age < 35 )\n" +
"then \n" +
" modify ( $p ) { \n" +
" setHeight( 184.0 ), \n" +
Expand Down
Loading

0 comments on commit 86d1053

Please sign in to comment.