-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonlogic_test.go
More file actions
46 lines (35 loc) · 867 Bytes
/
jsonlogic_test.go
File metadata and controls
46 lines (35 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package jsonlogic
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewInherit(t *testing.T) {
assert := assert.New(t)
parent := NewEmpty()
parent.AddOperation("xxx", func(apply Applier, params []interface{}, data interface{}) (interface{}, error) {
return "parent", nil
})
child := NewInherit(parent)
child.AddOperation("xxx", func(apply Applier, params []interface{}, data interface{}) (interface{}, error) {
return "child", nil
})
notFoundChild := NewInherit(parent)
notFoundChild.AddOperation("xxx", nil)
logic := map[string]interface{}{
"xxx": nil,
}
{
res, err := child.Apply(logic, nil)
assert.NoError(err)
assert.Equal("child", res)
}
{
_, err := notFoundChild.Apply(logic, nil)
assert.Error(err)
}
{
res, err := parent.Apply(logic, nil)
assert.NoError(err)
assert.Equal("parent", res)
}
}