1 package json_test
2
3 import (
4 "bytes"
5 "fmt"
6 "testing"
7
8 "github.com/goccy/go-json"
9 )
10
11 func TestCoverArray(t *testing.T) {
12 type structArray struct {
13 A [2]int `json:"a"`
14 }
15 type structArrayOmitEmpty struct {
16 A [2]int `json:"a,omitempty"`
17 }
18 type structArrayString struct {
19 A [2]int `json:"a,string"`
20 }
21 type structArrayPtr struct {
22 A *[2]int `json:"a"`
23 }
24 type structArrayPtrOmitEmpty struct {
25 A *[2]int `json:"a,omitempty"`
26 }
27 type structArrayPtrString struct {
28 A *[2]int `json:"a,string"`
29 }
30
31 type structArrayPtrContent struct {
32 A [2]*int `json:"a"`
33 }
34 type structArrayOmitEmptyPtrContent struct {
35 A [2]*int `json:"a,omitempty"`
36 }
37 type structArrayStringPtrContent struct {
38 A [2]*int `json:"a,string"`
39 }
40 type structArrayPtrPtrContent struct {
41 A *[2]*int `json:"a"`
42 }
43 type structArrayPtrOmitEmptyPtrContent struct {
44 A *[2]*int `json:"a,omitempty"`
45 }
46 type structArrayPtrStringPtrContent struct {
47 A *[2]*int `json:"a,string"`
48 }
49
50 tests := []struct {
51 name string
52 data interface{}
53 }{
54
55 {
56 name: "HeadArrayZero",
57 data: struct {
58 A [2]int `json:"a"`
59 }{},
60 },
61 {
62 name: "HeadArrayZeroOmitEmpty",
63 data: struct {
64 A [2]int `json:"a,omitempty"`
65 }{},
66 },
67 {
68 name: "HeadArrayZeroString",
69 data: struct {
70 A [2]int `json:"a,string"`
71 }{},
72 },
73
74
75 {
76 name: "HeadArray",
77 data: struct {
78 A [2]int `json:"a"`
79 }{A: [2]int{-1}},
80 },
81 {
82 name: "HeadArrayOmitEmpty",
83 data: struct {
84 A [2]int `json:"a,omitempty"`
85 }{A: [2]int{-1}},
86 },
87 {
88 name: "HeadArrayString",
89 data: struct {
90 A [2]int `json:"a,string"`
91 }{A: [2]int{-1}},
92 },
93
94
95 {
96 name: "HeadArrayPtr",
97 data: struct {
98 A *[2]int `json:"a"`
99 }{A: arrayptr([2]int{-1})},
100 },
101 {
102 name: "HeadArrayPtrOmitEmpty",
103 data: struct {
104 A *[2]int `json:"a,omitempty"`
105 }{A: arrayptr([2]int{-1})},
106 },
107 {
108 name: "HeadArrayPtrString",
109 data: struct {
110 A *[2]int `json:"a,string"`
111 }{A: arrayptr([2]int{-1})},
112 },
113
114
115 {
116 name: "HeadArrayPtrNil",
117 data: struct {
118 A *[2]int `json:"a"`
119 }{A: nil},
120 },
121 {
122 name: "HeadArrayPtrNilOmitEmpty",
123 data: struct {
124 A *[2]int `json:"a,omitempty"`
125 }{A: nil},
126 },
127 {
128 name: "HeadArrayPtrNilString",
129 data: struct {
130 A *[2]int `json:"a,string"`
131 }{A: nil},
132 },
133
134
135 {
136 name: "PtrHeadArrayZero",
137 data: &struct {
138 A [2]int `json:"a"`
139 }{},
140 },
141 {
142 name: "PtrHeadArrayZeroOmitEmpty",
143 data: &struct {
144 A [2]int `json:"a,omitempty"`
145 }{},
146 },
147 {
148 name: "PtrHeadArrayZeroString",
149 data: &struct {
150 A [2]int `json:"a,string"`
151 }{},
152 },
153
154
155 {
156 name: "PtrHeadArray",
157 data: &struct {
158 A [2]int `json:"a"`
159 }{A: [2]int{-1}},
160 },
161 {
162 name: "PtrHeadArrayOmitEmpty",
163 data: &struct {
164 A [2]int `json:"a,omitempty"`
165 }{A: [2]int{-1}},
166 },
167 {
168 name: "PtrHeadArrayString",
169 data: &struct {
170 A [2]int `json:"a,string"`
171 }{A: [2]int{-1}},
172 },
173
174
175 {
176 name: "PtrHeadArrayPtr",
177 data: &struct {
178 A *[2]int `json:"a"`
179 }{A: arrayptr([2]int{-1})},
180 },
181 {
182 name: "PtrHeadArrayPtrOmitEmpty",
183 data: &struct {
184 A *[2]int `json:"a,omitempty"`
185 }{A: arrayptr([2]int{-1})},
186 },
187 {
188 name: "PtrHeadArrayPtrString",
189 data: &struct {
190 A *[2]int `json:"a,string"`
191 }{A: arrayptr([2]int{-1})},
192 },
193
194
195 {
196 name: "PtrHeadArrayPtrNil",
197 data: &struct {
198 A *[2]int `json:"a"`
199 }{A: nil},
200 },
201 {
202 name: "PtrHeadArrayPtrNilOmitEmpty",
203 data: &struct {
204 A *[2]int `json:"a,omitempty"`
205 }{A: nil},
206 },
207 {
208 name: "PtrHeadArrayPtrNilString",
209 data: &struct {
210 A *[2]int `json:"a,string"`
211 }{A: nil},
212 },
213
214
215 {
216 name: "PtrHeadArrayNil",
217 data: (*struct {
218 A *[2]int `json:"a"`
219 })(nil),
220 },
221 {
222 name: "PtrHeadArrayNilOmitEmpty",
223 data: (*struct {
224 A *[2]int `json:"a,omitempty"`
225 })(nil),
226 },
227 {
228 name: "PtrHeadArrayNilString",
229 data: (*struct {
230 A *[2]int `json:"a,string"`
231 })(nil),
232 },
233
234
235 {
236 name: "HeadArrayZeroMultiFields",
237 data: struct {
238 A [2]int `json:"a"`
239 B [2]int `json:"b"`
240 C [2]int `json:"c"`
241 }{},
242 },
243 {
244 name: "HeadArrayZeroMultiFieldsOmitEmpty",
245 data: struct {
246 A [2]int `json:"a,omitempty"`
247 B [2]int `json:"b,omitempty"`
248 C [2]int `json:"c,omitempty"`
249 }{},
250 },
251 {
252 name: "HeadArrayZeroMultiFields",
253 data: struct {
254 A [2]int `json:"a,string"`
255 B [2]int `json:"b,string"`
256 C [2]int `json:"c,string"`
257 }{},
258 },
259
260
261 {
262 name: "HeadArrayMultiFields",
263 data: struct {
264 A [2]int `json:"a"`
265 B [2]int `json:"b"`
266 C [2]int `json:"c"`
267 }{A: [2]int{-1}, B: [2]int{-2}, C: [2]int{-3}},
268 },
269 {
270 name: "HeadArrayMultiFieldsOmitEmpty",
271 data: struct {
272 A [2]int `json:"a,omitempty"`
273 B [2]int `json:"b,omitempty"`
274 C [2]int `json:"c,omitempty"`
275 }{A: [2]int{-1}, B: [2]int{-2}, C: [2]int{-3}},
276 },
277 {
278 name: "HeadArrayMultiFieldsString",
279 data: struct {
280 A [2]int `json:"a,string"`
281 B [2]int `json:"b,string"`
282 C [2]int `json:"c,string"`
283 }{A: [2]int{-1}, B: [2]int{-2}, C: [2]int{-3}},
284 },
285
286
287 {
288 name: "HeadArrayPtrMultiFields",
289 data: struct {
290 A *[2]int `json:"a"`
291 B *[2]int `json:"b"`
292 C *[2]int `json:"c"`
293 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{-2}), C: arrayptr([2]int{-3})},
294 },
295 {
296 name: "HeadArrayPtrMultiFieldsOmitEmpty",
297 data: struct {
298 A *[2]int `json:"a,omitempty"`
299 B *[2]int `json:"b,omitempty"`
300 C *[2]int `json:"c,omitempty"`
301 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{-2}), C: arrayptr([2]int{-3})},
302 },
303 {
304 name: "HeadArrayPtrMultiFieldsString",
305 data: struct {
306 A *[2]int `json:"a,string"`
307 B *[2]int `json:"b,string"`
308 C *[2]int `json:"c,string"`
309 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{-2}), C: arrayptr([2]int{-3})},
310 },
311
312
313 {
314 name: "HeadArrayPtrNilMultiFields",
315 data: struct {
316 A *[2]int `json:"a"`
317 B *[2]int `json:"b"`
318 C *[2]int `json:"c"`
319 }{A: nil, B: nil, C: nil},
320 },
321 {
322 name: "HeadArrayPtrNilMultiFieldsOmitEmpty",
323 data: struct {
324 A *[2]int `json:"a,omitempty"`
325 B *[2]int `json:"b,omitempty"`
326 C *[2]int `json:"c,omitempty"`
327 }{A: nil, B: nil, C: nil},
328 },
329 {
330 name: "HeadArrayPtrNilMultiFieldsString",
331 data: struct {
332 A *[2]int `json:"a,string"`
333 B *[2]int `json:"b,string"`
334 C *[2]int `json:"c,string"`
335 }{A: nil, B: nil, C: nil},
336 },
337
338
339 {
340 name: "PtrHeadArrayZeroMultiFields",
341 data: &struct {
342 A [2]int `json:"a"`
343 B [2]int `json:"b"`
344 }{},
345 },
346 {
347 name: "PtrHeadArrayZeroMultiFieldsOmitEmpty",
348 data: &struct {
349 A [2]int `json:"a,omitempty"`
350 B [2]int `json:"b,omitempty"`
351 }{},
352 },
353 {
354 name: "PtrHeadArrayZeroMultiFieldsString",
355 data: &struct {
356 A [2]int `json:"a,string"`
357 B [2]int `json:"b,string"`
358 }{},
359 },
360
361
362 {
363 name: "PtrHeadArrayMultiFields",
364 data: &struct {
365 A [2]int `json:"a"`
366 B [2]int `json:"b"`
367 }{A: [2]int{-1}, B: [2]int{1}},
368 },
369 {
370 name: "PtrHeadArrayMultiFieldsOmitEmpty",
371 data: &struct {
372 A [2]int `json:"a,omitempty"`
373 B [2]int `json:"b,omitempty"`
374 }{A: [2]int{-1}, B: [2]int{1}},
375 },
376 {
377 name: "PtrHeadArrayMultiFieldsString",
378 data: &struct {
379 A [2]int `json:"a,string"`
380 B [2]int `json:"b,string"`
381 }{A: [2]int{-1}, B: [2]int{1}},
382 },
383
384
385 {
386 name: "PtrHeadArrayPtrMultiFields",
387 data: &struct {
388 A *[2]int `json:"a"`
389 B *[2]int `json:"b"`
390 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{-2})},
391 },
392 {
393 name: "PtrHeadArrayPtrMultiFieldsOmitEmpty",
394 data: &struct {
395 A *[2]int `json:"a,omitempty"`
396 B *[2]int `json:"b,omitempty"`
397 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{-2})},
398 },
399 {
400 name: "PtrHeadArrayPtrMultiFieldsString",
401 data: &struct {
402 A *[2]int `json:"a,string"`
403 B *[2]int `json:"b,string"`
404 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{-2})},
405 },
406
407
408 {
409 name: "PtrHeadArrayPtrNilMultiFields",
410 data: &struct {
411 A *[2]int `json:"a"`
412 B *[2]int `json:"b"`
413 }{A: nil, B: nil},
414 },
415 {
416 name: "PtrHeadArrayPtrNilMultiFieldsOmitEmpty",
417 data: &struct {
418 A *[2]int `json:"a,omitempty"`
419 B *[2]int `json:"b,omitempty"`
420 }{A: nil, B: nil},
421 },
422 {
423 name: "PtrHeadArrayPtrNilMultiFieldsString",
424 data: &struct {
425 A *[2]int `json:"a,string"`
426 B *[2]int `json:"b,string"`
427 }{A: nil, B: nil},
428 },
429
430
431 {
432 name: "PtrHeadArrayNilMultiFields",
433 data: (*struct {
434 A [2]int `json:"a"`
435 B [2]int `json:"b"`
436 })(nil),
437 },
438 {
439 name: "PtrHeadArrayNilMultiFieldsOmitEmpty",
440 data: (*struct {
441 A [2]int `json:"a,omitempty"`
442 B [2]int `json:"b,omitempty"`
443 })(nil),
444 },
445 {
446 name: "PtrHeadArrayNilMultiFieldsString",
447 data: (*struct {
448 A [2]int `json:"a,string"`
449 B [2]int `json:"b,string"`
450 })(nil),
451 },
452
453
454 {
455 name: "PtrHeadArrayNilMultiFields",
456 data: (*struct {
457 A *[2]int `json:"a"`
458 B *[2]int `json:"b"`
459 })(nil),
460 },
461 {
462 name: "PtrHeadArrayNilMultiFieldsOmitEmpty",
463 data: (*struct {
464 A *[2]int `json:"a,omitempty"`
465 B *[2]int `json:"b,omitempty"`
466 })(nil),
467 },
468 {
469 name: "PtrHeadArrayNilMultiFieldsString",
470 data: (*struct {
471 A *[2]int `json:"a,string"`
472 B *[2]int `json:"b,string"`
473 })(nil),
474 },
475
476
477 {
478 name: "HeadArrayZeroNotRoot",
479 data: struct {
480 A struct {
481 A [2]int `json:"a"`
482 }
483 }{},
484 },
485 {
486 name: "HeadArrayZeroNotRootOmitEmpty",
487 data: struct {
488 A struct {
489 A [2]int `json:"a,omitempty"`
490 }
491 }{},
492 },
493 {
494 name: "HeadArrayZeroNotRootString",
495 data: struct {
496 A struct {
497 A [2]int `json:"a,string"`
498 }
499 }{},
500 },
501
502
503 {
504 name: "HeadArrayNotRoot",
505 data: struct {
506 A struct {
507 A [2]int `json:"a"`
508 }
509 }{A: struct {
510 A [2]int `json:"a"`
511 }{A: [2]int{-1}}},
512 },
513 {
514 name: "HeadArrayNotRootOmitEmpty",
515 data: struct {
516 A struct {
517 A [2]int `json:"a,omitempty"`
518 }
519 }{A: struct {
520 A [2]int `json:"a,omitempty"`
521 }{A: [2]int{-1}}},
522 },
523 {
524 name: "HeadArrayNotRootString",
525 data: struct {
526 A struct {
527 A [2]int `json:"a,string"`
528 }
529 }{A: struct {
530 A [2]int `json:"a,string"`
531 }{A: [2]int{-1}}},
532 },
533
534
535 {
536 name: "HeadArrayPtrNotRoot",
537 data: struct {
538 A struct {
539 A *[2]int `json:"a"`
540 }
541 }{A: struct {
542 A *[2]int `json:"a"`
543 }{arrayptr([2]int{-1})}},
544 },
545 {
546 name: "HeadArrayPtrNotRootOmitEmpty",
547 data: struct {
548 A struct {
549 A *[2]int `json:"a,omitempty"`
550 }
551 }{A: struct {
552 A *[2]int `json:"a,omitempty"`
553 }{arrayptr([2]int{-1})}},
554 },
555 {
556 name: "HeadArrayPtrNotRootString",
557 data: struct {
558 A struct {
559 A *[2]int `json:"a,string"`
560 }
561 }{A: struct {
562 A *[2]int `json:"a,string"`
563 }{arrayptr([2]int{-1})}},
564 },
565
566
567 {
568 name: "HeadArrayPtrNilNotRoot",
569 data: struct {
570 A struct {
571 A *[2]int `json:"a"`
572 }
573 }{},
574 },
575 {
576 name: "HeadArrayPtrNilNotRootOmitEmpty",
577 data: struct {
578 A struct {
579 A *[2]int `json:"a,omitempty"`
580 }
581 }{},
582 },
583 {
584 name: "HeadArrayPtrNilNotRootString",
585 data: struct {
586 A struct {
587 A *[2]int `json:"a,string"`
588 }
589 }{},
590 },
591
592
593 {
594 name: "PtrHeadArrayZeroNotRoot",
595 data: struct {
596 A *struct {
597 A [2]int `json:"a"`
598 }
599 }{A: new(struct {
600 A [2]int `json:"a"`
601 })},
602 },
603 {
604 name: "PtrHeadArrayZeroNotRootOmitEmpty",
605 data: struct {
606 A *struct {
607 A [2]int `json:"a,omitempty"`
608 }
609 }{A: new(struct {
610 A [2]int `json:"a,omitempty"`
611 })},
612 },
613 {
614 name: "PtrHeadArrayZeroNotRootString",
615 data: struct {
616 A *struct {
617 A [2]int `json:"a,string"`
618 }
619 }{A: new(struct {
620 A [2]int `json:"a,string"`
621 })},
622 },
623
624
625 {
626 name: "PtrHeadArrayNotRoot",
627 data: struct {
628 A *struct {
629 A [2]int `json:"a"`
630 }
631 }{A: &(struct {
632 A [2]int `json:"a"`
633 }{A: [2]int{-1}})},
634 },
635 {
636 name: "PtrHeadArrayNotRootOmitEmpty",
637 data: struct {
638 A *struct {
639 A [2]int `json:"a,omitempty"`
640 }
641 }{A: &(struct {
642 A [2]int `json:"a,omitempty"`
643 }{A: [2]int{-1}})},
644 },
645 {
646 name: "PtrHeadArrayNotRootString",
647 data: struct {
648 A *struct {
649 A [2]int `json:"a,string"`
650 }
651 }{A: &(struct {
652 A [2]int `json:"a,string"`
653 }{A: [2]int{-1}})},
654 },
655
656
657 {
658 name: "PtrHeadArrayPtrNotRoot",
659 data: struct {
660 A *struct {
661 A *[2]int `json:"a"`
662 }
663 }{A: &(struct {
664 A *[2]int `json:"a"`
665 }{A: arrayptr([2]int{-1})})},
666 },
667 {
668 name: "PtrHeadArrayPtrNotRootOmitEmpty",
669 data: struct {
670 A *struct {
671 A *[2]int `json:"a,omitempty"`
672 }
673 }{A: &(struct {
674 A *[2]int `json:"a,omitempty"`
675 }{A: arrayptr([2]int{-1})})},
676 },
677 {
678 name: "PtrHeadArrayPtrNotRootString",
679 data: struct {
680 A *struct {
681 A *[2]int `json:"a,string"`
682 }
683 }{A: &(struct {
684 A *[2]int `json:"a,string"`
685 }{A: arrayptr([2]int{-1})})},
686 },
687
688
689 {
690 name: "PtrHeadArrayPtrNilNotRoot",
691 data: struct {
692 A *struct {
693 A *[2]int `json:"a"`
694 }
695 }{A: &(struct {
696 A *[2]int `json:"a"`
697 }{A: nil})},
698 },
699 {
700 name: "PtrHeadArrayPtrNilNotRootOmitEmpty",
701 data: struct {
702 A *struct {
703 A *[2]int `json:"a,omitempty"`
704 }
705 }{A: &(struct {
706 A *[2]int `json:"a,omitempty"`
707 }{A: nil})},
708 },
709 {
710 name: "PtrHeadArrayPtrNilNotRootString",
711 data: struct {
712 A *struct {
713 A *[2]int `json:"a,string"`
714 }
715 }{A: &(struct {
716 A *[2]int `json:"a,string"`
717 }{A: nil})},
718 },
719
720
721 {
722 name: "PtrHeadArrayNilNotRoot",
723 data: struct {
724 A *struct {
725 A *[2]int `json:"a"`
726 }
727 }{A: nil},
728 },
729 {
730 name: "PtrHeadArrayNilNotRootOmitEmpty",
731 data: struct {
732 A *struct {
733 A *[2]int `json:"a,omitempty"`
734 } `json:",omitempty"`
735 }{A: nil},
736 },
737 {
738 name: "PtrHeadArrayNilNotRootString",
739 data: struct {
740 A *struct {
741 A *[2]int `json:"a,string"`
742 } `json:",string"`
743 }{A: nil},
744 },
745
746
747 {
748 name: "HeadArrayZeroMultiFieldsNotRoot",
749 data: struct {
750 A struct {
751 A [2]int `json:"a"`
752 }
753 B struct {
754 B [2]int `json:"b"`
755 }
756 }{},
757 },
758 {
759 name: "HeadArrayZeroMultiFieldsNotRootOmitEmpty",
760 data: struct {
761 A struct {
762 A [2]int `json:"a,omitempty"`
763 }
764 B struct {
765 B [2]int `json:"b,omitempty"`
766 }
767 }{},
768 },
769 {
770 name: "HeadArrayZeroMultiFieldsNotRootString",
771 data: struct {
772 A struct {
773 A [2]int `json:"a,string"`
774 }
775 B struct {
776 B [2]int `json:"b,string"`
777 }
778 }{},
779 },
780
781
782 {
783 name: "HeadArrayMultiFieldsNotRoot",
784 data: struct {
785 A struct {
786 A [2]int `json:"a"`
787 }
788 B struct {
789 B [2]int `json:"b"`
790 }
791 }{A: struct {
792 A [2]int `json:"a"`
793 }{A: [2]int{-1}}, B: struct {
794 B [2]int `json:"b"`
795 }{B: [2]int{0}}},
796 },
797 {
798 name: "HeadArrayMultiFieldsNotRootOmitEmpty",
799 data: struct {
800 A struct {
801 A [2]int `json:"a,omitempty"`
802 }
803 B struct {
804 B [2]int `json:"b,omitempty"`
805 }
806 }{A: struct {
807 A [2]int `json:"a,omitempty"`
808 }{A: [2]int{-1}}, B: struct {
809 B [2]int `json:"b,omitempty"`
810 }{B: [2]int{1}}},
811 },
812 {
813 name: "HeadArrayMultiFieldsNotRootString",
814 data: struct {
815 A struct {
816 A [2]int `json:"a,string"`
817 }
818 B struct {
819 B [2]int `json:"b,string"`
820 }
821 }{A: struct {
822 A [2]int `json:"a,string"`
823 }{A: [2]int{-1}}, B: struct {
824 B [2]int `json:"b,string"`
825 }{B: [2]int{1}}},
826 },
827
828
829 {
830 name: "HeadArrayPtrMultiFieldsNotRoot",
831 data: struct {
832 A struct {
833 A *[2]int `json:"a"`
834 }
835 B struct {
836 B *[2]int `json:"b"`
837 }
838 }{A: struct {
839 A *[2]int `json:"a"`
840 }{A: arrayptr([2]int{-1})}, B: struct {
841 B *[2]int `json:"b"`
842 }{B: arrayptr([2]int{1})}},
843 },
844 {
845 name: "HeadArrayPtrMultiFieldsNotRootOmitEmpty",
846 data: struct {
847 A struct {
848 A *[2]int `json:"a,omitempty"`
849 }
850 B struct {
851 B *[2]int `json:"b,omitempty"`
852 }
853 }{A: struct {
854 A *[2]int `json:"a,omitempty"`
855 }{A: arrayptr([2]int{-1})}, B: struct {
856 B *[2]int `json:"b,omitempty"`
857 }{B: arrayptr([2]int{1})}},
858 },
859 {
860 name: "HeadArrayPtrMultiFieldsNotRootString",
861 data: struct {
862 A struct {
863 A *[2]int `json:"a,string"`
864 }
865 B struct {
866 B *[2]int `json:"b,string"`
867 }
868 }{A: struct {
869 A *[2]int `json:"a,string"`
870 }{A: arrayptr([2]int{-1})}, B: struct {
871 B *[2]int `json:"b,string"`
872 }{B: arrayptr([2]int{1})}},
873 },
874
875
876 {
877 name: "HeadArrayPtrNilMultiFieldsNotRoot",
878 data: struct {
879 A struct {
880 A *[2]int `json:"a"`
881 }
882 B struct {
883 B *[2]int `json:"b"`
884 }
885 }{A: struct {
886 A *[2]int `json:"a"`
887 }{A: nil}, B: struct {
888 B *[2]int `json:"b"`
889 }{B: nil}},
890 },
891 {
892 name: "HeadArrayPtrNilMultiFieldsNotRootOmitEmpty",
893 data: struct {
894 A struct {
895 A *[2]int `json:"a,omitempty"`
896 }
897 B struct {
898 B *[2]int `json:"b,omitempty"`
899 }
900 }{A: struct {
901 A *[2]int `json:"a,omitempty"`
902 }{A: nil}, B: struct {
903 B *[2]int `json:"b,omitempty"`
904 }{B: nil}},
905 },
906 {
907 name: "HeadArrayPtrNilMultiFieldsNotRootString",
908 data: struct {
909 A struct {
910 A *[2]int `json:"a,string"`
911 }
912 B struct {
913 B *[2]int `json:"b,string"`
914 }
915 }{A: struct {
916 A *[2]int `json:"a,string"`
917 }{A: nil}, B: struct {
918 B *[2]int `json:"b,string"`
919 }{B: nil}},
920 },
921
922
923 {
924 name: "PtrHeadArrayZeroMultiFieldsNotRoot",
925 data: &struct {
926 A struct {
927 A [2]int `json:"a"`
928 }
929 B struct {
930 B [2]int `json:"b"`
931 }
932 }{},
933 },
934 {
935 name: "PtrHeadArrayZeroMultiFieldsNotRootOmitEmpty",
936 data: &struct {
937 A struct {
938 A [2]int `json:"a,omitempty"`
939 }
940 B struct {
941 B [2]int `json:"b,omitempty"`
942 }
943 }{},
944 },
945 {
946 name: "PtrHeadArrayZeroMultiFieldsNotRootString",
947 data: &struct {
948 A struct {
949 A [2]int `json:"a,string"`
950 }
951 B struct {
952 B [2]int `json:"b,string"`
953 }
954 }{},
955 },
956
957
958 {
959 name: "PtrHeadArrayMultiFieldsNotRoot",
960 data: &struct {
961 A struct {
962 A [2]int `json:"a"`
963 }
964 B struct {
965 B [2]int `json:"b"`
966 }
967 }{A: struct {
968 A [2]int `json:"a"`
969 }{A: [2]int{-1}}, B: struct {
970 B [2]int `json:"b"`
971 }{B: [2]int{1}}},
972 },
973 {
974 name: "PtrHeadArrayMultiFieldsNotRootOmitEmpty",
975 data: &struct {
976 A struct {
977 A [2]int `json:"a,omitempty"`
978 }
979 B struct {
980 B [2]int `json:"b,omitempty"`
981 }
982 }{A: struct {
983 A [2]int `json:"a,omitempty"`
984 }{A: [2]int{-1}}, B: struct {
985 B [2]int `json:"b,omitempty"`
986 }{B: [2]int{1}}},
987 },
988 {
989 name: "PtrHeadArrayMultiFieldsNotRootString",
990 data: &struct {
991 A struct {
992 A [2]int `json:"a,string"`
993 }
994 B struct {
995 B [2]int `json:"b,string"`
996 }
997 }{A: struct {
998 A [2]int `json:"a,string"`
999 }{A: [2]int{-1}}, B: struct {
1000 B [2]int `json:"b,string"`
1001 }{B: [2]int{1}}},
1002 },
1003
1004
1005 {
1006 name: "PtrHeadArrayPtrMultiFieldsNotRoot",
1007 data: &struct {
1008 A *struct {
1009 A *[2]int `json:"a"`
1010 }
1011 B *struct {
1012 B *[2]int `json:"b"`
1013 }
1014 }{A: &(struct {
1015 A *[2]int `json:"a"`
1016 }{A: arrayptr([2]int{-1})}), B: &(struct {
1017 B *[2]int `json:"b"`
1018 }{B: arrayptr([2]int{1})})},
1019 },
1020 {
1021 name: "PtrHeadArrayPtrMultiFieldsNotRootOmitEmpty",
1022 data: &struct {
1023 A *struct {
1024 A *[2]int `json:"a,omitempty"`
1025 }
1026 B *struct {
1027 B *[2]int `json:"b,omitempty"`
1028 }
1029 }{A: &(struct {
1030 A *[2]int `json:"a,omitempty"`
1031 }{A: arrayptr([2]int{-1})}), B: &(struct {
1032 B *[2]int `json:"b,omitempty"`
1033 }{B: arrayptr([2]int{1})})},
1034 },
1035 {
1036 name: "PtrHeadArrayPtrMultiFieldsNotRootString",
1037 data: &struct {
1038 A *struct {
1039 A *[2]int `json:"a,string"`
1040 }
1041 B *struct {
1042 B *[2]int `json:"b,string"`
1043 }
1044 }{A: &(struct {
1045 A *[2]int `json:"a,string"`
1046 }{A: arrayptr([2]int{-1})}), B: &(struct {
1047 B *[2]int `json:"b,string"`
1048 }{B: arrayptr([2]int{1})})},
1049 },
1050
1051
1052 {
1053 name: "PtrHeadArrayPtrNilMultiFieldsNotRoot",
1054 data: &struct {
1055 A *struct {
1056 A *[2]int `json:"a"`
1057 }
1058 B *struct {
1059 B *[2]int `json:"b"`
1060 }
1061 }{A: nil, B: nil},
1062 },
1063 {
1064 name: "PtrHeadArrayPtrNilMultiFieldsNotRootOmitEmpty",
1065 data: &struct {
1066 A *struct {
1067 A *[2]int `json:"a,omitempty"`
1068 } `json:",omitempty"`
1069 B *struct {
1070 B *[2]int `json:"b,omitempty"`
1071 } `json:",omitempty"`
1072 }{A: nil, B: nil},
1073 },
1074 {
1075 name: "PtrHeadArrayPtrNilMultiFieldsNotRootString",
1076 data: &struct {
1077 A *struct {
1078 A *[2]int `json:"a,string"`
1079 } `json:",string"`
1080 B *struct {
1081 B *[2]int `json:"b,string"`
1082 } `json:",string"`
1083 }{A: nil, B: nil},
1084 },
1085
1086
1087 {
1088 name: "PtrHeadArrayNilMultiFieldsNotRoot",
1089 data: (*struct {
1090 A *struct {
1091 A *[2]int `json:"a"`
1092 }
1093 B *struct {
1094 B *[2]int `json:"b"`
1095 }
1096 })(nil),
1097 },
1098 {
1099 name: "PtrHeadArrayNilMultiFieldsNotRootOmitEmpty",
1100 data: (*struct {
1101 A *struct {
1102 A *[2]int `json:"a,omitempty"`
1103 }
1104 B *struct {
1105 B *[2]int `json:"b,omitempty"`
1106 }
1107 })(nil),
1108 },
1109 {
1110 name: "PtrHeadArrayNilMultiFieldsNotRootString",
1111 data: (*struct {
1112 A *struct {
1113 A *[2]int `json:"a,string"`
1114 }
1115 B *struct {
1116 B *[2]int `json:"b,string"`
1117 }
1118 })(nil),
1119 },
1120
1121
1122 {
1123 name: "PtrHeadArrayDoubleMultiFieldsNotRoot",
1124 data: &struct {
1125 A *struct {
1126 A [2]int `json:"a"`
1127 B [2]int `json:"b"`
1128 }
1129 B *struct {
1130 A [2]int `json:"a"`
1131 B [2]int `json:"b"`
1132 }
1133 }{A: &(struct {
1134 A [2]int `json:"a"`
1135 B [2]int `json:"b"`
1136 }{A: [2]int{-1}, B: [2]int{1}}), B: &(struct {
1137 A [2]int `json:"a"`
1138 B [2]int `json:"b"`
1139 }{A: [2]int{-1}, B: [2]int{1}})},
1140 },
1141 {
1142 name: "PtrHeadArrayDoubleMultiFieldsNotRootOmitEmpty",
1143 data: &struct {
1144 A *struct {
1145 A [2]int `json:"a,omitempty"`
1146 B [2]int `json:"b,omitempty"`
1147 }
1148 B *struct {
1149 A [2]int `json:"a,omitempty"`
1150 B [2]int `json:"b,omitempty"`
1151 }
1152 }{A: &(struct {
1153 A [2]int `json:"a,omitempty"`
1154 B [2]int `json:"b,omitempty"`
1155 }{A: [2]int{-1}, B: [2]int{1}}), B: &(struct {
1156 A [2]int `json:"a,omitempty"`
1157 B [2]int `json:"b,omitempty"`
1158 }{A: [2]int{-1}, B: [2]int{1}})},
1159 },
1160 {
1161 name: "PtrHeadArrayDoubleMultiFieldsNotRootString",
1162 data: &struct {
1163 A *struct {
1164 A [2]int `json:"a,string"`
1165 B [2]int `json:"b,string"`
1166 }
1167 B *struct {
1168 A [2]int `json:"a,string"`
1169 B [2]int `json:"b,string"`
1170 }
1171 }{A: &(struct {
1172 A [2]int `json:"a,string"`
1173 B [2]int `json:"b,string"`
1174 }{A: [2]int{-1}, B: [2]int{1}}), B: &(struct {
1175 A [2]int `json:"a,string"`
1176 B [2]int `json:"b,string"`
1177 }{A: [2]int{-1}, B: [2]int{1}})},
1178 },
1179
1180
1181 {
1182 name: "PtrHeadArrayNilDoubleMultiFieldsNotRoot",
1183 data: &struct {
1184 A *struct {
1185 A [2]int `json:"a"`
1186 B [2]int `json:"b"`
1187 }
1188 B *struct {
1189 A [2]int `json:"a"`
1190 B [2]int `json:"b"`
1191 }
1192 }{A: nil, B: nil},
1193 },
1194 {
1195 name: "PtrHeadArrayNilDoubleMultiFieldsNotRootOmitEmpty",
1196 data: &struct {
1197 A *struct {
1198 A [2]int `json:"a,omitempty"`
1199 B [2]int `json:"b,omitempty"`
1200 } `json:",omitempty"`
1201 B *struct {
1202 A [2]int `json:"a,omitempty"`
1203 B [2]int `json:"b,omitempty"`
1204 } `json:",omitempty"`
1205 }{A: nil, B: nil},
1206 },
1207 {
1208 name: "PtrHeadArrayNilDoubleMultiFieldsNotRootString",
1209 data: &struct {
1210 A *struct {
1211 A [2]int `json:"a,string"`
1212 B [2]int `json:"b,string"`
1213 }
1214 B *struct {
1215 A [2]int `json:"a,string"`
1216 B [2]int `json:"b,string"`
1217 }
1218 }{A: nil, B: nil},
1219 },
1220
1221
1222 {
1223 name: "PtrHeadArrayNilDoubleMultiFieldsNotRoot",
1224 data: (*struct {
1225 A *struct {
1226 A [2]int `json:"a"`
1227 B [2]int `json:"b"`
1228 }
1229 B *struct {
1230 A [2]int `json:"a"`
1231 B [2]int `json:"b"`
1232 }
1233 })(nil),
1234 },
1235 {
1236 name: "PtrHeadArrayNilDoubleMultiFieldsNotRootOmitEmpty",
1237 data: (*struct {
1238 A *struct {
1239 A [2]int `json:"a,omitempty"`
1240 B [2]int `json:"b,omitempty"`
1241 }
1242 B *struct {
1243 A [2]int `json:"a,omitempty"`
1244 B [2]int `json:"b,omitempty"`
1245 }
1246 })(nil),
1247 },
1248 {
1249 name: "PtrHeadArrayNilDoubleMultiFieldsNotRootString",
1250 data: (*struct {
1251 A *struct {
1252 A [2]int `json:"a,string"`
1253 B [2]int `json:"b,string"`
1254 }
1255 B *struct {
1256 A [2]int `json:"a,string"`
1257 B [2]int `json:"b,string"`
1258 }
1259 })(nil),
1260 },
1261
1262
1263 {
1264 name: "PtrHeadArrayPtrDoubleMultiFieldsNotRoot",
1265 data: &struct {
1266 A *struct {
1267 A *[2]int `json:"a"`
1268 B *[2]int `json:"b"`
1269 }
1270 B *struct {
1271 A *[2]int `json:"a"`
1272 B *[2]int `json:"b"`
1273 }
1274 }{A: &(struct {
1275 A *[2]int `json:"a"`
1276 B *[2]int `json:"b"`
1277 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{1})}), B: &(struct {
1278 A *[2]int `json:"a"`
1279 B *[2]int `json:"b"`
1280 }{A: nil, B: nil})},
1281 },
1282 {
1283 name: "PtrHeadArrayPtrDoubleMultiFieldsNotRootOmitEmpty",
1284 data: &struct {
1285 A *struct {
1286 A *[2]int `json:"a,omitempty"`
1287 B *[2]int `json:"b,omitempty"`
1288 }
1289 B *struct {
1290 A *[2]int `json:"a,omitempty"`
1291 B *[2]int `json:"b,omitempty"`
1292 }
1293 }{A: &(struct {
1294 A *[2]int `json:"a,omitempty"`
1295 B *[2]int `json:"b,omitempty"`
1296 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{1})}), B: &(struct {
1297 A *[2]int `json:"a,omitempty"`
1298 B *[2]int `json:"b,omitempty"`
1299 }{A: nil, B: nil})},
1300 },
1301 {
1302 name: "PtrHeadArrayPtrDoubleMultiFieldsNotRootString",
1303 data: &struct {
1304 A *struct {
1305 A *[2]int `json:"a,string"`
1306 B *[2]int `json:"b,string"`
1307 }
1308 B *struct {
1309 A *[2]int `json:"a,string"`
1310 B *[2]int `json:"b,string"`
1311 }
1312 }{A: &(struct {
1313 A *[2]int `json:"a,string"`
1314 B *[2]int `json:"b,string"`
1315 }{A: arrayptr([2]int{-1}), B: arrayptr([2]int{1})}), B: &(struct {
1316 A *[2]int `json:"a,string"`
1317 B *[2]int `json:"b,string"`
1318 }{A: nil, B: nil})},
1319 },
1320
1321
1322 {
1323 name: "PtrHeadArrayPtrNilDoubleMultiFieldsNotRoot",
1324 data: &struct {
1325 A *struct {
1326 A *[2]int `json:"a"`
1327 B *[2]int `json:"b"`
1328 }
1329 B *struct {
1330 A *[2]int `json:"a"`
1331 B *[2]int `json:"b"`
1332 }
1333 }{A: nil, B: nil},
1334 },
1335 {
1336 name: "PtrHeadArrayPtrNilDoubleMultiFieldsNotRootOmitEmpty",
1337 data: &struct {
1338 A *struct {
1339 A *[2]int `json:"a,omitempty"`
1340 B *[2]int `json:"b,omitempty"`
1341 } `json:",omitempty"`
1342 B *struct {
1343 A *[2]int `json:"a,omitempty"`
1344 B *[2]int `json:"b,omitempty"`
1345 } `json:",omitempty"`
1346 }{A: nil, B: nil},
1347 },
1348 {
1349 name: "PtrHeadArrayPtrNilDoubleMultiFieldsNotRootString",
1350 data: &struct {
1351 A *struct {
1352 A *[2]int `json:"a,string"`
1353 B *[2]int `json:"b,string"`
1354 }
1355 B *struct {
1356 A *[2]int `json:"a,string"`
1357 B *[2]int `json:"b,string"`
1358 }
1359 }{A: nil, B: nil},
1360 },
1361
1362
1363 {
1364 name: "PtrHeadArrayPtrNilDoubleMultiFieldsNotRoot",
1365 data: (*struct {
1366 A *struct {
1367 A *[2]int `json:"a"`
1368 B *[2]int `json:"b"`
1369 }
1370 B *struct {
1371 A *[2]int `json:"a"`
1372 B *[2]int `json:"b"`
1373 }
1374 })(nil),
1375 },
1376 {
1377 name: "PtrHeadArrayPtrNilDoubleMultiFieldsNotRootOmitEmpty",
1378 data: (*struct {
1379 A *struct {
1380 A *[2]int `json:"a,omitempty"`
1381 B *[2]int `json:"b,omitempty"`
1382 }
1383 B *struct {
1384 A *[2]int `json:"a,omitempty"`
1385 B *[2]int `json:"b,omitempty"`
1386 }
1387 })(nil),
1388 },
1389 {
1390 name: "PtrHeadArrayPtrNilDoubleMultiFieldsNotRootString",
1391 data: (*struct {
1392 A *struct {
1393 A *[2]int `json:"a,string"`
1394 B *[2]int `json:"b,string"`
1395 }
1396 B *struct {
1397 A *[2]int `json:"a,string"`
1398 B *[2]int `json:"b,string"`
1399 }
1400 })(nil),
1401 },
1402
1403
1404 {
1405 name: "AnonymousHeadArray",
1406 data: struct {
1407 structArray
1408 B [2]int `json:"b"`
1409 }{
1410 structArray: structArray{A: [2]int{-1}},
1411 B: [2]int{1},
1412 },
1413 },
1414 {
1415 name: "AnonymousHeadArrayOmitEmpty",
1416 data: struct {
1417 structArrayOmitEmpty
1418 B [2]int `json:"b,omitempty"`
1419 }{
1420 structArrayOmitEmpty: structArrayOmitEmpty{A: [2]int{-1}},
1421 B: [2]int{1},
1422 },
1423 },
1424 {
1425 name: "AnonymousHeadArrayString",
1426 data: struct {
1427 structArrayString
1428 B [2]int `json:"b,string"`
1429 }{
1430 structArrayString: structArrayString{A: [2]int{-1}},
1431 B: [2]int{1},
1432 },
1433 },
1434
1435
1436 {
1437 name: "PtrAnonymousHeadArray",
1438 data: struct {
1439 *structArray
1440 B [2]int `json:"b"`
1441 }{
1442 structArray: &structArray{A: [2]int{-1}},
1443 B: [2]int{1},
1444 },
1445 },
1446 {
1447 name: "PtrAnonymousHeadArrayOmitEmpty",
1448 data: struct {
1449 *structArrayOmitEmpty
1450 B [2]int `json:"b,omitempty"`
1451 }{
1452 structArrayOmitEmpty: &structArrayOmitEmpty{A: [2]int{-1}},
1453 B: [2]int{1},
1454 },
1455 },
1456 {
1457 name: "PtrAnonymousHeadArrayString",
1458 data: struct {
1459 *structArrayString
1460 B [2]int `json:"b,string"`
1461 }{
1462 structArrayString: &structArrayString{A: [2]int{-1}},
1463 B: [2]int{1},
1464 },
1465 },
1466
1467
1468 {
1469 name: "PtrAnonymousHeadArrayNil",
1470 data: struct {
1471 *structArray
1472 B [2]int `json:"b"`
1473 }{
1474 structArray: &structArray{A: [2]int{1}},
1475 B: [2]int{1},
1476 },
1477 },
1478 {
1479 name: "PtrAnonymousHeadArrayNilOmitEmpty",
1480 data: struct {
1481 *structArrayOmitEmpty
1482 B [2]int `json:"b,omitempty"`
1483 }{
1484 structArrayOmitEmpty: &structArrayOmitEmpty{A: [2]int{1}},
1485 B: [2]int{1},
1486 },
1487 },
1488 {
1489 name: "PtrAnonymousHeadArrayNilString",
1490 data: struct {
1491 *structArrayString
1492 B [2]int `json:"b,string"`
1493 }{
1494 structArrayString: &structArrayString{A: [2]int{1}},
1495 B: [2]int{1},
1496 },
1497 },
1498
1499
1500 {
1501 name: "NilPtrAnonymousHeadArray",
1502 data: struct {
1503 *structArray
1504 B [2]int `json:"b"`
1505 }{
1506 structArray: nil,
1507 B: [2]int{-1},
1508 },
1509 },
1510 {
1511 name: "NilPtrAnonymousHeadArrayOmitEmpty",
1512 data: struct {
1513 *structArrayOmitEmpty
1514 B [2]int `json:"b,omitempty"`
1515 }{
1516 structArrayOmitEmpty: nil,
1517 B: [2]int{-1},
1518 },
1519 },
1520 {
1521 name: "NilPtrAnonymousHeadArrayString",
1522 data: struct {
1523 *structArrayString
1524 B [2]int `json:"b,string"`
1525 }{
1526 structArrayString: nil,
1527 B: [2]int{-1},
1528 },
1529 },
1530
1531
1532 {
1533 name: "AnonymousHeadArrayPtr",
1534 data: struct {
1535 structArrayPtr
1536 B *[2]int `json:"b"`
1537 }{
1538 structArrayPtr: structArrayPtr{A: arrayptr([2]int{-1})},
1539 B: nil,
1540 },
1541 },
1542 {
1543 name: "AnonymousHeadArrayPtrOmitEmpty",
1544 data: struct {
1545 structArrayPtrOmitEmpty
1546 B *[2]int `json:"b,omitempty"`
1547 }{
1548 structArrayPtrOmitEmpty: structArrayPtrOmitEmpty{A: arrayptr([2]int{-1})},
1549 B: nil,
1550 },
1551 },
1552 {
1553 name: "AnonymousHeadArrayPtrString",
1554 data: struct {
1555 structArrayPtrString
1556 B *[2]int `json:"b,string"`
1557 }{
1558 structArrayPtrString: structArrayPtrString{A: arrayptr([2]int{-1})},
1559 B: nil,
1560 },
1561 },
1562
1563
1564 {
1565 name: "AnonymousHeadArrayPtrNil",
1566 data: struct {
1567 structArrayPtr
1568 B *[2]int `json:"b"`
1569 }{
1570 structArrayPtr: structArrayPtr{A: nil},
1571 B: arrayptr([2]int{-1}),
1572 },
1573 },
1574 {
1575 name: "AnonymousHeadArrayPtrNilOmitEmpty",
1576 data: struct {
1577 structArrayPtrOmitEmpty
1578 B *[2]int `json:"b,omitempty"`
1579 }{
1580 structArrayPtrOmitEmpty: structArrayPtrOmitEmpty{A: nil},
1581 B: arrayptr([2]int{-1}),
1582 },
1583 },
1584 {
1585 name: "AnonymousHeadArrayPtrNilString",
1586 data: struct {
1587 structArrayPtrString
1588 B *[2]int `json:"b,string"`
1589 }{
1590 structArrayPtrString: structArrayPtrString{A: nil},
1591 B: arrayptr([2]int{-1}),
1592 },
1593 },
1594
1595
1596 {
1597 name: "PtrAnonymousHeadArrayPtr",
1598 data: struct {
1599 *structArrayPtr
1600 B *[2]int `json:"b"`
1601 }{
1602 structArrayPtr: &structArrayPtr{A: arrayptr([2]int{-1})},
1603 B: nil,
1604 },
1605 },
1606 {
1607 name: "PtrAnonymousHeadArrayPtrOmitEmpty",
1608 data: struct {
1609 *structArrayPtrOmitEmpty
1610 B *[2]int `json:"b,omitempty"`
1611 }{
1612 structArrayPtrOmitEmpty: &structArrayPtrOmitEmpty{A: arrayptr([2]int{-1})},
1613 B: nil,
1614 },
1615 },
1616 {
1617 name: "PtrAnonymousHeadArrayPtrString",
1618 data: struct {
1619 *structArrayPtrString
1620 B *[2]int `json:"b,string"`
1621 }{
1622 structArrayPtrString: &structArrayPtrString{A: arrayptr([2]int{-1})},
1623 B: nil,
1624 },
1625 },
1626
1627
1628 {
1629 name: "NilPtrAnonymousHeadArrayPtr",
1630 data: struct {
1631 *structArrayPtr
1632 B *[2]int `json:"b"`
1633 }{
1634 structArrayPtr: nil,
1635 B: arrayptr([2]int{-1}),
1636 },
1637 },
1638 {
1639 name: "NilPtrAnonymousHeadArrayPtrOmitEmpty",
1640 data: struct {
1641 *structArrayPtrOmitEmpty
1642 B *[2]int `json:"b,omitempty"`
1643 }{
1644 structArrayPtrOmitEmpty: nil,
1645 B: arrayptr([2]int{-1}),
1646 },
1647 },
1648 {
1649 name: "NilPtrAnonymousHeadArrayPtrString",
1650 data: struct {
1651 *structArrayPtrString
1652 B *[2]int `json:"b,string"`
1653 }{
1654 structArrayPtrString: nil,
1655 B: arrayptr([2]int{-1}),
1656 },
1657 },
1658
1659
1660 {
1661 name: "AnonymousHeadArrayOnly",
1662 data: struct {
1663 structArray
1664 }{
1665 structArray: structArray{A: [2]int{-1}},
1666 },
1667 },
1668 {
1669 name: "AnonymousHeadArrayOnlyOmitEmpty",
1670 data: struct {
1671 structArrayOmitEmpty
1672 }{
1673 structArrayOmitEmpty: structArrayOmitEmpty{A: [2]int{-1}},
1674 },
1675 },
1676 {
1677 name: "AnonymousHeadArrayOnlyString",
1678 data: struct {
1679 structArrayString
1680 }{
1681 structArrayString: structArrayString{A: [2]int{-1}},
1682 },
1683 },
1684
1685
1686 {
1687 name: "PtrAnonymousHeadArrayOnly",
1688 data: struct {
1689 *structArray
1690 }{
1691 structArray: &structArray{A: [2]int{-1}},
1692 },
1693 },
1694 {
1695 name: "PtrAnonymousHeadArrayOnlyOmitEmpty",
1696 data: struct {
1697 *structArrayOmitEmpty
1698 }{
1699 structArrayOmitEmpty: &structArrayOmitEmpty{A: [2]int{-1}},
1700 },
1701 },
1702 {
1703 name: "PtrAnonymousHeadArrayOnlyString",
1704 data: struct {
1705 *structArrayString
1706 }{
1707 structArrayString: &structArrayString{A: [2]int{-1}},
1708 },
1709 },
1710
1711
1712 {
1713 name: "NilPtrAnonymousHeadArrayOnly",
1714 data: struct {
1715 *structArray
1716 }{
1717 structArray: nil,
1718 },
1719 },
1720 {
1721 name: "NilPtrAnonymousHeadArrayOnlyOmitEmpty",
1722 data: struct {
1723 *structArrayOmitEmpty
1724 }{
1725 structArrayOmitEmpty: nil,
1726 },
1727 },
1728 {
1729 name: "NilPtrAnonymousHeadArrayOnlyString",
1730 data: struct {
1731 *structArrayString
1732 }{
1733 structArrayString: nil,
1734 },
1735 },
1736
1737
1738 {
1739 name: "AnonymousHeadArrayPtrOnly",
1740 data: struct {
1741 structArrayPtr
1742 }{
1743 structArrayPtr: structArrayPtr{A: arrayptr([2]int{-1})},
1744 },
1745 },
1746 {
1747 name: "AnonymousHeadArrayPtrOnlyOmitEmpty",
1748 data: struct {
1749 structArrayPtrOmitEmpty
1750 }{
1751 structArrayPtrOmitEmpty: structArrayPtrOmitEmpty{A: arrayptr([2]int{-1})},
1752 },
1753 },
1754 {
1755 name: "AnonymousHeadArrayPtrOnlyString",
1756 data: struct {
1757 structArrayPtrString
1758 }{
1759 structArrayPtrString: structArrayPtrString{A: arrayptr([2]int{-1})},
1760 },
1761 },
1762
1763
1764 {
1765 name: "AnonymousHeadArrayPtrNilOnly",
1766 data: struct {
1767 structArrayPtr
1768 }{
1769 structArrayPtr: structArrayPtr{A: nil},
1770 },
1771 },
1772 {
1773 name: "AnonymousHeadArrayPtrNilOnlyOmitEmpty",
1774 data: struct {
1775 structArrayPtrOmitEmpty
1776 }{
1777 structArrayPtrOmitEmpty: structArrayPtrOmitEmpty{A: nil},
1778 },
1779 },
1780 {
1781 name: "AnonymousHeadArrayPtrNilOnlyString",
1782 data: struct {
1783 structArrayPtrString
1784 }{
1785 structArrayPtrString: structArrayPtrString{A: nil},
1786 },
1787 },
1788
1789
1790 {
1791 name: "PtrAnonymousHeadArrayPtrOnly",
1792 data: struct {
1793 *structArrayPtr
1794 }{
1795 structArrayPtr: &structArrayPtr{A: arrayptr([2]int{-1})},
1796 },
1797 },
1798 {
1799 name: "PtrAnonymousHeadArrayPtrOnlyOmitEmpty",
1800 data: struct {
1801 *structArrayPtrOmitEmpty
1802 }{
1803 structArrayPtrOmitEmpty: &structArrayPtrOmitEmpty{A: arrayptr([2]int{-1})},
1804 },
1805 },
1806 {
1807 name: "PtrAnonymousHeadArrayPtrOnlyString",
1808 data: struct {
1809 *structArrayPtrString
1810 }{
1811 structArrayPtrString: &structArrayPtrString{A: arrayptr([2]int{-1})},
1812 },
1813 },
1814
1815
1816 {
1817 name: "NilPtrAnonymousHeadArrayPtrOnly",
1818 data: struct {
1819 *structArrayPtr
1820 }{
1821 structArrayPtr: nil,
1822 },
1823 },
1824 {
1825 name: "NilPtrAnonymousHeadArrayPtrOnlyOmitEmpty",
1826 data: struct {
1827 *structArrayPtrOmitEmpty
1828 }{
1829 structArrayPtrOmitEmpty: nil,
1830 },
1831 },
1832 {
1833 name: "NilPtrAnonymousHeadArrayPtrOnlyString",
1834 data: struct {
1835 *structArrayPtrString
1836 }{
1837 structArrayPtrString: nil,
1838 },
1839 },
1840 }
1841 for _, test := range tests {
1842 for _, indent := range []bool{true, false} {
1843 for _, htmlEscape := range []bool{true, false} {
1844 t.Run(fmt.Sprintf("%s_indent_%t_escape_%t", test.name, indent, htmlEscape), func(t *testing.T) {
1845 var buf bytes.Buffer
1846 enc := json.NewEncoder(&buf)
1847 enc.SetEscapeHTML(htmlEscape)
1848 if indent {
1849 enc.SetIndent("", " ")
1850 }
1851 if err := enc.Encode(test.data); err != nil {
1852 t.Fatalf("%s(htmlEscape:%v,indent:%v): %+v: %s", test.name, htmlEscape, indent, test.data, err)
1853 }
1854 stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
1855 if buf.String() != stdresult {
1856 t.Errorf("%s(htmlEscape:%v,indent:%v): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, indent, stdresult, buf.String())
1857 }
1858 })
1859 }
1860 }
1861 }
1862 }
1863
View as plain text