Skip to content

Commit

Permalink
Merge pull request #19 from bytedance/dev/change_numconstty
Browse files Browse the repository at this point in the history
change num const build param type to interface
  • Loading branch information
AoranAllen authored Jun 4, 2024
2 parents 2606b45 + 7d2e2cf commit f7a957c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions arishem/arishem_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ import (
"github.com/bytedance/arishem/internal/operator"
"github.com/bytedance/arishem/internal/parser"
"github.com/stretchr/testify/assert"
"math"
"testing"
)

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"
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions arishem/arishem_expr_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f7a957c

Please sign in to comment.