Giter Site home page Giter Site logo

Comments (4)

vkryukov avatar vkryukov commented on May 21, 2024

This is an interesting example. Indeed, these two values will fail all of ObjectsAreEqual tests:

a b: []byte{} []byte(nil)
a==nil b==nil: false true
a DeepEqual b: false
aValue == bValue: false
aValue convertible to bValue: true
bValue convertible to aValue: true
aValue converted to bValue == bValue: false
bValue converted to aValue == aValue: false

BTW, fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) is not covered by tests, and when I was working on #76, I couldn't come up with anything that would fail all the previous comparisons in ObjectsAreEqual but not this one.

Hopefully someone more enlightened about Go reflection could provide some insight here.

from testify.

vkryukov avatar vkryukov commented on May 21, 2024

The Nil section at http://blog.golang.org/slices describes the difference between empty and nil slices of the same type, specifically:

As should be clear, an empty slice can grow (assuming it has non-zero capacity), but a nil slice has no array to put values in and can never grow to hold even one element.

That said, a nil slice is functionally equivalent to a zero-length slice, even though it points to nothing. It has length zero and can be appended to, with allocation.

Based on the above, I would say the ObjectsAreEqual behavior is correct in this case.

from testify.

vkryukov avatar vkryukov commented on May 21, 2024

See also this: https://groups.google.com/d/msg/golang-nuts/QrItXLz3jis/NubiAVy9F6sJ

from testify.

m0sth8 avatar m0sth8 commented on May 21, 2024

Victor, I agree with you. It was a mistake in go and they fixed it. But behavior of testify is different on go 1.2 and 1.3. I think I'll close this bug and leave it for the history.

from testify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.