use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testFunctionWithArrays.
// public void FIXME_testLatinChars() throws Exception {
// final DrlParser parser = new DrlParser();
// final Reader drl = new InputStreamReader( this.getClass().getResourceAsStream( "latin-sample.dslr" ) );
// final Reader dsl = new InputStreamReader( this.getClass().getResourceAsStream( "latin.dsl" ) );
//
// final PackageDescr pkg = parser.parse( drl,
// dsl );
//
// // MN: will get some errors due to the char encoding on my FC5 install
// // others who use the right encoding may not see this, feel free to
// // uncomment
// // the following assertion.
// assertFalse( parser.hasErrors() );
//
// assertEquals( "br.com.auster.drools.sample",
// pkg.getName() );
// assertEquals( 1,
// pkg.getRules().size() );
//
// }
//
@Test
public void testFunctionWithArrays() throws Exception {
PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "function_arrays.drl");
assertEquals("foo", pkg.getName());
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEqualsIgnoreWhitespace("yourFunction(new String[3] {\"a\",\"b\",\"c\"});", (String) rule.getConsequence());
final FunctionDescr func = (FunctionDescr) pkg.getFunctions().get(0);
assertEquals("String[]", func.getReturnType());
assertEquals("args[]", func.getParameterNames().get(0));
assertEquals("String", func.getParameterTypes().get(0));
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testDurationExpression.
@Test
public void testDurationExpression() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_duration_expression.drl");
assertEquals("simple_rule", rule.getName());
assertEqualsIgnoreWhitespace("bar();", (String) rule.getConsequence());
final Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(2, attrs.size());
AttributeDescr at = (AttributeDescr) attrs.get("duration");
assertEquals("duration", at.getName());
assertEquals("1h30m", at.getValue());
at = (AttributeDescr) attrs.get("lock-on-active");
assertEquals("lock-on-active", at.getName());
assertEquals("true", at.getValue());
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testEscapedStrings.
@Test
public void testEscapedStrings() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "escaped-string.drl");
assertNotNull(rule);
assertEquals("test_Quotes", rule.getName());
final String expected = "String s = \"\\\"\\n\\t\\\\\";";
assertEqualsIgnoreWhitespace(expected, (String) rule.getConsequence());
}
use of org.drools.drl.ast.descr.RuleDescr 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.drl.ast.descr.RuleDescr 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();
}
Aggregations