[jboss-svn-commits] JBL Code SVN: r23863 - labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 13 10:27:33 EST 2008
Author: Rikkola
Date: 2008-11-13 10:27:33 -0500 (Thu, 13 Nov 2008)
New Revision: 23863
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java
Log:
Unit test that shows a DSL bug.
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java 2008-11-13 14:54:00 UTC (rev 23862)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java 2008-11-13 15:27:33 UTC (rev 23863)
@@ -107,10 +107,47 @@
}
+ /**
+ * From Toni to Edson.
+ * Right now this test fails because there is no RHS for the rule. It connects the "then" and "end" to "thenend".
+ */
+ public void FIXMEtestNoRHS() {
+ String file = "[then]TEST=System.out.println(\"DO_SOMETHING\");\n" + "[when]code {code1} occurs and sum of all digit not equal \\( {code2} \\+ {code3} \\)=AAAA( cd1 == {code1}, cd2 != ( {code2} + {code3} ))\n"
+ + "[when]code {code1} occurs=BBBB\n";
+ try {
+ final Reader reader = new StringReader( file );
+ this.file = new DSLMappingFile();
+
+ final boolean parsingResult = this.file.parseAndLoad( reader );
+ reader.close();
+
+ assertTrue( this.file.getErrors().toString(),
+ parsingResult );
+ assertTrue( this.file.getErrors().isEmpty() );
+
+ final String LHS = "code 1041 occurs and sum of all digit not equal ( 1034 + 1035 )";
+ final String rule = "rule \"x\"\nwhen\n" + LHS + "\nthen\nend";
+
+ DefaultExpander de = new DefaultExpander();
+ de.addDSLMapping( this.file.getMapping() );
+
+ final String ruleAfterExpansion = de.expand( rule );
+
+ final String expected = "rule \"x\"\nwhen\nAAAA( cd1 == 1041, cd2 != ( 1034 + 1035 ))\nthen\nend\n";
+
+ assertEquals( expected,
+ ruleAfterExpansion );
+
+ } catch ( final IOException e ) {
+ e.printStackTrace();
+ fail( "Should not raise exception " );
+ }
+
+ }
+
public void testParseFileWithEscapes() {
- String file = "[then]TEST=System.out.println(\"DO_SOMETHING\");\n" +
- "[when]code {code1} occurs and sum of all digit not equal \\( {code2} \\+ {code3} \\)=AAAA( cd1 == {code1}, cd2 != ( {code2} + {code3} ))\n" +
- "[when]code {code1} occurs=BBBB\n";
+ String file = "[then]TEST=System.out.println(\"DO_SOMETHING\");\n" + "[when]code {code1} occurs and sum of all digit not equal \\( {code2} \\+ {code3} \\)=AAAA( cd1 == {code1}, cd2 != ( {code2} + {code3} ))\n"
+ + "[when]code {code1} occurs=BBBB\n";
try {
final Reader reader = new StringReader( file );
this.file = new DSLMappingFile();
@@ -121,19 +158,20 @@
assertTrue( this.file.getErrors().toString(),
parsingResult );
assertTrue( this.file.getErrors().isEmpty() );
-
+
final String LHS = "code 1041 occurs and sum of all digit not equal ( 1034 + 1035 )";
final String rule = "rule \"x\"\nwhen\n" + LHS + "\nthen\nTEST\nend";
DefaultExpander de = new DefaultExpander();
- de.addDSLMapping(this.file.getMapping());
-
- final String ruleAfterExpansion = de.expand(rule);
-
+ de.addDSLMapping( this.file.getMapping() );
+
+ final String ruleAfterExpansion = de.expand( rule );
+
final String expected = "rule \"x\"\nwhen\nAAAA( cd1 == 1041, cd2 != ( 1034 + 1035 ))\nthen\nSystem.out.println(\"DO_SOMETHING\");\nend\n";
-
- assertEquals( expected, ruleAfterExpansion );
-
+
+ assertEquals( expected,
+ ruleAfterExpansion );
+
} catch ( final IOException e ) {
e.printStackTrace();
fail( "Should not raise exception " );
@@ -174,7 +212,7 @@
}
}
-
+
public void testEnum() {
String file = "[when][]ATTRIBUTE {attr:ENUM:Attribute.value} in {list}=Attribute( {attr} in ({list}) )";
try {
@@ -197,14 +235,16 @@
entry.getSection() );
assertEquals( DSLMappingEntry.EMPTY_METADATA,
entry.getMetaData() );
- System.out.println(entry.getValuePattern());
- System.out.println(entry.getVariables());
+ System.out.println( entry.getValuePattern() );
+ System.out.println( entry.getVariables() );
assertEquals( "ATTRIBUTE {attr:ENUM:Attribute.value} in {list}",
entry.getMappingKey() );
- assertEquals( "Attribute( {attr} in ({list}) )",entry.getMappingValue() );
-
- assertEquals("(\\W|^)ATTRIBUTE\\s+(.*?)\\s+in\\s+(.*?)$",entry.getKeyPattern().toString());
+ assertEquals( "Attribute( {attr} in ({list}) )",
+ entry.getMappingValue() );
+ assertEquals( "(\\W|^)ATTRIBUTE\\s+(.*?)\\s+in\\s+(.*?)$",
+ entry.getKeyPattern().toString() );
+
} catch ( final IOException e ) {
e.printStackTrace();
fail( "Should not raise exception " );
More information about the jboss-svn-commits
mailing list