mirror of
https://github.com/bytedance/arishem.git
synced 2025-12-24 11:30:57 +08:00
change num const build param type to interface
Change-Id: I77e7ec9968bfc20cd8977129e805bbea70bb7c86
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/bytedance/arishem/internal/operator"
|
||||
"github.com/bytedance/arishem/internal/parser"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -28,12 +29,12 @@ func TestBuildCondition(t *testing.T) {
|
||||
condGroup := NewConditionsCondGroup(OpLogicAnd)
|
||||
cond1 := NewCondition(operator.Equal)
|
||||
cond1.Lhs = NewConstExpr(NewNumConst(1.0))
|
||||
cond1.Rhs = NewConstExpr(NewNumConst(1.0))
|
||||
cond1.Rhs = NewConstExpr(NewNumConst(int64(math.MaxInt64)))
|
||||
condGroup.AddConditions(cond1)
|
||||
expr, err := condGroup.Build()
|
||||
assert.Nil(t, err)
|
||||
assert.NotEmpty(t, expr)
|
||||
assert.Equal(t, `{"OpLogic":"&&","Conditions":[{"Operator":"==","Lhs":{"Const":{"NumConst":1}},"Rhs":{"Const":{"NumConst":1}}}]}`, expr)
|
||||
assert.Equal(t, `{"OpLogic":"&&","Conditions":[{"Operator":"==","Lhs":{"Const":{"NumConst":1}},"Rhs":{"Const":{"NumConst":9223372036854775807}}}]}`, expr)
|
||||
|
||||
cond2 := NewCondition(operator.ListIn, NOT)
|
||||
var varPath VarExpr = "user.user_list#2.name"
|
||||
@@ -48,7 +49,7 @@ func TestBuildCondition(t *testing.T) {
|
||||
expr, err = condGroup.Build()
|
||||
assert.Nil(t, err)
|
||||
assert.NotEmpty(t, expr)
|
||||
assert.Equal(t, `{"OpLogic":"&&","Conditions":[{"Operator":"==","Lhs":{"Const":{"NumConst":1}},"Rhs":{"Const":{"NumConst":1}}},{"Operator":"!LIST_IN","Lhs":{"VarExpr":"user.user_list#2.name"},"Rhs":{"ConstList":[{"StrConst":"Jack"},{"StrConst":"Jane"},{"StrConst":"John"},{"StrConst":"Ezreal"}]}}]}`, expr)
|
||||
assert.Equal(t, `{"OpLogic":"&&","Conditions":[{"Operator":"==","Lhs":{"Const":{"NumConst":1}},"Rhs":{"Const":{"NumConst":9223372036854775807}}},{"Operator":"!LIST_IN","Lhs":{"VarExpr":"user.user_list#2.name"},"Rhs":{"ConstList":[{"StrConst":"Jack"},{"StrConst":"Jane"},{"StrConst":"John"},{"StrConst":"Ezreal"}]}}]}`, expr)
|
||||
|
||||
pass, err := JudgeConditionWithFactMeta(context.Background(), expr, `{"user":{"user_list":[{"name":"Aatrox"},{"name":"Ahri"},{"name":"Ezreal"},{"name":"MalPhite"}]}}`)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
package arishem
|
||||
|
||||
type Const struct {
|
||||
BoolConst *bool `json:"BoolConst,omitempty"`
|
||||
NumConst *float64 `json:"NumConst,omitempty"`
|
||||
StrConst *string `json:"StrConst,omitempty"`
|
||||
BoolConst *bool `json:"BoolConst,omitempty"`
|
||||
NumConst interface{} `json:"NumConst,omitempty"`
|
||||
StrConst *string `json:"StrConst,omitempty"`
|
||||
}
|
||||
|
||||
func NewBoolConst(b bool) *Const {
|
||||
return &Const{BoolConst: &b}
|
||||
}
|
||||
|
||||
func NewNumConst(f float64) *Const {
|
||||
return &Const{NumConst: &f}
|
||||
func NewNumConst(n interface{}) *Const {
|
||||
return &Const{NumConst: n}
|
||||
}
|
||||
|
||||
func NewStrConst(s string) *Const {
|
||||
|
||||
Reference in New Issue
Block a user