Search in sources :

Example 71 with RuleDescr

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));
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) FunctionDescr(org.drools.drl.ast.descr.FunctionDescr) Test(org.junit.Test)

Example 72 with RuleDescr

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());
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Example 73 with RuleDescr

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());
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) Test(org.junit.Test)

Example 74 with RuleDescr

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());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 75 with RuleDescr

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();
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Aggregations

RuleDescr (org.drools.drl.ast.descr.RuleDescr)191 Test (org.junit.Test)147 PackageDescr (org.drools.drl.ast.descr.PackageDescr)105 PatternDescr (org.drools.drl.ast.descr.PatternDescr)104 AndDescr (org.drools.drl.ast.descr.AndDescr)55 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)37 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)33 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)27 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)27 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)24 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)17 Cheese (org.drools.mvel.compiler.Cheese)16 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)15 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)14 OrDescr (org.drools.drl.ast.descr.OrDescr)14 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)13 Pattern (org.drools.core.rule.Pattern)13 List (java.util.List)12 BindingDescr (org.drools.drl.ast.descr.BindingDescr)11 FromDescr (org.drools.drl.ast.descr.FromDescr)11