Skip to content

Commit

Permalink
Fixed eq, in and holds
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-obernberger committed Jun 3, 2022
1 parent d040b39 commit 48a1615
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ type QueryFunc func(x, y interface{}) (bool, error)
// eq checks whether x, y are deeply eq
func eq(x, y interface{}) (bool, error) {
// if the y value is numeric (int/int8-int64/float32/float64) then convert to float64
if fv, ok := toFloat64(y); ok {
y = fv
}
// if fv, ok := toFloat64(y); ok {
// y = fv
// }
// commenting this out since it returns false for:
//
// var a int, var b int = 3, 3
// fmt.Println(eq(a, b)) // → false
return reflect.DeepEqual(x, y), nil
}

Expand Down Expand Up @@ -166,8 +170,6 @@ func strEndsWith(x, y interface{}) (bool, error) {
func in(x, y interface{}) (bool, error) {
if yv, ok := y.([]string); ok {
for _, v := range yv {
fmt.Printf("vy: %s\n", v)
fmt.Printf("x: %s\n", x)
if ok, _ := eq(x, v); ok {
return true, nil
}
Expand Down Expand Up @@ -199,9 +201,6 @@ func notIn(x, y interface{}) (bool, error) {
// holds checks if x contains y e.g: holds("[1,2,3]", 1)
func holds(x, y interface{}) (bool, error) {
b, err := in(y, x)
fmt.Printf("x: %s\n\ttype: %t\n", x, x)
fmt.Printf("y: %s\n\ttype: %t\n", y, y)
fmt.Printf("y holds y: %t", b)
return b, err
}

Expand Down

0 comments on commit 48a1615

Please sign in to comment.