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 9fcc046
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;
Expand All @@ -38,7 +37,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.kie.internal.builder.conf.LanguageLevelOption;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
Expand Down Expand Up @@ -175,7 +173,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
Expand Up @@ -24,13 +24,12 @@
import org.drools.drl.ast.descr.BindingDescr;
import org.drools.drl.ast.descr.ConstraintConnectiveDescr;
import org.drools.drl.parser.DrlExprParser;
import org.drools.drl.parser.DrlExprParserFactory;
import org.drools.mvel.evaluators.MatchesEvaluatorsDefinition;
import org.drools.mvel.evaluators.SetEvaluatorsDefinition;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.kie.internal.builder.conf.LanguageLevelOption;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;

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

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

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
void dump() {
String input = "price > 10 && < 20 || == $val || == 30";
Expand Down Expand Up @@ -147,6 +147,7 @@ void dumpWithDateAttr() {
assertThat(result).isEqualTo(expected);
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@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 +221,7 @@ void dumpBindings4() {
assertThat(result).isEqualTo(expected);
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
void dumpBindingsWithRestriction() {
String input = "$x : age > 10 && < 20 || > 30";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
import org.drools.drl.parser.impl.Operator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -95,14 +96,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 +874,7 @@ void simpleRuleWithBindings() {
assertThat((String) rule.getConsequence()).isEqualToIgnoringWhitespace("if ( a == b ) { " + " assert( foo3 );" + "} else {" + " retract( foo4 );" + "}" + " System.out.println( a4 );");
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
void multipleRestrictionsConstraint() {
RuleDescr rule = parseAndGetFirstRuleDescrFromFile("restrictions_test.drl");
Expand Down Expand Up @@ -2452,7 +2446,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 +2480,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 +2530,7 @@ void constraintOrConnective() {
assertThat(fcd.getExpression()).isEqualToIgnoringWhitespace("age < 42 || location==\"atlanta\"");
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
void restrictions() {
final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
Expand Down Expand Up @@ -2987,7 +2982,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 +3891,7 @@ void constraintOperators(String constraint) {
assertThat(exprConstraintDescr.getExpression()).isEqualToIgnoringWhitespace(constraint);
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@ParameterizedTest
@ValueSource(strings = {
"country matches \"[a-z]*\" || matches \"[A-Z]*\"",
Expand Down Expand Up @@ -4419,7 +4415,7 @@ void traitExtendsMultiple() {
.containsExactlyInAnyOrder("com.sample.ParentTrait", "UncleTrait", "org.test.GrandParentTrait");
}

@EnabledIf("isOldParser")
@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
void pluggableEvaluatorOldParser() {
final String source = "package org.drools\n" +
Expand All @@ -4440,7 +4436,7 @@ void pluggableEvaluatorOldParser() {
.containsExactly("$c : core", "this not isA t.x.E.class", "this isA t.x.D.class");
}

@EnabledIf("isNewParser")
@EnabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
void pluggableEvaluatorNewParser() {
final String source = "package org.drools\n" +
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 @@ -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.DisabledIfSystemProperty;
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");
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@ParameterizedTest
@MethodSource("parameters")
public void testOrWithFixedLeftOperand(RUN_TYPE runType) {
Expand Down Expand Up @@ -2095,6 +2097,7 @@ public void testNumericLimits(RUN_TYPE runType) {

}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@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.DisabledIfSystemProperty;
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;

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
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.DisabledIfSystemProperty;
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);
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@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);
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@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.DisabledIfSystemProperty;
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");
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@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
Loading

0 comments on commit 9fcc046

Please sign in to comment.