From 7d2e2cf0a86e4e3a82c9ada321f3a0556c9ba3c9 Mon Sep 17 00:00:00 2001 From: murasame Date: Tue, 4 Jun 2024 15:52:47 +0800 Subject: [PATCH] change num const build param type to interface Change-Id: I77e7ec9968bfc20cd8977129e805bbea70bb7c86 --- arishem/arishem_builder_test.go | 7 ++++--- arishem/arishem_expr_builder.go | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arishem/arishem_builder_test.go b/arishem/arishem_builder_test.go index b7312e4..fd60a23 100644 --- a/arishem/arishem_builder_test.go +++ b/arishem/arishem_builder_test.go @@ -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) diff --git a/arishem/arishem_expr_builder.go b/arishem/arishem_expr_builder.go index 4dcfda0..94c7c18 100644 --- a/arishem/arishem_expr_builder.go +++ b/arishem/arishem_expr_builder.go @@ -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 {