Skip to content

Commit

Permalink
Render uint types as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Mar 21, 2015
1 parent 68b6cb0 commit ca39074
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ var (
openParenBytes = []byte("(")
closeParenBytes = []byte(")")
nilBytes = []byte("nil")
hexZeroBytes = []byte("0x")
zeroBytes = []byte("0")
pointZeroBytes = []byte(".0")
circularBytes = []byte("(<already shown>)")
Expand Down
3 changes: 2 additions & 1 deletion dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ func (d *dumpState) dump(v reflect.Value, wasPtr bool) {
printInt(d.w, v.Int(), 10)

case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
printUint(d.w, v.Uint(), 10)
d.w.Write(hexZeroBytes)
printUint(d.w, v.Uint(), 16)

case reflect.Float32:
printFloat(d.w, v.Float(), 32, !wantType)
Expand Down
20 changes: 10 additions & 10 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func addUintDumpTests() {
nv := (*uint8)(nil)
pv := &v
vt := "uint8"
vs := "255"
vs := "0xff"
addDumpTest(v, vt+"("+vs+")\n")
addDumpTest(pv, "&"+vt+"("+vs+")\n")
addDumpTest(&pv, "&&"+vt+"("+vs+")\n")
Expand All @@ -161,7 +161,7 @@ func addUintDumpTests() {
nv2 := (*uint16)(nil)
pv2 := &v2
v2t := "uint16"
v2s := "65535"
v2s := "0xffff"
addDumpTest(v2, v2t+"("+v2s+")\n")
addDumpTest(pv2, "&"+v2t+"("+v2s+")\n")
addDumpTest(&pv2, "&&"+v2t+"("+v2s+")\n")
Expand All @@ -172,7 +172,7 @@ func addUintDumpTests() {
nv3 := (*uint32)(nil)
pv3 := &v3
v3t := "uint32"
v3s := "4294967295"
v3s := "0xffffffff"
addDumpTest(v3, v3t+"("+v3s+")\n")
addDumpTest(pv3, "&"+v3t+"("+v3s+")\n")
addDumpTest(&pv3, "&&"+v3t+"("+v3s+")\n")
Expand All @@ -183,7 +183,7 @@ func addUintDumpTests() {
nv4 := (*uint64)(nil)
pv4 := &v4
v4t := "uint64"
v4s := "18446744073709551615"
v4s := "0xffffffffffffffff"
addDumpTest(v4, v4t+"("+v4s+")\n")
addDumpTest(pv4, "&"+v4t+"("+v4s+")\n")
addDumpTest(&pv4, "&&"+v4t+"("+v4s+")\n")
Expand All @@ -194,7 +194,7 @@ func addUintDumpTests() {
nv5 := (*uint)(nil)
pv5 := &v5
v5t := "uint"
v5s := "4294967295"
v5s := "0xffffffff"
addDumpTest(v5, v5t+"("+v5s+")\n")
addDumpTest(pv5, "&"+v5t+"("+v5s+")\n")
addDumpTest(&pv5, "&&"+v5t+"("+v5s+")\n")
Expand Down Expand Up @@ -328,7 +328,7 @@ func addArrayDumpTests() {
v3t2 := "string"
v3t3 := "int"
v3t4 := "uint"
v3s := "{\n " + v3t2 + "(\"one\"),\n " + v3t3 + "(2),\n " + v3t4 + "(3),\n}"
v3s := "{\n " + v3t2 + "(\"one\"),\n " + v3t3 + "(2),\n " + v3t4 + "(0x3),\n}"
addDumpTest(v3, v3t+v3s+"\n")
addDumpTest(pv3, "&"+v3t+v3s+"\n")
addDumpTest(&pv3, "&&"+v3t+v3s+"\n")
Expand Down Expand Up @@ -391,7 +391,7 @@ func addSliceDumpTests() {
v3t3 := "int"
v3t4 := "uint"
v3t5 := "interface{}"
v3s := "{\n " + v3t2 + "(\"one\"),\n " + v3t3 + "(2),\n " + v3t4 + "(3),\n " + v3t5 + "(nil),\n}"
v3s := "{\n " + v3t2 + "(\"one\"),\n " + v3t3 + "(2),\n " + v3t4 + "(0x3),\n " + v3t5 + "(nil),\n}"
addDumpTest(v3, v3t+v3s+"\n")
addDumpTest(pv3, "&"+v3t+v3s+"\n")
addDumpTest(&pv3, "&&"+v3t+v3s+"\n")
Expand Down Expand Up @@ -458,7 +458,7 @@ func addInterfaceDumpTests() {
v2 := interface{}(uint16(65535))
pv2 := &v2
v2t := "uint16"
v2s := "65535"
v2s := "0xffff"
addDumpTest(v2, v2t+"("+v2s+")\n")
addDumpTest(pv2, "&"+v2t+"("+v2s+")\n")
addDumpTest(&pv2, "&&"+v2t+"("+v2s+")\n")
Expand Down Expand Up @@ -545,7 +545,7 @@ func addStructDumpTests() {
vt := "utter_test.s1"
vt2 := "int8"
vt3 := "uint8"
vs := "{\n a: " + vt2 + "(127),\n b: " + vt3 + "(255),\n}"
vs := "{\n a: " + vt2 + "(127),\n b: " + vt3 + "(0xff),\n}"
addDumpTest(v, vt+vs+"\n")
addDumpTest(pv, "&"+vt+vs+"\n")
addDumpTest(&pv, "&&"+vt+vs+"\n")
Expand All @@ -564,7 +564,7 @@ func addStructDumpTests() {
v2t3 := "int8"
v2t4 := "uint8"
v2t5 := "bool"
v2s := "{\n s1: " + v2t2 + "{\n a: " + v2t3 + "(127),\n b: " + v2t4 + "(255),\n },\n b: " + v2t5 + "(true),\n}"
v2s := "{\n s1: " + v2t2 + "{\n a: " + v2t3 + "(127),\n b: " + v2t4 + "(0xff),\n },\n b: " + v2t5 + "(true),\n}"
addDumpTest(v2, v2t+v2s+"\n")
addDumpTest(pv2, "&"+v2t+v2s+"\n")
addDumpTest(&pv2, "&&"+v2t+v2s+"\n")
Expand Down
2 changes: 1 addition & 1 deletion spew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func initSpewTests() {

utterTests = []utterTest{
{scsDefault, fCSFdump, int8(127), "int8(127)\n"},
{scsDefault, fCSSdump, uint8(64), "uint8(64)\n"},
{scsDefault, fCSSdump, uint8(64), "uint8(0x40)\n"},
{scsDefault, fSdump, complex(-10, -20), "complex128(-10-20i)\n"},
{noComDefault, fCSFdump, []byte{1, 2, 3, 4, 5, 0},
"[]uint8{\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x00,\n}\n",
Expand Down

0 comments on commit ca39074

Please sign in to comment.