From 1166d339d189420b01f0b54747fc2d1746fee7b9 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sat, 29 Jan 2022 20:30:03 +1030 Subject: [PATCH] utter: fix local package removal logic --- dump.go | 3 +++ spew_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/dump.go b/dump.go index df47c89..43ac0ff 100644 --- a/dump.go +++ b/dump.go @@ -588,6 +588,9 @@ func (d *dumpState) dump(v reflect.Value, wasPtr, static, canElideCompound bool, // typeString returns the string representation of the reflect.Type with the local // package selector removed. func typeString(typ reflect.Type, local string) string { + if typ.PkgPath() != "" { + return strings.TrimPrefix(strings.TrimPrefix(typ.String(), local), ".") + } switch typ.Kind() { case reflect.Ptr: return "*" + strings.TrimPrefix(strings.TrimPrefix(strings.TrimPrefix(typ.String(), "*"), local), ".") diff --git a/spew_test.go b/spew_test.go index b353c00..436e223 100644 --- a/spew_test.go +++ b/spew_test.go @@ -140,6 +140,8 @@ func initSpewTests() { m := map[int][]interface{}{1: c} + type b map[string]interface{} + utterTests = []utterTest{ {scsDefault, fCSFdump, int8(127), "int8(127)\n"}, {scsDefault, fCSSdump, uint8(64), "uint8(0x40)\n"}, @@ -209,6 +211,7 @@ func initSpewTests() { {elideLocalDefault, fCSFdump, chan<- cs(nil), "chan<- cs(nil)\n", }, + {elideLocalDefault, fCSFdump, b{"one": b{"two": "three"}}, "b{\n string(\"one\"): b{\n string(\"two\"): string(\"three\"),\n },\n}\n"}, {elideTypeDefault, fCSFdump, float64(1), "1.0\n"}, {elideTypeDefault, fCSFdump, float32(1), "float32(1)\n"}, {elideTypeDefault, fCSFdump, int(1), "1\n"}, @@ -229,6 +232,7 @@ func initSpewTests() { {elideTypeDefault, fCSFdump, map[struct{ int }]interface{}{{1}: struct{ int }{1}}, "map[struct { int }]interface{}{\n {\n int: 1,\n }: struct { int }{\n int: 1,\n },\n}\n"}, {elideTypeDefault, fCSFdump, []struct{ int }{{1}}, "[]struct { int }{\n {\n int: 1,\n },\n}\n"}, {elideTypeDefault, fCSFdump, []interface{}{struct{ int }{1}}, "[]interface{}{\n struct { int }{\n int: 1,\n },\n}\n"}, + {elideTypeDefault, fCSFdump, b{"one": b{"two": "three"}}, "utter_test.b{\n \"one\": utter_test.b{\n \"two\": \"three\",\n },\n}\n"}, {num4elideDefault, fCSFdump, []interface{}{ []int{1, 2, 3, 4}, []uint{1, 2, 3, 4, 5},