frankban / quicktest

Quick helpers for testing Go applications
MIT License
529 stars 27 forks source link

format uint64 differently. #92

Closed komuw closed 3 years ago

komuw commented 3 years ago

Right now, if you have code like;

c := qt.New(t)
c.Assert(uint64(17), qt.Equals, 8)

See: https://play.golang.org/p/MV6g6URN_Gy

It results in

=== RUN   TestLastIndex
    prog.go:11: 
        error:
          values are not equal
        got:
          uint64(0x11)
        want:
          int(8)
        stack:
          /tmp/sandbox759567241/prog.go:11
            <cannot parse source file: open /tmp/sandbox759567241/prog.go: no such file or directory>

--- FAIL: TestLastIndex (0.00s)

In my opinion, formatting it as uint64(17) instead of the current uint64(0x11) would be much better

komuw commented 3 years ago

this is worse when the unit64's in question are large; uint64(17_898) gets formatted as uint64(0x45ea)

komuw commented 3 years ago

If the maintainer/s of this repo do agree that this is worth doing, I would be happy to push a PR. the following diff seems like it might fix it:

diff --git a/format.go b/format.go
index 39cc8ab..056f791 100644
--- a/format.go
+++ b/format.go
@@ -35,6 +35,8 @@ func Format(v interface{}) string {
                return "s" + quoteString(s)
        case string:
                return quoteString(v)
+       case uint64:
+               return fmt.Sprintf("%T(%d)", v, v)
        }
        if bytes, ok := byteSlice(v); ok && bytes != nil && utf8.Valid(bytes) {
                // It's a top level slice of bytes that's also valid UTF-8.
frankban commented 3 years ago

Thanks for reporting, and yes please feel free to propose a PR! This seems to involve all uint types.

frankban commented 3 years ago

Tagged as v1.12.1.