-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Better make file * Added samples * Taking the oportunity in this branch to fix some documentation issue * Fixed issue 306 and 307, due to wrong logic when adding ArrayMapSelector ast into ExpressionAtom * Removed unnecessary dummy file
- Loading branch information
Showing
6 changed files
with
96 additions
and
45,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package examples | ||
|
||
import ( | ||
"github.com/hyperjumptech/grule-rule-engine/ast" | ||
"github.com/hyperjumptech/grule-rule-engine/builder" | ||
"github.com/hyperjumptech/grule-rule-engine/engine" | ||
"github.com/hyperjumptech/grule-rule-engine/pkg" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
type StructStringsData struct { | ||
Strings []string | ||
} | ||
|
||
func (f *StructStringsData) GetStrings() []string { | ||
return f.Strings | ||
} | ||
|
||
const panickingRule = ` rule test { | ||
when | ||
Fact.GetStrings()[0] == Fact.GetStrings()[1] | ||
then | ||
Complete(); | ||
}` | ||
|
||
func TestSliceFunctionPanicTest(t *testing.T) { | ||
fact := &StructStringsData{ | ||
Strings: []string{"0", "0"}, | ||
} | ||
|
||
dataContext := ast.NewDataContext() | ||
err := dataContext.Add("Fact", fact) | ||
assert.NoError(t, err) | ||
knowledgeLibrary := ast.NewKnowledgeLibrary() | ||
ruleBuilder := builder.NewRuleBuilder(knowledgeLibrary) | ||
err = ruleBuilder.BuildRuleFromResource("test", "0.0.1", pkg.NewBytesResource([]byte(panickingRule))) | ||
assert.NoError(t, err) | ||
knowledgeBase := knowledgeLibrary.NewKnowledgeBaseInstance("test", "0.0.1") | ||
engine := engine.NewGruleEngine() | ||
|
||
err = engine.Execute(dataContext, knowledgeBase) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package examples | ||
|
||
import ( | ||
"github.com/hyperjumptech/grule-rule-engine/ast" | ||
"github.com/hyperjumptech/grule-rule-engine/builder" | ||
"github.com/hyperjumptech/grule-rule-engine/engine" | ||
"github.com/hyperjumptech/grule-rule-engine/pkg" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
type TestData struct { | ||
Index int | ||
Strings []string | ||
Concatenation string | ||
} | ||
|
||
func (f *TestData) GetStrings() []string { | ||
return f.Strings | ||
} | ||
|
||
const rule = ` rule test { | ||
when | ||
Fact.Index < Fact.Strings.Len() | ||
then | ||
Fact.Concatenation = Fact.Concatenation + Fact.GetStrings()[Fact.Index]; | ||
Fact.Index = Fact.Index + 1; | ||
}` | ||
|
||
func TestSliceFunctionTest(t *testing.T) { | ||
fact := &TestData{ | ||
Index: 0, | ||
Strings: []string{"1", "2", "3"}, | ||
} | ||
|
||
dataContext := ast.NewDataContext() | ||
err := dataContext.Add("Fact", fact) | ||
assert.NoError(t, err) | ||
knowledgeLibrary := ast.NewKnowledgeLibrary() | ||
ruleBuilder := builder.NewRuleBuilder(knowledgeLibrary) | ||
err = ruleBuilder.BuildRuleFromResource("test", "0.0.1", pkg.NewBytesResource([]byte(rule))) | ||
assert.NoError(t, err) | ||
knowledgeBase := knowledgeLibrary.NewKnowledgeBaseInstance("test", "0.0.1") | ||
engine := engine.NewGruleEngine() | ||
|
||
err = engine.Execute(dataContext, knowledgeBase) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "123", fact.Concatenation) | ||
} |
Binary file not shown.
Oops, something went wrong.