Skip to content

Commit

Permalink
dont wrap natural Stringers
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdata committed Nov 21, 2024
1 parent 3f70545 commit 746af07
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ func Stringer[T any](v *T) fmt.Stringer {
if x, ok := any(*v).(fmt.Stringer); ok {
return x
}
if x, ok := any(v).(fmt.Stringer); ok {
return x
}
return stringizer[T]{v}
}
26 changes: 25 additions & 1 deletion stringer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import (
"testing"
)

type testStringer struct{}

func (s testStringer) String() string {
return "I_Am_A_testStringer"
}

type testPtrStringer struct{}

func (s *testPtrStringer) String() string {
return "I_Am_A_testPtrStringer"
}

func TestStringer(t *testing.T) {
txt := "text"
stringer := Stringer(&txt)
Expand All @@ -27,7 +39,7 @@ func TestStringer(t *testing.T) {
teststringer := testStringer{}
stringer = Stringer(&teststringer)
if !reflect.DeepEqual(stringer, teststringer) {
t.Error("not equal")
t.Errorf("%#v != %#v", stringer, teststringer)
}
if s := stringer.String(); s != (testStringer{}).String() {
t.Error(s)
Expand All @@ -36,4 +48,16 @@ func TestStringer(t *testing.T) {
t.Error(tags)
}

testptrstringer := &testPtrStringer{}
stringer = Stringer(testptrstringer)
if !reflect.DeepEqual(stringer, testptrstringer) {
t.Errorf("%#v != %#v", stringer, testptrstringer)
}
if s := stringer.String(); s != (&testPtrStringer{}).String() {
t.Error(s)
}
if tags := MustTagExpand(nil, stringer); !reflect.DeepEqual(tags, []any{testptrstringer}) {
t.Error(tags)
}

}
6 changes: 0 additions & 6 deletions ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import (
"github.com/linkdata/deadlock"
)

type testStringer struct{}

func (s testStringer) String() string {
return "I_Am_A_testStringer"
}

func TestRequest_NewElement_DebugPanicsIfNotComparable(t *testing.T) {
notHashableUI := struct {
*UiSpan
Expand Down

0 comments on commit 746af07

Please sign in to comment.