use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testBoundVariables.
@Test
public void testBoundVariables() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "bindings.drl");
final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
final AndDescr lhs = ruleDescr.getLhs();
assertEquals(2, lhs.getDescrs().size());
final PatternDescr cheese = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("Cheese", cheese.getObjectType());
assertEquals(1, cheese.getDescrs().size());
ExprConstraintDescr fieldBinding = (ExprConstraintDescr) cheese.getDescrs().get(0);
assertEquals("$type : type == \"stilton\"", fieldBinding.getExpression());
final PatternDescr person = (PatternDescr) lhs.getDescrs().get(1);
assertEquals(2, person.getDescrs().size());
fieldBinding = (ExprConstraintDescr) person.getDescrs().get(0);
assertEquals("$name : name == \"bob\"", fieldBinding.getExpression());
ExprConstraintDescr fld = (ExprConstraintDescr) person.getDescrs().get(1);
assertEquals("likes == $type", fld.getExpression());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class AndDescrTest method testAddUnboundPatternsEtc.
@Test
public void testAddUnboundPatternsEtc() {
final AndDescr and = new AndDescr();
and.addDescr(new NotDescr());
and.addDescr(new PatternDescr("Foo"));
and.addDescr(new NotDescr());
assertEquals(3, and.getDescrs().size());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testBracketsPrecedence.
/**
*/
@Test
public void testBracketsPrecedence() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "brackets_precedence.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
final AndDescr rootAnd = (AndDescr) rule.getLhs();
assertEquals(2, rootAnd.getDescrs().size());
final OrDescr leftOr = (OrDescr) rootAnd.getDescrs().get(0);
assertEquals(2, leftOr.getDescrs().size());
final NotDescr not = (NotDescr) leftOr.getDescrs().get(0);
final PatternDescr foo1 = (PatternDescr) not.getDescrs().get(0);
assertEquals("Foo", foo1.getObjectType());
final PatternDescr foo2 = (PatternDescr) leftOr.getDescrs().get(1);
assertEquals("Foo", foo2.getObjectType());
final OrDescr rightOr = (OrDescr) rootAnd.getDescrs().get(1);
assertEquals(2, rightOr.getDescrs().size());
final PatternDescr shoes = (PatternDescr) rightOr.getDescrs().get(0);
assertEquals("Shoes", shoes.getObjectType());
final PatternDescr butt = (PatternDescr) rightOr.getDescrs().get(1);
assertEquals("Butt", butt.getObjectType());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testNotNode.
@Test
public void testNotNode() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_not.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
final AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
final NotDescr not = (NotDescr) lhs.getDescrs().get(0);
assertEquals(1, not.getDescrs().size());
final PatternDescr pattern = (PatternDescr) not.getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
assertEquals(1, pattern.getConstraint().getDescrs().size());
final AndDescr and = (AndDescr) pattern.getConstraint();
final ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
assertEquals("type == \"stilton\"", fld.getExpression());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testStringEscapes.
@Test
public void testStringEscapes() throws Exception {
String source = "package com.sample rule test when Cheese( type matches \"\\..*\\\\.\" ) then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertEquals("com.sample", pkg.getName());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("test", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
AndDescr constraint = (AndDescr) pattern.getConstraint();
assertEquals(1, constraint.getDescrs().size());
assertEquals("type matches \"\\..*\\\\.\"", constraint.getDescrs().get(0).toString());
}
Aggregations