change num const build param type to interface

Change-Id: I77e7ec9968bfc20cd8977129e805bbea70bb7c86
This commit is contained in:
murasame
2024-06-04 15:52:47 +08:00
parent 2606b453f1
commit 7d2e2cf0a8
2 changed files with 9 additions and 8 deletions

View File

@@ -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)

View File

@@ -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 {