github.com/Aoi-hosizora/ahlib@v1.5.1-0.20230404072829-241b93cf91c7/xdefault/xdefault_test.go (about)

     1  package xdefault
     2  
     3  import (
     4  	"github.com/Aoi-hosizora/ahlib/xtesting"
     5  	"math"
     6  	"reflect"
     7  	"testing"
     8  )
     9  
    10  func TestFillDefaultFields_MassCases(t *testing.T) {
    11  	// 1. errors
    12  	t.Run("errors", func(t *testing.T) {
    13  		_, err := FillDefaultFields(nil)
    14  		xtesting.Equal(t, err != nil, true)
    15  		_, err = FillDefaultFields(0)
    16  		xtesting.Equal(t, err != nil, true)
    17  		_, err = FillDefaultFields(new(uint32))
    18  		xtesting.Equal(t, err != nil, true)
    19  		_, err = FillDefaultFields(struct{}{})
    20  		xtesting.Equal(t, err != nil, true)
    21  		_, err = FillDefaultFields(struct{ I int }{})
    22  		xtesting.Equal(t, err != nil, true)
    23  		_, err = FillDefaultFields(new(*struct{}))
    24  		xtesting.Equal(t, err != nil, true)
    25  		_, err = FillDefaultFields([]struct{}{})
    26  		xtesting.Equal(t, err != nil, true)
    27  		_, err = FillDefaultFields(map[string]struct{}{})
    28  		xtesting.Equal(t, err != nil, true)
    29  
    30  		filled, err := FillDefaultFields(&struct{}{})
    31  		xtesting.Equal(t, err == nil, true)
    32  		xtesting.Equal(t, filled, false)
    33  		filled, err = FillDefaultFields(&struct{ I int }{})
    34  		xtesting.Equal(t, err == nil, true)
    35  		xtesting.Equal(t, filled, false)
    36  		xtesting.Equal(t, filled, false)
    37  		filled, err = FillDefaultFields(new(struct{}))
    38  		xtesting.Equal(t, err == nil, true)
    39  		xtesting.Equal(t, filled, false)
    40  
    41  		xtesting.Panic(t, func() {
    42  			_, _ = FillDefaultFields(&struct {
    43  				I int `default:"a"`
    44  			}{})
    45  		})
    46  		xtesting.NotPanic(t, func() {
    47  			filled, err = FillDefaultFields(&struct {
    48  				I int `default:"1"`
    49  			}{})
    50  			xtesting.Equal(t, err == nil, true)
    51  			xtesting.Equal(t, filled, true)
    52  		})
    53  	})
    54  
    55  	// 2. coverage for unreachable cases
    56  	t.Run("unreachable", func(t *testing.T) {
    57  		xtesting.Equal(t, fillComplexField(reflect.Invalid, nil, reflect.Value{}, "", "", nil), false)
    58  		xtesting.Equal(t, fillSimpleField(reflect.Invalid, nil, reflect.Value{}, "", "", nil), false)
    59  	})
    60  }
    61  
    62  func TestFillDefaultFields_SimpleTypes(t *testing.T) {
    63  	// types
    64  	type struct1 struct {
    65  		i1 int
    66  		i2 int `default:"1"`
    67  		I3 int
    68  		I4 int `default:"1"`
    69  	}
    70  	type struct2 struct {
    71  		I1 int        `default:"-1"`
    72  		I2 int8       `default:"-2"`
    73  		I3 int16      `default:"-3"`
    74  		I4 int32      `default:"-4"`
    75  		I5 int64      `default:"-5"`
    76  		U1 uint       `default:"1"`
    77  		U2 uint8      `default:"2"`
    78  		U3 uint16     `default:"3"`
    79  		U4 uint32     `default:"4"`
    80  		U5 uint64     `default:"5"`
    81  		U6 uintptr    `default:"6"`
    82  		F1 float64    `default:"0.1"`
    83  		F2 float32    `default:"-1.2"`
    84  		B1 bool       `default:"true"`
    85  		B2 bool       `default:"false"`
    86  		C1 complex128 `default:"1+2i"`
    87  		C2 complex64  `default:"-3.4-5.6i"`
    88  		S1 string     `default:""`
    89  		S2 string     `default:"golang"`
    90  		Y1 []byte     `default:""`
    91  		Y2 []byte     `default:"GOLANG"`
    92  	}
    93  	type struct3 struct {
    94  		I  int        `default:"1.1"`
    95  		U  uint       `default:"-2"`
    96  		F  float64    `default:"three"`
    97  		C  complex128 `default:"imag"`
    98  		B1 bool       `default:"True"`
    99  		B2 bool       `default:"TRUE"`
   100  		B3 bool       `default:"t"`
   101  		B4 bool       `default:"T"`
   102  		B5 bool       `default:"x"`
   103  		B6 bool       `default:"1"`
   104  		B7 bool       `default:"2"`
   105  		B8 bool       `default:"0"`
   106  	}
   107  	type struct4 struct {
   108  		Array1    [0]int
   109  		Array2    [1]int
   110  		Slice1    []int
   111  		Slice2    []int `default:"1"`
   112  		Map1      map[string]int
   113  		Map2      map[string]int `default:"1"`
   114  		Struct    struct{}
   115  		Func      func()
   116  		Chan      chan interface{}
   117  		Interface interface{}
   118  	}
   119  
   120  	// test cases
   121  	for _, tc := range []struct {
   122  		name       string
   123  		giveStruct interface{}
   124  		wantPanic  bool
   125  		wantFilled bool
   126  		checkFunc  interface{}
   127  	}{
   128  		{"struct1", &struct1{}, false, true, func(s *struct1) bool { return s.i1 == 0 && s.i2 == 0 && s.I3 == 0 && s.I4 == 1 }},
   129  		{"struct1", &struct1{i2: 2, I4: 3}, false, false, func(s *struct1) bool { return s.i1 == 0 && s.i2 == 2 && s.I3 == 0 && s.I4 == 3 }},
   130  		{"struct2", &struct2{}, false, true, func(s *struct2) bool {
   131  			return s.I1 == -1 && s.I2 == -2 && s.I3 == -3 && s.I4 == -4 && s.I5 == -5 && s.U1 == 1 && s.U2 == 2 && s.U3 == 3 && s.U4 == 4 && s.U5 == 5 && s.U6 == 6 &&
   132  				math.Abs(s.F1-0.1) < 1e-3 && math.Abs(float64(s.F2+1.2)) < 1e-3 && s.B1 == true && s.B2 == false && s.C1 == 1+2i && s.C2 == -3.4-5.6i && s.S1 == "" && s.S2 == "golang" && string(s.Y1) == "" && string(s.Y2) == "GOLANG"
   133  		}},
   134  		{"struct2", &struct2{I1: 1, I3: 1, I5: 1, U2: 1, U4: 1, U6: 1, F2: 1, B2: true, C2: 3i, S2: ".", Y2: []byte(",")}, false, true, func(s *struct2) bool {
   135  			return s.I1 == 1 && s.I2 == -2 && s.I3 == 1 && s.I4 == -4 && s.I5 == 1 && s.U1 == 1 && s.U2 == 1 && s.U3 == 3 && s.U4 == 1 && s.U5 == 5 && s.U6 == 1 &&
   136  				math.Abs(s.F1-0.1) < 1e-3 && math.Abs(float64(s.F2-1)) < 1e-3 && s.B1 == true && s.B2 == true && s.C1 == 1+2i && s.C2 == 3i && s.S1 == "" && s.S2 == "." && string(s.Y1) == "" && string(s.Y2) == ","
   137  		}},
   138  		{"struct2", &struct2{I1: 1, I2: 1, I3: 1, I4: 1, I5: 1, U1: 1, U2: 1, U3: 1, U4: 1, U5: 1, U6: 1, F1: 1, F2: 1, B1: true, B2: true, C1: 3i, C2: 3i, S1: ".", S2: ".", Y1: []byte(","), Y2: []byte(",")}, false, false, func(s *struct2) bool {
   139  			return s.I1 == 1 && s.I2 == 1 && s.I3 == 1 && s.I4 == 1 && s.I5 == 1 && s.U1 == 1 && s.U2 == 1 && s.U3 == 1 && s.U4 == 1 && s.U5 == 1 && s.U6 == 1 &&
   140  				math.Abs(s.F1-1) < 1e-3 && math.Abs(float64(s.F2-1)) < 1e-3 && s.B1 == true && s.B2 == true && s.C1 == 3i && s.C2 == 3i && s.S1 == "." && s.S2 == "." && string(s.Y1) == "," && string(s.Y2) == ","
   141  		}},
   142  		{"struct3", &struct3{I: 1, U: 1, F: 1, C: 1}, false, true, func(s *struct3) bool { return s.B1 && s.B2 && s.B3 && s.B4 && !s.B5 && s.B6 && !s.B7 && !s.B8 }},
   143  		{"struct3", &struct3{I: 1, U: 1, F: 1, C: 1, B5: true, B7: true, B8: true}, false, true, func(s *struct3) bool { return s.B1 && s.B2 && s.B3 && s.B4 && s.B5 && s.B6 && s.B7 && s.B8 }},
   144  		{"struct3", &struct3{I: 0, U: 1, F: 1, C: 1}, true, false, nil},
   145  		{"struct3", &struct3{I: 1, U: 0, F: 1, C: 1}, true, false, nil},
   146  		{"struct3", &struct3{I: 1, U: 1, F: 0, C: 1}, true, false, nil},
   147  		{"struct3", &struct3{I: 1, U: 1, F: 1, C: 0}, true, false, nil},
   148  		{"struct4", &struct4{}, false, false, func(s *struct4) bool { return s.Array2[0] == 0 && len(s.Slice2) == 0 && len(s.Map2) == 0 }},
   149  		{"struct4", &struct4{Array2: [1]int{2}, Slice1: []int{}, Slice2: []int{}, Map1: map[string]int{}, Map2: map[string]int{}, Func: func() {}, Chan: make(chan interface{}), Interface: new(int)}, false, false, func(s *struct4) bool {
   150  			return s.Array1 == [0]int{} && s.Array2[0] == 2 && len(s.Slice1) == 0 && len(s.Slice2) == 0 && len(s.Map1) == 0 && len(s.Map2) == 0
   151  		}},
   152  		{"struct4", &struct4{Array1: [0]int{}, Array2: [1]int{0}, Slice1: []int{0}, Slice2: []int{0}}, false, true, func(s *struct4) bool {
   153  			return s.Array1 == [0]int{} && s.Array2[0] == 0 && len(s.Slice1) == 1 && s.Slice1[0] == 0 && len(s.Slice2) == 1 && s.Slice2[0] == 1
   154  		}},
   155  		{"struct4", &struct4{Array1: [0]int{}, Array2: [1]int{0}, Slice1: []int{0, 0}, Slice2: []int{0, 2, 0, 3, 0}}, false, true, func(s *struct4) bool {
   156  			return s.Array1 == [0]int{} && s.Array2[0] == 0 && len(s.Slice1) == 2 && s.Slice1[0] == 0 && s.Slice1[1] == 0 && len(s.Slice2) == 5 && s.Slice2[0] == 1 && s.Slice2[1] == 2 && s.Slice2[2] == 1 && s.Slice2[3] == 3 && s.Slice2[4] == 1
   157  		}},
   158  		{"struct4", &struct4{Map1: map[string]int{"": 0}, Map2: map[string]int{"": 0}}, false, true, func(s *struct4) bool {
   159  			return len(s.Map1) == 1 && s.Map1[""] == 0 && len(s.Map2) == 1 && s.Map2[""] == 1
   160  		}},
   161  		{"struct4", &struct4{Map1: map[string]int{"": 0, ".": 0}, Map2: map[string]int{"0": 0, "1": 2, "2": 0, "3": 3, "4": 0}}, false, true, func(s *struct4) bool {
   162  			return len(s.Map1) == 2 && s.Map1[""] == 0 && s.Map1["."] == 0 && len(s.Map2) == 5 && s.Map2["0"] == 1 && s.Map2["1"] == 2 && s.Map2["2"] == 1 && s.Map2["3"] == 3 && s.Map2["4"] == 1
   163  		}},
   164  	} {
   165  		t.Run(tc.name, func(t *testing.T) {
   166  			if tc.wantPanic {
   167  				xtesting.Panic(t, func() { _, _ = FillDefaultFields(tc.giveStruct) })
   168  			} else {
   169  				filled, err := FillDefaultFields(tc.giveStruct)
   170  				xtesting.Equal(t, err == nil, true)
   171  				xtesting.Equal(t, filled, tc.wantFilled)
   172  				if tc.checkFunc != nil {
   173  					xtesting.Equal(t, reflect.ValueOf(tc.checkFunc).Call([]reflect.Value{reflect.ValueOf(tc.giveStruct)})[0].Bool(), true)
   174  				}
   175  			}
   176  		})
   177  	}
   178  }
   179  
   180  func TestFillDefaultFields_ComplexTypes(t *testing.T) {
   181  	// types
   182  	type simpleStruct2 struct {
   183  		i int
   184  		I int        `default:"1"`
   185  		U uint       `default:"1"`
   186  		F float64    `default:"1."`
   187  		B bool       `default:"true"`
   188  		C complex128 `default:"1i"`
   189  		S string     `default:"a"`
   190  		Y []byte     `default:"bb"`
   191  	}
   192  	checkSS := func(ss simpleStruct2, i int, u uint, f float64, b bool, c complex128, s string, y string) bool {
   193  		return ss.I == i && ss.U == u && ss.F == f && ss.B == b && ss.C == c && ss.S == s && string(ss.Y) == y
   194  	}
   195  	i, u, f, b, c, s, y := 2, uint(2), 2., true, 2i, "b", []byte("aa")
   196  	p2_ := &f
   197  	p3_ := &s
   198  	p3__ := &p3_
   199  	p1, p2, p3 := &i, &p2_, &p3__
   200  	type struct5 struct {
   201  		I1 *int
   202  		U1 *uint
   203  		F1 *float64
   204  		B1 *bool
   205  		C1 *complex128
   206  		S1 *string
   207  		Y1 *[]byte
   208  		I2 *int        `default:"1"`
   209  		U2 *uint       `default:"1"`
   210  		F2 *float64    `default:"1."`
   211  		B2 *bool       `default:"true"`
   212  		C2 *complex128 `default:"1i"`
   213  		S2 *string     `default:"a"`
   214  		Y2 *[]byte     `default:"bb"`
   215  		P1 **int
   216  		P2 ***float64
   217  		P3 ****string
   218  		P4 **int      `default:"3"`
   219  		P5 ***float64 `default:"3."`
   220  		P6 ****string `default:"c"`
   221  	}
   222  	type struct6 struct {
   223  		Array1  [1]simpleStruct2
   224  		Array2  [2]*simpleStruct2
   225  		Array3  *[1]*simpleStruct2
   226  		Struct1 simpleStruct2
   227  		Struct2 *simpleStruct2
   228  		Struct3 *struct{ S *simpleStruct2 }
   229  		Slice1  []simpleStruct2
   230  		Slice2  []*simpleStruct2
   231  		Slice3  *[]*simpleStruct2
   232  		Map1    map[string]simpleStruct2
   233  		Map2    map[string]*simpleStruct2
   234  		Map3    *map[string]*simpleStruct2
   235  	}
   236  	type struct7 struct {
   237  		MapArr1 map[string][1]uint            `default:"1"`
   238  		MapArr2 map[string][2]*uint           `default:"1"`
   239  		MapArr3 *map[string]*[1]*uint         `default:"1"`
   240  		ArrMap1 [1]map[string]uint            `default:"1"`
   241  		ArrMap2 [2]map[string]*uint           `default:"1"`
   242  		ArrMap3 *[1]*map[string]*uint         `default:"1"`
   243  		MapSli1 map[string][]uint             `default:"1"`
   244  		MapSli2 map[string][]*uint            `default:"1"`
   245  		MapSli3 *map[string]*[]*uint          `default:"1"`
   246  		SliMap1 []map[string]uint             `default:"1"`
   247  		SliMap2 []map[string]*uint            `default:"1"`
   248  		SliMap3 *[]*map[string]*uint          `default:"1"`
   249  		MapMap1 map[string]map[string]uint    `default:"1"`
   250  		MapMap2 map[string]map[string]*uint   `default:"1"`
   251  		MapMap3 *map[string]*map[string]*uint `default:"1"`
   252  	}
   253  
   254  	// test cases
   255  	for _, tc := range []struct {
   256  		name       string
   257  		giveStruct interface{}
   258  		wantPanic  bool
   259  		wantFilled bool
   260  		checkFunc  interface{}
   261  	}{
   262  		{"struct5", &struct5{}, false, true, func(s *struct5) bool {
   263  			return s.I1 == nil && s.U1 == nil && s.F1 == nil && s.B1 == nil && s.C1 == nil && s.S1 == nil && s.Y1 == nil &&
   264  				*(s.I2) == 1 && *(s.U2) == 1 && *(s.F2) == 1. && *(s.B2) == true && *(s.C2) == 1i && *(s.S2) == "a" && string(*(s.Y2)) == "bb" &&
   265  				s.P1 == nil && s.P2 == nil && s.P3 == nil && **(s.P4) == 3 && ***(s.P5) == 3. && ****(s.P6) == "c"
   266  		}},
   267  		{"struct5", &struct5{I1: new(int), U1: new(uint), F1: new(float64), B1: new(bool), C1: new(complex128), S1: new(string), Y1: new([]byte)}, false, true, func(s *struct5) bool {
   268  			return *(s.I1) == 0 && *(s.U1) == 0 && *(s.F1) == 0 && *(s.B1) == false && *(s.C1) == 0 && *(s.S1) == "" && string(*(s.Y1)) == ""
   269  		}},
   270  		{"struct5", &struct5{I1: &i, U1: &u, F1: &f, B1: &b, C1: &c, S1: &s, Y1: &y, I2: nil, U2: nil, F2: nil, B2: nil, C2: nil, S2: nil, Y2: nil}, false, true, func(s *struct5) bool {
   271  			return *(s.I1) == 2 && *(s.U1) == 2 && *(s.F1) == 2. && *(s.B1) == true && *(s.C1) == 2i && *(s.S1) == "b" && string(*(s.Y1)) == "aa" && *(s.I2) == 1 && *(s.U2) == 1 && *(s.F2) == 1. && *(s.B2) == true && *(s.C2) == 1i && *(s.S2) == "a" && string(*(s.Y2)) == "bb"
   272  		}},
   273  		{"struct5", &struct5{I2: &i, U2: &u, F2: &f, B2: &b, C2: &c, S2: &s, Y2: &y}, false, true, func(s *struct5) bool {
   274  			return *(s.I2) == 2 && *(s.U2) == 2 && *(s.F2) == 2. && *(s.B2) == true && *(s.C2) == 2i && *(s.S2) == "b" && string(*(s.Y2)) == "aa"
   275  		}},
   276  		{"struct5", &struct5{P1: &p1, P2: &p2, P3: &p3, P4: nil, P5: nil, P6: nil}, false, true, func(s *struct5) bool {
   277  			return **(s.P1) == 2 && ***(s.P2) == 2. && ****(s.P3) == "b" && **(s.P4) == 3 && ***(s.P5) == 3. && ****(s.P6) == "c"
   278  		}},
   279  		{"struct5", &struct5{I2: &i, F2: &f, C2: &c, P4: &p1, P5: &p2, P6: &p3}, false, true, func(s *struct5) bool {
   280  			return *(s.I2) == 2 && *(s.U2) == 1 && *(s.F2) == 2. && *(s.B2) == true && *(s.C2) == 2i && *(s.S2) == "a" && **(s.P4) == 2 && ***(s.P5) == 2. && ****(s.P6) == "b"
   281  		}},
   282  		{"struct6", &struct6{}, false, true, func(s *struct6) bool {
   283  			return checkSS(s.Array1[0], 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Array2[0]), 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Array2[1]), 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Array3[0]), 1, 1, 1., true, 1i, "a", "bb") &&
   284  				checkSS(s.Struct1, 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Struct2), 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Struct3.S), 1, 1, 1., true, 1i, "a", "bb") &&
   285  				len(s.Slice1) == 0 && len(s.Slice2) == 0 && s.Slice3 == nil &&
   286  				len(s.Map1) == 0 && len(s.Map2) == 0 && s.Map3 == nil
   287  		}},
   288  		{"struct6", &struct6{Array1: [1]simpleStruct2{{I: 2, F: 2, C: 2i}}, Array2: [2]*simpleStruct2{{I: 2, F: 2, C: 2i}, {U: 2, B: true, S: "b", Y: []byte("aa")}}, Array3: &[1]*simpleStruct2{{I: 2, F: 2, C: 2i, U: 2, B: true, S: "b", Y: []byte("aa")}}}, false, true, func(s *struct6) bool {
   289  			return checkSS(s.Array1[0], 2, 1, 2., true, 2i, "a", "bb") && checkSS(*(s.Array2[0]), 2, 1, 2., true, 2i, "a", "bb") &&
   290  				checkSS(*(s.Array2[1]), 1, 2, 1., true, 1i, "b", "aa") && checkSS(*((*s.Array3)[0]), 2, 2, 2., true, 2i, "b", "aa")
   291  		}},
   292  		{"struct6", &struct6{Struct1: simpleStruct2{I: 2, F: 2, C: 2i}, Struct2: &simpleStruct2{U: 2, B: true, S: "b", Y: []byte("a")}, Struct3: &struct{ S *simpleStruct2 }{&simpleStruct2{I: 2, F: 2, C: 2i, U: 2, B: true, S: "b", Y: []byte("a")}}}, false, true, func(s *struct6) bool {
   293  			return checkSS(s.Struct1, 2, 1, 2., true, 2i, "a", "bb") && checkSS(*(s.Struct2), 1, 2, 1., true, 1i, "b", "a") && checkSS(*(s.Struct3.S), 2, 2, 2., true, 2i, "b", "a")
   294  		}},
   295  		{"struct6", &struct6{Slice1: []simpleStruct2{{}}, Slice2: []*simpleStruct2{{}, {}}, Slice3: &[]*simpleStruct2{{}}}, false, true, func(s *struct6) bool {
   296  			return len(s.Slice1) == 1 && len(s.Slice2) == 2 && len(*s.Slice3) == 1 &&
   297  				checkSS(s.Slice1[0], 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Slice2[0]), 1, 1, 1., true, 1i, "a", "bb") &&
   298  				checkSS(*(s.Slice2[1]), 1, 1, 1., true, 1i, "a", "bb") && checkSS(*((*s.Slice3)[0]), 1, 1, 1., true, 1i, "a", "bb")
   299  		}},
   300  		{"struct6", &struct6{Slice1: []simpleStruct2{{I: 2, F: 2, C: 2i}}, Slice2: []*simpleStruct2{{I: 2, F: 2, C: 2i}, {U: 2, B: true, S: "b", Y: []byte("aa")}}, Slice3: &[]*simpleStruct2{{I: 2, F: 2, C: 2i, U: 2, B: true, S: "b", Y: []byte("aa")}}}, false, true, func(s *struct6) bool {
   301  			return checkSS(s.Slice1[0], 2, 1, 2., true, 2i, "a", "bb") && checkSS(*(s.Slice2[0]), 2, 1, 2., true, 2i, "a", "bb") &&
   302  				checkSS(*(s.Slice2[1]), 1, 2, 1., true, 1i, "b", "aa") && checkSS(*((*s.Slice3)[0]), 2, 2, 2., true, 2i, "b", "aa")
   303  		}},
   304  		{"struct6", &struct6{Map1: map[string]simpleStruct2{"": {i: 999}}, Map2: map[string]*simpleStruct2{"": {i: 999}, ".": {}}, Map3: &map[string]*simpleStruct2{"": {i: 999}}}, false, true, func(s *struct6) bool {
   305  			return len(s.Map1) == 1 && len(s.Map2) == 2 && len(*s.Map3) == 1 && s.Map1[""].i == 999 && (*(s.Map2[""])).i == 999 && (*((*s.Map3)[""])).i == 999 &&
   306  				checkSS(s.Map1[""], 1, 1, 1., true, 1i, "a", "bb") && checkSS(*(s.Map2[""]), 1, 1, 1., true, 1i, "a", "bb") &&
   307  				checkSS(*(s.Map2["."]), 1, 1, 1., true, 1i, "a", "bb") && checkSS(*((*s.Map3)[""]), 1, 1, 1., true, 1i, "a", "bb")
   308  		}},
   309  		{"struct6", &struct6{Map1: map[string]simpleStruct2{"": {I: 2, F: 2, C: 2i}}, Map2: map[string]*simpleStruct2{"": {I: 2, F: 2, C: 2i}, ".": {U: 2, B: true, S: "b", Y: []byte("aa")}}, Map3: &map[string]*simpleStruct2{"": {I: 2, F: 2, C: 2i, U: 2, B: true, S: "b", Y: []byte("aa")}}}, false, true, func(s *struct6) bool {
   310  			return checkSS(s.Map1[""], 2, 1, 2., true, 2i, "a", "bb") && checkSS(*(s.Map2[""]), 2, 1, 2., true, 2i, "a", "bb") &&
   311  				checkSS(*(s.Map2["."]), 1, 2, 1., true, 1i, "b", "aa") && checkSS(*((*s.Map3)[""]), 2, 2, 2., true, 2i, "b", "aa")
   312  		}},
   313  		{"struct7", &struct7{}, false, false, func(s *struct7) bool {
   314  			return len(s.MapArr1) == 0 && len(s.MapArr2) == 0 && s.MapArr3 == nil && len(s.ArrMap1[0]) == 0 && len(s.ArrMap2[0]) == 0 && len(s.ArrMap2[1]) == 0 && s.ArrMap3 == nil &&
   315  				len(s.MapSli1) == 0 && len(s.MapSli2) == 0 && s.MapSli3 == nil && len(s.SliMap1) == 0 && len(s.SliMap2) == 0 && s.SliMap3 == nil &&
   316  				len(s.MapMap1) == 0 && len(s.MapMap2) == 0 && s.MapMap3 == nil
   317  		}},
   318  		{"struct7", &struct7{MapArr1: map[string][1]uint{"": {0}}, MapArr2: map[string][2]*uint{"": {nil, new(uint)}, ".": {new(uint), &u}}, MapArr3: &map[string]*[1]*uint{"": {&u}}}, false, true, func(s *struct7) bool {
   319  			return len(s.MapArr1) == 1 && len(s.MapArr2) == 2 && len(*s.MapArr3) == 1 &&
   320  				s.MapArr1[""][0] == 1 && *(s.MapArr2[""][0]) == 1 && *(s.MapArr2[""][1]) == 1 && *(s.MapArr2["."][0]) == 1 && *(s.MapArr2["."][1]) == 2 && *((*s.MapArr3)[""][0]) == 2
   321  		}},
   322  		{"struct7", &struct7{ArrMap1: [1]map[string]uint{{"": 0}}, ArrMap2: [2]map[string]*uint{{"": nil, ".": new(uint)}, {"": new(uint), ".": &u}}, ArrMap3: &[1]*map[string]*uint{{"": &u}}}, false, true, func(s *struct7) bool {
   323  			return len(s.ArrMap1[0]) == 1 && len(s.ArrMap2[0]) == 2 && len(s.ArrMap2[1]) == 2 && len(*((*s.ArrMap3)[0])) == 1 &&
   324  				s.ArrMap1[0][""] == 1 && *(s.ArrMap2[0][""]) == 1 && *(s.ArrMap2[0]["."]) == 1 && *(s.ArrMap2[1][""]) == 1 && *(s.ArrMap2[1]["."]) == 2 && *((*(*s.ArrMap3)[0])[""]) == 2
   325  		}},
   326  		{"struct7", &struct7{MapSli1: map[string][]uint{"": {0}}, MapSli2: map[string][]*uint{"": {nil, new(uint)}, ".": {new(uint), &u}}, MapSli3: &map[string]*[]*uint{"": {&u}}}, false, true, func(s *struct7) bool {
   327  			return len(s.MapSli1) == 1 && len(s.MapSli2) == 2 && len(*s.MapSli3) == 1 &&
   328  				s.MapSli1[""][0] == 1 && *(s.MapSli2[""][0]) == 1 && *(s.MapSli2[""][1]) == 1 && *(s.MapSli2["."][0]) == 1 && *(s.MapSli2["."][1]) == 2 && *((*(*s.MapSli3)[""])[0]) == 2
   329  		}},
   330  		{"struct7", &struct7{SliMap1: []map[string]uint{{"": 0}}, SliMap2: []map[string]*uint{{"": nil, ".": new(uint)}, {"": new(uint), ".": &u}}, SliMap3: &[]*map[string]*uint{{"": &u}}}, false, true, func(s *struct7) bool {
   331  			return len(s.SliMap1[0]) == 1 && len(s.SliMap2[0]) == 2 && len(s.SliMap2[1]) == 2 && len(*((*s.SliMap3)[0])) == 1 &&
   332  				s.SliMap1[0][""] == 1 && *(s.SliMap2[0][""]) == 1 && *(s.SliMap2[0]["."]) == 1 && *(s.SliMap2[1][""]) == 1 && *(s.SliMap2[1]["."]) == 2 && *((*(*s.SliMap3)[0])[""]) == 2
   333  		}},
   334  		{"struct7", &struct7{MapMap1: map[string]map[string]uint{"": {"": 0}}, MapMap2: map[string]map[string]*uint{"": {"": nil, ".": new(uint)}, ".": {"": new(uint), ".": &u}}, MapMap3: &map[string]*map[string]*uint{"": {"": &u}}}, false, true, func(s *struct7) bool {
   335  			return len(s.MapMap1) == 1 && len(s.MapMap1[""]) == 1 && len(s.MapMap2) == 2 && len(s.MapMap2[""]) == 2 && len(s.MapMap2["."]) == 2 && len(*s.MapMap3) == 1 && len(*(*s.MapMap3)[""]) == 1 &&
   336  				s.MapMap1[""][""] == 1 && *(s.MapMap2[""][""]) == 1 && *(s.MapMap2[""]["."]) == 1 && *(s.MapMap2["."][""]) == 1 && *(s.MapMap2["."]["."]) == 2 && *((*(*s.MapMap3)[""])[""]) == 2
   337  		}},
   338  	} {
   339  		t.Run(tc.name, func(t *testing.T) {
   340  			if tc.wantPanic {
   341  				xtesting.Panic(t, func() { _, _ = FillDefaultFields(tc.giveStruct) })
   342  			} else {
   343  				filled, err := FillDefaultFields(tc.giveStruct)
   344  				xtesting.Equal(t, err == nil, true)
   345  				xtesting.Equal(t, filled, tc.wantFilled)
   346  				if tc.checkFunc != nil {
   347  					xtesting.Equal(t, reflect.ValueOf(tc.checkFunc).Call([]reflect.Value{reflect.ValueOf(tc.giveStruct)})[0].Bool(), true)
   348  				}
   349  			}
   350  		})
   351  	}
   352  }