use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testMemberof.
@Test
public void testMemberof() throws Exception {
final String text = "rule X when Country( $cities : city )\nPerson( city memberOf $cities )\n then end";
AndDescr descrs = ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(2, descrs.getDescrs().size());
PatternDescr pat = (PatternDescr) descrs.getDescrs().get(1);
ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
assertEquals("city memberOf $cities", fieldConstr.getExpression());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testNullConstraints.
@Test
public void testNullConstraints() throws Exception {
final String text = "rule X when Person( name == null ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(1, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("name == null", fcd.getExpression());
assertEquals(0, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.NAMED, fcd.getType());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testPositionalConstraintsOnly.
@Test
public void testPositionalConstraintsOnly() throws Exception {
final String text = "rule X when Person( \"Mark\", 42; ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(2, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("\"Mark\"", fcd.getExpression());
assertEquals(0, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
fcd = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("42", fcd.getExpression());
assertEquals(1, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testRestrictions.
@Test
public void testRestrictions() throws Exception {
final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
AndDescr descrs = (AndDescr) ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(1, descrs.getDescrs().size());
PatternDescr pat = (PatternDescr) descrs.getDescrs().get(0);
ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
assertEquals("bar > 1 || == 1", fieldConstr.getExpression());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testBigLiterals.
@Test
public void testBigLiterals() throws Exception {
final String text = "rule X when Primitives( bigInteger == (10I), " + " bigDecimal == (10B), " + " bigInteger < 50I, " + " bigDecimal < 50B ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(4, pattern.getDescrs().size());
ExprConstraintDescr ecd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("bigInteger == (10I)", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("bigDecimal == (10B)", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(2);
assertEquals("bigInteger < 50I", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(3);
assertEquals("bigDecimal < 50B", ecd.getExpression());
}
Aggregations