franela / goblin

Minimal and Beautiful Go testing framework
MIT License
887 stars 79 forks source link

Reflect Value can be compared? #47

Closed ggaaooppeenngg closed 9 years ago

ggaaooppeenngg commented 9 years ago

about https://github.com/franela/goblin/blob/master/assertions.go#L23

I am finding some snippets about reflect ,I tried

package main

import (
    "fmt"
    "reflect"
)

func main() {
    fmt.Println(reflect.ValueOf(1) == reflect.ValueOf(1))
}

it shows "FALSE", reflect.Value underlying structure is pointer,even they get same value,it points to different address.

marcosnils commented 9 years ago

@ggaaooppeenngg We know that, that's why objectsAreEqual function tries many different ways to check if the two parameters supplied return true.

If you run the following code it will print "Are Equal".


package main

import (
    "fmt"
    "github.com/franela/goblin"
)

func main() {
    g := goblin.G{}
    g.Assert(1).Equal(1)
    fmt.Println("Are Equal")
}
ggaaooppeenngg commented 9 years ago

@marcosnils I think that line is a redundant.

marcosnils commented 9 years ago

@ggaaooppeenngg you're right. Thanks for the catch. I'll remove that line.