Skip to content

Commit

Permalink
[DROOLS-7271] Fully port RuleParserTest as MiscDRLParserTest with @di…
Browse files Browse the repository at this point in the history
…sabled and priority comment (#10)
  • Loading branch information
tkobayas authored and rgdoliveira committed Oct 24, 2024
1 parent d637f88 commit 413d4cf
Show file tree
Hide file tree
Showing 69 changed files with 4,235 additions and 13 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.compiler

rule test_rule extends rule1
when
$foo : foo()
then

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.drools.compiler

rule test_rule
@fooMeta1(barVal1)
@fooMeta2(barVal2)
when
then
System.out.println("Consequence");
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.compiler

rule test
when
A()
( B() and C() ) or
( D() and E() ) or
( F() and G() )
then

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rule "AccumulateParserTest"
when
Integer() from accumulate( Person( age > 21 ),
init( int x = 0; ),
action( x++; ),
result( new Integer(x) ) );
then
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rule "AccumulateReverseParserTest"
when
Number() from accumulate( Person( $age : age > 21 ),
average( $age ) );
then
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.compiler

rule "Accumulate 1"
when
accumulate( Cheese( $price : price ),
$a1 : average( $price ),
$m1 : min( $price ),
$M1 : max( $price ) // binds are optional, but it makes no sense to not have a binding in this case
)
then
// do something
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.compiler

rule "Accumulate 1"
when
accumulate( Cheese( $price : price );
$a1 : average( $price ),
$m1 : min( $price ),
$M1 : max( $price ); // binds are optional, but it makes no sense to not have a binding in this case
$a1 > 10 && $M1 <= 100,
$m1 == 5 // inline evals
)
then
// do something
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rule "AccumulateReverseParserTest"
when
Integer() from accumulate( Person( age > 21 ),
init( int x = 0; ),
action( x++; ),
reverse( x--; ),
result( new Integer(x) ) );
then
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rule "AccumulateMultiPatternParserTest"
when
$counter:Integer() from accumulate( $person : Person( age > 21 ) and Cheese( type == $person.likes ),
init( int x = 0; ),
action( x++; ),
result( new Integer(x) ) );
then
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rule "AccumulateParserTest"
when
$counter:Integer() from accumulate( $person : Person( age > 21 ),
init( int x = 0; ),
action( x++; ),
result( new Integer(x) ) );
then
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rule "AccumulateParserTest"
when
// below statement makes no sense, but is useful to test parsing recursiveness
$personList : ArrayList() from accumulate( Person( $age : age > 21 || < 10 ) from collect( People() from $town.getPeople() ),
max( $age ) );
then
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import org.drools.compiler.Person

rule simple_rule
when
Person(name == "mark") and Cheese(type == "stilton")
Person(name == "mark") or Cheese(type == "stilton")
then
System.out.println( "Mark and Michael" );
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.compiler.test;

import org.drools.compiler.Cheese;

rule "like cheddar"
when
Cheese( $type:type )
then
System.out.println("I like " + $type);
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.compiler.test;

import org.drools.compiler.Cheese;
import org.drools.compiler.Person;

rule "Who likes Stilton"
when
Cheese($type : type == "stilton")
$person : Person( $name : name == "bob", likes == $type)
then
System.out.println( $name + " likes " + $type);
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


rule simple_rule
when
( (not Foo(x=="a") or Foo(x=="y") ) and ( Shoes() or Butt() ) )
then
end
Loading

0 comments on commit 413d4cf

Please sign in to comment.