use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhsWithStringQuotes2.
@Test
public void testRuleParseLhsWithStringQuotes2() throws Exception {
final String text = "rule X when Cheese( $x: type, type == \"s\\tti\\\"lto\\nn\" ) then end\n";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
ExprConstraintDescr constr = (ExprConstraintDescr) ((PatternDescr) lhs.getDescrs().get(0)).getDescrs().get(1);
assertEquals("type == \"s\\tti\\\"lto\\nn\"", constr.getText());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhsWithStringQuotes.
@Test
public void testRuleParseLhsWithStringQuotes() throws Exception {
final String text = "rule X when Person( location==\"atlanta\\\"\") then end\n";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
ExprConstraintDescr constr = (ExprConstraintDescr) ((PatternDescr) lhs.getDescrs().get(0)).getDescrs().get(0);
assertEquals("location==\"atlanta\\\"\"", constr.getText());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testBasicBinding.
// @Test public void testExpanderUnExpandableErrorLines() throws Exception {
//
// //stubb expander
// final ExpanderResolver res = new ExpanderResolver() {
// public Expander get(String name,
// String config) {
// return new Expander() {
// public String expand(String scope,
// String pattern) {
// if ( pattern.startsWith( "Good" ) ) {
// return pattern;
// } else {
// throw new IllegalArgumentException( "whoops" );
// }
//
// }
// };
// }
// };
//
// final DRLParser parser = parseResource( "expander_line_errors.dslr" );
// parser.setExpanderResolver( res );
// parser.compilationUnit();
// assertTrue( parser.hasErrors() );
//
// final List messages = parser.getErrorMessages();
// assertEquals( messages.size(),
// parser.getErrors().size() );
//
// assertEquals( 4,
// parser.getErrors().size() );
// assertEquals( ExpanderException.class,
// parser.getErrors().get( 0 ).getClass() );
// assertEquals( 8,
// ((RecognitionException) parser.getErrors().get( 0 )).line );
// assertEquals( 10,
// ((RecognitionException) parser.getErrors().get( 1 )).line );
// assertEquals( 12,
// ((RecognitionException) parser.getErrors().get( 2 )).line );
// assertEquals( 13,
// ((RecognitionException) parser.getErrors().get( 3 )).line );
//
// final PackageDescr pack = parser.getPackageDescr();
// assertNotNull( pack );
//
// final ExpanderException ex = (ExpanderException) parser.getErrors().get(
// 0 );
// assertTrue( ex.getMessage().indexOf( "whoops" ) > -1 );
//
// }
@Test
public void testBasicBinding() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "basic_binding.drl");
final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
final AndDescr lhs = ruleDescr.getLhs();
assertEquals(1, lhs.getDescrs().size());
final PatternDescr cheese = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("Cheese", cheese.getObjectType());
assertEquals(1, cheese.getConstraint().getDescrs().size());
final ExprConstraintDescr fieldBinding = (ExprConstraintDescr) cheese.getDescrs().get(0);
assertEquals("$type:type", fieldBinding.getExpression());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testOrNesting.
@Test
public void testOrNesting() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_nesting.drl");
assertNotNull(pkg);
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("simple_rule", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
final PatternDescr first = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", first.getObjectType());
final AndDescr and = (AndDescr) or.getDescrs().get(1);
assertEquals(2, and.getDescrs().size());
final PatternDescr left = (PatternDescr) and.getDescrs().get(0);
assertEquals("Person", left.getObjectType());
final PatternDescr right = (PatternDescr) and.getDescrs().get(1);
assertEquals("Cheese", right.getObjectType());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleQuery.
@Test
public void testSimpleQuery() throws Exception {
final QueryDescr query = (QueryDescr) parseResource("query", "simple_query.drl");
assertNotNull(query);
assertEquals("simple_query", query.getName());
final AndDescr lhs = query.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());
AndDescr and = (AndDescr) first.getConstraint();
ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
assertNotNull(fld);
assertEquals("a==3", fld.getExpression());
// Check second pattern
final PatternDescr second = (PatternDescr) lhs.getDescrs().get(1);
assertEquals("foo4", second.getIdentifier());
assertEquals("Bar", second.getObjectType());
assertEquals(1, second.getDescrs().size());
// check it has field bindings.
final ExprConstraintDescr bindingDescr = (ExprConstraintDescr) second.getDescrs().get(0);
assertEquals("a4:a==4", bindingDescr.getExpression());
}
Aggregations