Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Mar 1, 2024
1 parent ca813c1 commit 8685736
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package kama

import (
"fmt"
"golang.org/x/exp/slices"
"math"
"reflect"
"sort"
"strings"
"unicode"

"golang.org/x/exp/slices"
)

func dump(val reflect.Value, hideZeroValues bool, indentLevel int) string {
Expand Down
31 changes: 31 additions & 0 deletions kama_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,34 @@ func TestDiff(t *testing.T) {
})
}
}

func TestDirWithStack(t *testing.T) {
t.Parallel()

req, _ := http.NewRequest("GET", "https://example.com", nil)
req.Header.Set("Content-Type", "application/octet-stream")
req.AddCookie(&http.Cookie{Name: "hello", Value: "world"})

tt := []struct {
tName string
item interface{}
}{
{
tName: "http request with stack",
item: req,
},
}

for _, v := range tt {
v := v

t.Run(v.tName, func(t *testing.T) {
t.Parallel()

res := Dir(v.item)

path := getDataPath(t, "kama_test.go", v.tName)
dealWithTestData(t, path, res)
})
}
}
3 changes: 2 additions & 1 deletion packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package kama
import (
"fmt"
"go/types"
"golang.org/x/exp/slices"
"strings"

"golang.org/x/exp/slices"

"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/types/typeutil"
)
Expand Down
9 changes: 9 additions & 0 deletions vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func (v vari) String() string {
return fm
}

st := getStackTrace()
tr := ""
for _, v := range st {
tr = tr + fmt.Sprintf("\n%v", v)
}

return fmt.Sprintf(
`
[
Expand All @@ -80,6 +86,8 @@ KIND: %v
SIGNATURE: %v
FIELDS: %v
METHODS: %v
TRACE: [ %v
]
SNIPPET: %s
]
`,
Expand All @@ -88,6 +96,7 @@ SNIPPET: %s
v.Signature,
nLf(v.Fields),
nLf(v.Methods),
tr,
v.Val,
)
}
Expand Down

0 comments on commit 8685736

Please sign in to comment.