use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testSoundsLike.
@Test
public void testSoundsLike() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "soundslike_operator.drl");
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
PatternDescr pat = (PatternDescr) rule.getLhs().getDescrs().get(0);
pat.getConstraint();
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testFromWithTernaryFollowedByQuery.
@Test
public void testFromWithTernaryFollowedByQuery() throws Exception {
// the 'from' expression requires a ";" to disambiguate the "?"
// prefix for queries from the ternary operator "? :"
final String text = "rule X when Cheese() from (isFull ? $cheesery : $market) ?person( \"Mark\", 42; ) then end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
assertEquals("from (isFull ? $cheesery : $market)", pattern.getSource().getText());
assertFalse(pattern.isQuery());
pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("person", pattern.getObjectType());
assertTrue(pattern.isQuery());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testOrCE.
@Test
public void testOrCE() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_ce.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
final PatternDescr person = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Person", person.getObjectType());
assertEquals("$p", person.getIdentifier());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(1);
assertEquals(2, or.getDescrs().size());
final PatternDescr cheese1 = (PatternDescr) or.getDescrs().get(0);
assertEquals("Cheese", cheese1.getObjectType());
assertEquals("$c", cheese1.getIdentifier());
final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get(1);
assertEquals("Cheese", cheese2.getObjectType());
assertNull(cheese2.getIdentifier());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testIsQuery.
@Test
public void testIsQuery() throws Exception {
final String text = "rule X when ?person( \"Mark\", 42; ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertTrue(pattern.isQuery());
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.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testBindingCompositeWithMethods.
@Test
public void testBindingCompositeWithMethods() throws Exception {
final String text = "rule X when Person( $name : name.toUpperCase() == \"Bob\" || $loc : location[0].city == \"Montreal\" ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals("Person", pattern.getObjectType());
assertFalse(pattern.isUnification());
// assertEquals( 2,
// pattern.getDescrs().size() );
// BindingDescr bindingDescr = pattern.getDescrs().get( 0 );
// assertEquals( "$name",
// bindingDescr.getVariable() );
// assertEquals( "name.toUpperCase()",
// bindingDescr.getExpression() );
// assertFalse( bindingDescr.isUnification() );
//
// bindingDescr = pattern.getDescrs().get( 1 );
// assertEquals( "$loc",
// bindingDescr.getVariable() );
// assertEquals( "location[0].city",
// bindingDescr.getExpression() );
// assertFalse( bindingDescr.isUnification() );
// embedded bindings are extracted at compile time
List<?> constraints = pattern.getDescrs();
assertEquals(1, constraints.size());
assertEquals("$name : name.toUpperCase() == \"Bob\" || $loc : location[0].city == \"Montreal\"", ((ExprConstraintDescr) constraints.get(0)).getExpression());
}
Aggregations