mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
feat(struct): add struct name function (#328)
* feat(struct): add struct name function - Add Name() method to Struct type to return the struct name - Implement unit tests for the new Name() method * refactor(structs): rename Struct.Name to Struct.TypeName - Rename method Name to TypeName for clarity and accuracy - Update corresponding test cases
This commit is contained in:
@@ -122,3 +122,8 @@ func (s *Struct) IsStruct() bool {
|
|||||||
func ToMap(v any) (map[string]any, error) {
|
func ToMap(v any) (map[string]any, error) {
|
||||||
return New(v).ToMap()
|
return New(v).ToMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypeName return struct type name
|
||||||
|
func (s *Struct) TypeName() string {
|
||||||
|
return s.rtype.Name()
|
||||||
|
}
|
||||||
|
|||||||
@@ -177,3 +177,21 @@ func TestStruct_IsStruct(t *testing.T) {
|
|||||||
assert.Equal(true, s1.IsStruct())
|
assert.Equal(true, s1.IsStruct())
|
||||||
assert.Equal(false, s2.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())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user