From 8685736ac1d440fdfde7a7a1fd296b3fe11cea51 Mon Sep 17 00:00:00 2001 From: komuw Date: Fri, 1 Mar 2024 22:57:21 +0300 Subject: [PATCH] f --- dump.go | 3 ++- kama_test.go | 31 +++++++++++++++++++++++++++++++ packages.go | 3 ++- vars.go | 9 +++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/dump.go b/dump.go index c756e34..b42c33d 100644 --- a/dump.go +++ b/dump.go @@ -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 { diff --git a/kama_test.go b/kama_test.go index 75129f3..605a31d 100644 --- a/kama_test.go +++ b/kama_test.go @@ -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) + }) + } +} diff --git a/packages.go b/packages.go index ec1964b..a719bda 100644 --- a/packages.go +++ b/packages.go @@ -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" ) diff --git a/vars.go b/vars.go index 97d3ff9..9795c2f 100644 --- a/vars.go +++ b/vars.go @@ -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( ` [ @@ -80,6 +86,8 @@ KIND: %v SIGNATURE: %v FIELDS: %v METHODS: %v +TRACE: [ %v +] SNIPPET: %s ] `, @@ -88,6 +96,7 @@ SNIPPET: %s v.Signature, nLf(v.Fields), nLf(v.Methods), + tr, v.Val, ) }