Bladeren bron

修改bug

yjp 4 maanden geleden
bovenliggende
commit
18a68cf3f3
2 gewijzigde bestanden met toevoegingen van 14 en 1 verwijderingen
  1. 1 1
      framework/core/tag/assign/tag.go
  2. 13 0
      test/assign_tag_test.go

+ 1 - 1
framework/core/tag/assign/tag.go

@@ -93,7 +93,7 @@ func parseTag(fromElemValue reflect.Value, toElemValue *reflect.Value, onParsedF
 
 		toFieldElemValue := toFieldValue
 		if toFieldValue.Kind() == reflect.Pointer {
-			if fromFieldElemValue.IsZero() {
+			if fromFieldValue.Kind() == reflect.Pointer && fromFieldValue.IsNil() {
 				continue
 			}
 

+ 13 - 0
test/assign_tag_test.go

@@ -1,6 +1,7 @@
 package test
 
 import (
+	"fmt"
 	"git.sxidc.com/go-framework/baize/framework/core/tag/assign"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/pkg/errors"
@@ -307,6 +308,8 @@ func (to AssignTagToPointerField) checkFields(t *testing.T, from AssignTagFrom)
 			from.StringField, *to.StringField))
 	}
 
+	fmt.Println("from", from.BoolField)
+	fmt.Println("to", to.BoolField)
 	if from.BoolField != *to.BoolField {
 		t.Fatalf("%+v\n", errors.Errorf("BoolField not equal: from %v, to %v",
 			from.BoolField, *to.BoolField))
@@ -747,6 +750,7 @@ type AssignTagFromSlice struct {
 	FuncPointerSliceField        []*func() string     `assign:"toField:FuncPointerSliceField"`
 	FromStringSliceToStringField []string             `assign:"toField:FromStringSliceToStringField"`
 	FromTimeToStringField        []time.Time          `assign:"toField:FromTimeToStringField"`
+	FromStringToTimeField        []string             `assign:"toField:FromStringToTimeField"`
 }
 
 type AssignTagFromSlicePointerField struct {
@@ -765,6 +769,7 @@ type AssignTagFromSlicePointerField struct {
 	FuncPointerSliceField        *[]*func() string     `assign:"toField:FuncPointerSliceField"`
 	FromStringSliceToStringField *[]string             `assign:"toField:FromStringSliceToStringField"`
 	FromTimeToStringField        *[]time.Time          `assign:"toField:FromTimeToStringField"`
+	FromStringToTimeField        *[]string             `assign:"toField:FromStringToTimeField"`
 }
 
 type AssignTagToSlice struct {
@@ -783,6 +788,7 @@ type AssignTagToSlice struct {
 	FuncPointerSliceField        []*func() string
 	FromStringSliceToStringField string
 	FromTimeToStringField        string
+	FromStringToTimeField        []time.Time
 }
 
 func (to AssignTagToSlice) checkFields(t *testing.T, from AssignTagFromSlice) {
@@ -964,6 +970,7 @@ type AssignTagToSlicePointerField struct {
 	FuncPointerSliceField        *[]*func() string
 	FromStringSliceToStringField *string
 	FromTimeToStringField        *string
+	FromStringToTimeField        []time.Time
 }
 
 func (to AssignTagToSlicePointerField) checkFields(t *testing.T, from AssignTagFromSlice) {
@@ -1204,6 +1211,8 @@ func TestAssignTagDefaultUsageSlice(t *testing.T) {
 	chanPointerSliceField := []*chan any{&chan1, &chan2}
 	funcPointerSliceField := []*func() string{&func1, &func2}
 	fromStringSliceToStringField := []string{str1, str2}
+	fromTimeToStringField := []time.Time{time1, time2}
+	fromStringToTimeField := []string{time1.Format(time.DateTime), time2.Format(time.DateTime)}
 
 	from := AssignTagFromSlice{
 		BasicField:                   basicField,
@@ -1220,6 +1229,8 @@ func TestAssignTagDefaultUsageSlice(t *testing.T) {
 		ChanPointerSliceField:        chanPointerSliceField,
 		FuncPointerSliceField:        funcPointerSliceField,
 		FromStringSliceToStringField: fromStringSliceToStringField,
+		FromTimeToStringField:        fromTimeToStringField,
+		FromStringToTimeField:        fromStringToTimeField,
 	}
 
 	fromPointer := AssignTagFromSlicePointerField{
@@ -1237,6 +1248,8 @@ func TestAssignTagDefaultUsageSlice(t *testing.T) {
 		ChanPointerSliceField:        &chanPointerSliceField,
 		FuncPointerSliceField:        &funcPointerSliceField,
 		FromStringSliceToStringField: &fromStringSliceToStringField,
+		FromTimeToStringField:        &fromTimeToStringField,
+		FromStringToTimeField:        &fromStringToTimeField,
 	}
 
 	fromPointerNil := AssignTagFromPointerField{}