-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Better make file * Fixes issue #270, where in JSON DOM, evaluating non-existent field in map interface yield a zero value, thus caling val.elem() causes a panic. Now the zero is evaluated and returned a normal error
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package examples | ||
|
||
import ( | ||
"fmt" | ||
"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" | ||
"testing" | ||
) | ||
|
||
const ( | ||
input_rule = ` | ||
rule TestRule "" { | ||
when | ||
R.Result == 'NoResult' && | ||
inputs.i_am_missing == 'abc' && | ||
inputs.name.first == 'john' | ||
then | ||
R.Result = "ok"; | ||
} | ||
` | ||
) | ||
|
||
|
||
func TestDataContextMissingFact(t *testing.T) { | ||
|
||
oresult := &ObjectResult{ | ||
Result: "NoResult", | ||
} | ||
|
||
// build rules | ||
lib := ast.NewKnowledgeLibrary() | ||
rb := builder.NewRuleBuilder(lib) | ||
err := rb.BuildRuleFromResource("Test", "0.0.1", pkg.NewBytesResource([]byte(input_rule))) | ||
|
||
// add JSON fact | ||
json := []byte(`{"blabla":"bla","name":{"first":"john","last":"doe"}}`) | ||
kb := lib.NewKnowledgeBaseInstance("Test", "0.0.1") | ||
dcx := ast.NewDataContext() | ||
|
||
err = dcx.Add("R", oresult) | ||
err = dcx.AddJSON("inputs", json) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
|
||
// results in panic | ||
engine.NewGruleEngine().Execute(dcx, kb) | ||
|
||
} |
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