fix: type matching supports string to int (#2038)
* fix: type matching supports string to int * feat: type matching supports string to int Co-authored-by: 程家福 <chengjiafu@uniontech.com>
This commit is contained in:
@@ -15,7 +15,7 @@ type Foo struct {
|
||||
StrWithTagAndOption string `key:"stringwithtag,string"`
|
||||
}
|
||||
|
||||
func TestDeferInt(t *testing.T) {
|
||||
func TestDerefInt(t *testing.T) {
|
||||
i := 1
|
||||
s := "hello"
|
||||
number := struct {
|
||||
@@ -60,6 +60,51 @@ func TestDeferInt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDerefValInt(t *testing.T) {
|
||||
i := 1
|
||||
s := "hello"
|
||||
number := struct {
|
||||
f float64
|
||||
}{
|
||||
f: 6.4,
|
||||
}
|
||||
cases := []struct {
|
||||
t reflect.Value
|
||||
expect reflect.Kind
|
||||
}{
|
||||
{
|
||||
t: reflect.ValueOf(i),
|
||||
expect: reflect.Int,
|
||||
},
|
||||
{
|
||||
t: reflect.ValueOf(&i),
|
||||
expect: reflect.Int,
|
||||
},
|
||||
{
|
||||
t: reflect.ValueOf(s),
|
||||
expect: reflect.String,
|
||||
},
|
||||
{
|
||||
t: reflect.ValueOf(&s),
|
||||
expect: reflect.String,
|
||||
},
|
||||
{
|
||||
t: reflect.ValueOf(number.f),
|
||||
expect: reflect.Float64,
|
||||
},
|
||||
{
|
||||
t: reflect.ValueOf(&number.f),
|
||||
expect: reflect.Float64,
|
||||
},
|
||||
}
|
||||
|
||||
for _, each := range cases {
|
||||
t.Run(each.t.String(), func(t *testing.T) {
|
||||
assert.Equal(t, each.expect, DerefVal(each.t).Kind())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseKeyAndOptionWithoutTag(t *testing.T) {
|
||||
var foo Foo
|
||||
rte := reflect.TypeOf(&foo).Elem()
|
||||
|
||||
Reference in New Issue
Block a user