Skip to content

Commit

Permalink
utter: fix local package removal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jan 29, 2022
1 parent ba89990 commit 1166d33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), ".")
Expand Down
4 changes: 4 additions & 0 deletions spew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand All @@ -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},
Expand Down

0 comments on commit 1166d33

Please sign in to comment.