mirror of
https://github.com/asdine/storm.git
synced 2025-09-27 03:06:16 +08:00
29
q/compare.go
29
q/compare.go
@@ -24,6 +24,10 @@ func compare(a, b interface{}, tok token.Token) bool {
|
||||
return constant.Compare(constant.MakeInt64(vala.Int()), tok, constant.MakeInt64(valb.Int()))
|
||||
}
|
||||
|
||||
if bk >= reflect.Uint && bk <= reflect.Uint64 {
|
||||
return constant.Compare(constant.MakeInt64(vala.Int()), tok, constant.MakeInt64(int64(valb.Uint())))
|
||||
}
|
||||
|
||||
if bk == reflect.Float32 || bk == reflect.Float64 {
|
||||
return constant.Compare(constant.MakeFloat64(float64(vala.Int())), tok, constant.MakeFloat64(valb.Float()))
|
||||
}
|
||||
@@ -36,6 +40,27 @@ func compare(a, b interface{}, tok token.Token) bool {
|
||||
|
||||
return constant.Compare(constant.MakeFloat64(float64(vala.Int())), tok, constant.MakeFloat64(bla))
|
||||
}
|
||||
case ak >= reflect.Uint && ak <= reflect.Uint64:
|
||||
if bk >= reflect.Uint && bk <= reflect.Uint64 {
|
||||
return constant.Compare(constant.MakeUint64(vala.Uint()), tok, constant.MakeUint64(valb.Uint()))
|
||||
}
|
||||
|
||||
if bk >= reflect.Int && bk <= reflect.Int64 {
|
||||
return constant.Compare(constant.MakeUint64(vala.Uint()), tok, constant.MakeUint64(uint64(valb.Int())))
|
||||
}
|
||||
|
||||
if bk == reflect.Float32 || bk == reflect.Float64 {
|
||||
return constant.Compare(constant.MakeFloat64(float64(vala.Uint())), tok, constant.MakeFloat64(valb.Float()))
|
||||
}
|
||||
|
||||
if bk == reflect.String {
|
||||
bla, err := strconv.ParseFloat(valb.String(), 64)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return constant.Compare(constant.MakeFloat64(float64(vala.Uint())), tok, constant.MakeFloat64(bla))
|
||||
}
|
||||
case ak == reflect.Float32 || ak == reflect.Float64:
|
||||
if bk == reflect.Float32 || bk == reflect.Float64 {
|
||||
return constant.Compare(constant.MakeFloat64(vala.Float()), tok, constant.MakeFloat64(valb.Float()))
|
||||
@@ -45,6 +70,10 @@ func compare(a, b interface{}, tok token.Token) bool {
|
||||
return constant.Compare(constant.MakeFloat64(vala.Float()), tok, constant.MakeFloat64(float64(valb.Int())))
|
||||
}
|
||||
|
||||
if bk >= reflect.Uint && bk <= reflect.Uint64 {
|
||||
return constant.Compare(constant.MakeFloat64(vala.Float()), tok, constant.MakeFloat64(float64(valb.Uint())))
|
||||
}
|
||||
|
||||
if bk == reflect.String {
|
||||
bla, err := strconv.ParseFloat(valb.String(), 64)
|
||||
if err != nil {
|
||||
|
@@ -41,6 +41,12 @@ func TestCompare(t *testing.T) {
|
||||
assert.True(t, compare(t1, t3, token.GTR))
|
||||
assert.False(t, compare(&A{Name: "John"}, t1, token.EQL))
|
||||
assert.False(t, compare(&A{Name: "John"}, t1, token.LEQ))
|
||||
assert.True(t, compare(uint32(10), uint32(5), token.GTR))
|
||||
assert.False(t, compare(uint32(5), uint32(10), token.GTR))
|
||||
assert.True(t, compare(uint32(10), int32(5), token.GTR))
|
||||
assert.True(t, compare(uint32(10), float32(5), token.GTR))
|
||||
assert.True(t, compare(int32(10), uint32(5), token.GTR))
|
||||
assert.True(t, compare(float32(10), uint32(5), token.GTR))
|
||||
}
|
||||
|
||||
func TestCmp(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user