@@ -18,11 +18,17 @@ type InnerObject struct {
1818 Name string
1919 ID int
2020}
21+
2122type InnerObject2 struct {
2223 Foo string
2324 Is bool
2425}
2526
27+ type InnerObject3 struct {
28+ Foo string
29+ Count * int
30+ }
31+
2632// These are all possible field types, mandatory and optional.
2733type AllFields struct {
2834 I int `json:"i"`
@@ -36,6 +42,7 @@ type AllFields struct {
3642 Oas * []string `json:"oas,omitempty"`
3743 O InnerObject `json:"o"`
3844 Ao []InnerObject2 `json:"ao"`
45+ Aop * []InnerObject3 `json:"aop"`
3946 Onas InnerArrayObject `json:"onas"`
4047 Oo * InnerObject `json:"oo,omitempty"`
4148 D MockBinder `json:"d"`
@@ -58,6 +65,9 @@ func TestDeepObject(t *testing.T) {
5865 }
5966 d := MockBinder {Time : time .Date (2020 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC )}
6067
68+ one := 1
69+ two := 1
70+
6171 srcObj := AllFields {
6272 I : 12 ,
6373 Oi : & oi ,
@@ -76,6 +86,10 @@ func TestDeepObject(t *testing.T) {
7686 {Foo : "bar" , Is : true },
7787 {Foo : "baz" , Is : false },
7888 },
89+ Aop : & []InnerObject3 {
90+ {Foo : "a" , Count : & one },
91+ {Foo : "b" , Count : & two },
92+ },
7993 Onas : InnerArrayObject {
8094 Names : []string {"Bill" , "Frank" },
8195 },
@@ -88,7 +102,7 @@ func TestDeepObject(t *testing.T) {
88102
89103 marshaled , err := MarshalDeepObject (srcObj , "p" )
90104 require .NoError (t , err )
91- require .EqualValues (t , "p[ab][0]=true&p[ao][0][Foo]=bar&p[ao][0][Is]=true&p[ao][1][Foo]=baz&p[ao][1][Is]=false&p[as][0]=hello&p[as][1]=world&p[b]=true&p[d]=2020-02-01&p[f]=4.2&p[i]=12&p[m][additional]=1&p[o][ID]=456&p[o][Name]=Joe Schmoe&p[oas][0]=foo&p[oas][1]=bar&p[ob]=true&p[od]=2020-02-01&p[of]=3.7&p[oi]=5&p[om][additional]=1&p[onas][names][0]=Bill&p[onas][names][1]=Frank&p[oo][ID]=123&p[oo][Name]=Marcin Romaszewicz" , marshaled )
105+ require .EqualValues (t , "p[ab][0]=true&p[ao][0][Foo]=bar&p[ao][0][Is]=true&p[ao][1][Foo]=baz&p[ao][1][Is]=false&p[aop][0][Count]=1&p[aop][0][Foo]=a&p[aop][1][Count]=1&p[aop][1][Foo]=b&p[ as][0]=hello&p[as][1]=world&p[b]=true&p[d]=2020-02-01&p[f]=4.2&p[i]=12&p[m][additional]=1&p[o][ID]=456&p[o][Name]=Joe Schmoe&p[oas][0]=foo&p[oas][1]=bar&p[ob]=true&p[od]=2020-02-01&p[of]=3.7&p[oi]=5&p[om][additional]=1&p[onas][names][0]=Bill&p[onas][names][1]=Frank&p[oo][ID]=123&p[oo][Name]=Marcin Romaszewicz" , marshaled )
92106
93107 params := make (url.Values )
94108 marshaledParts := strings .Split (marshaled , "&" )
0 commit comments