use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testEvalMultiple.
@Test
public void testEvalMultiple() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "eval_multiple.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(4, rule.getLhs().getDescrs().size());
final EvalDescr eval = (EvalDescr) rule.getLhs().getDescrs().get(0);
assertEqualsIgnoreWhitespace("abc(\"foo\") + 5", (String) eval.getContent());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Foo", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testEval.
@Test
public void testEval() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "eval_parsing.drl");
assertEquals("org.drools.compiler", pkg.getName());
assertEquals(1, pkg.getRules().size());
final RuleDescr rule1 = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule1.getLhs().getDescrs().size());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testLineNumberInAST.
@Test
public void testLineNumberInAST() throws Exception {
// also see testSimpleExpander to see how this works with an expander
// (should be the same).
final RuleDescr rule = (RuleDescr) parseResource("rule", "simple_rule.drl");
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
assertEquals(22, rule.getConsequenceLine());
assertEquals(2, rule.getConsequencePattern());
final AndDescr lhs = rule.getLhs();
assertNotNull(lhs);
assertEquals(3, lhs.getDescrs().size());
// Check first pattern
final PatternDescr first = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("foo3", first.getIdentifier());
assertEquals("Bar", first.getObjectType());
assertEquals(1, first.getConstraint().getDescrs().size());
// Check second pattern
final PatternDescr second = (PatternDescr) lhs.getDescrs().get(1);
assertEquals("foo4", second.getIdentifier());
assertEquals("Bar", second.getObjectType());
final PatternDescr third = (PatternDescr) lhs.getDescrs().get(2);
assertEquals("Baz", third.getObjectType());
assertEquals(19, first.getLine());
assertEquals(20, second.getLine());
assertEquals(21, third.getLine());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhs.
@Test
public void testRuleParseLhs() throws Exception {
final String text = "rule X when Person(age < 42, location==\"atlanta\") \nor\nPerson(name==\"bob\") then end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
assertEquals(2, ((OrDescr) lhs.getDescrs().get(0)).getDescrs().size());
}
use of org.drools.compiler.lang.descr.RuleDescr 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());
}
Aggregations