@Test public void testExtraLhsNewline() throws Exception { parseResource( "compilationUnit", "extra_lhs_newline.drl" ); }
@Test public void testEvalWithNewline() throws Exception { parseResource( "compilationUnit", "eval_with_newline.drl" ); }
@Test public void testLineNumberIncludingCommentsInRHS() throws Exception { PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "test_CommentLineNumbersInConsequence.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); final String rhs = (String) ((RuleDescr) pkg.getRules().get( 0 )).getConsequence(); String expected = "\\s*//woot$\\s*first$\\s*$\\s*//$\\s*$\\s*/\\* lala$\\s*$\\s*\\*/$\\s*second$\\s*"; assertTrue( Pattern.compile( expected, Pattern.DOTALL | Pattern.MULTILINE ).matcher( rhs ).matches() ); }
@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(); }
@Test public void testTypeWithMetaData() throws Exception { PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "type_with_meta.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); final List<TypeDeclarationDescr> declarations = pkg.getTypeDeclarations(); assertEquals( 3, declarations.size() ); }
@Test public void testQualifiedClassname() throws Exception { final PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "qualified_classname.drl" ); final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 ); final PatternDescr p = (PatternDescr) rule.getLhs().getDescrs().get( 0 ); assertEquals( "com.cheeseco.Cheese", p.getObjectType() ); }
@Test public void testKeywordCollisions() throws Exception { PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "eol_funny_business.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); assertEquals( 1, pkg.getRules().size() ); }
@Test public void testTernaryExpression() throws Exception { PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "ternary_expression.drl" ); final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 ); assertEquals( 1, pkg.getRules().size() ); assertEqualsIgnoreWhitespace( "if (speed > speedLimit ? true : false;) pullEmOver();", (String) rule.getConsequence() ); }
@Test public void testComment() throws Exception { final PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "comment.drl" ); assertNotNull( pkg ); assertEquals( "foo.bar", pkg.getName() ); }
@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() ); }
@Test public void testRuleNamesStartingWithNumbers() throws Exception { final PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "rule_names_number_prefix.drl" ); assertEquals( 2, pkg.getRules().size() ); assertEquals( "1. Do Stuff!", ((RuleDescr) pkg.getRules().get( 0 )).getName() ); assertEquals( "2. Do More Stuff!", ((RuleDescr) pkg.getRules().get( 1 )).getName() ); }
@Test public void testEndPosition() throws Exception { final PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "test_EndPosition.drl" ); final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 ); final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get( 0 ); assertEquals( 21, col.getLine() ); assertEquals( 23, col.getEndLine() ); }
@Test public void testFrom() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "from.drl" ); assertFalse( parser.getErrorMessages().toString(), parser.hasErrors() ); assertNotNull( rule ); assertEquals( "using_from", rule.getName() ); assertEquals( 9, rule.getLhs().getDescrs().size() ); }
@Test public void testSimpleMethodCallWithFrom() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "test_SimpleMethodCallWithFrom.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 ); final FromDescr from = (FromDescr) pattern.getSource(); final MVELExprDescr method = (MVELExprDescr) from.getDataSource(); assertEquals( "something.doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", method.getExpression() ); }
@Test public void testSimpleFunctionCallWithFrom() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "test_SimpleFunctionCallWithFrom.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 ); final FromDescr from = (FromDescr) pattern.getSource(); final MVELExprDescr func = (MVELExprDescr) from.getDataSource(); assertEquals( "doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", func.getExpression() ); }
@Test public void testSimpleAccessorWithFrom() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "test_SimpleAccessorWithFrom.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 ); final FromDescr from = (FromDescr) pattern.getSource(); final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource(); assertEquals( "something.doIt", accessor.getExpression() ); }
@Test public void testSimpleAccessorAndArgWithFrom() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "test_SimpleAccessorArgWithFrom.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 ); final FromDescr from = (FromDescr) pattern.getSource(); final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource(); assertEquals( "something.doIt[\"key\"]", accessor.getExpression() ); }
@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() ); }
@Test public void testQuotedStringNameRule() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "quoted_string_name_rule.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); assertNotNull( rule ); assertEquals( "quoted string name", rule.getName() ); assertNotNull( rule.getLhs() ); assertEquals( "", ((String) rule.getConsequence()).trim() ); }
@Test public void testEmptyRule() throws Exception { final RuleDescr rule = (RuleDescr) parseResource( "rule", "empty_rule.drl" ); assertNotNull( rule ); assertEquals( "empty", rule.getName() ); assertNotNull( rule.getLhs() ); assertNotNull( rule.getConsequence() ); }