Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions structs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ func (s *Struct) IsStruct() bool {
func ToMap(v any) (map[string]any, error) {
return New(v).ToMap()
}

// TypeName return struct type name
func (s *Struct) TypeName() string {
return s.rtype.Name()
}
18 changes: 18 additions & 0 deletions structs/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,21 @@ func TestStruct_IsStruct(t *testing.T) {
assert.Equal(true, s1.IsStruct())
assert.Equal(false, s2.IsStruct())
}

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

assert := internal.NewAssert(t, "TestStruct_TypeName")

type Test1 struct{}
t1 := &Test1{}

s1 := New(t1)
assert.Equal("Test1", s1.TypeName())

type Test2 struct{}
t2 := Test2{}

s2 := New(t2)
assert.Equal("Test2", s2.TypeName())
}
Loading