github.com/goccy/go-json@v0.10.3-0.20240509105655-5e2ae3f23c1d/test/cover/cover_slice_test.go (about) 1 package json_test 2 3 import ( 4 "bytes" 5 "fmt" 6 "testing" 7 8 "github.com/goccy/go-json" 9 ) 10 11 type coverSliceMarshalJSON struct { 12 A int 13 } 14 15 func (coverSliceMarshalJSON) MarshalJSON() ([]byte, error) { 16 return []byte(`"hello"`), nil 17 } 18 19 type coverSliceMarshalJSONMap map[string]any 20 21 func (c coverSliceMarshalJSONMap) MarshalJSON() ([]byte, error) { 22 return json.Marshal(map[string]any(c)) 23 } 24 25 type coverSliceMarshalJSONMapPtr map[string]any 26 27 func (c *coverSliceMarshalJSONMapPtr) MarshalJSON() ([]byte, error) { 28 return json.Marshal(map[string]any(*c)) 29 } 30 31 type coverSliceMarshalText struct { 32 A int 33 } 34 35 func (coverSliceMarshalText) MarshalText() ([]byte, error) { 36 return []byte(`"hello"`), nil 37 } 38 39 type recursiveSlice struct { 40 A int 41 B []*recursiveSlice 42 } 43 44 func TestCoverSlice(t *testing.T) { 45 type structSlice struct { 46 A []int `json:"a"` 47 } 48 type structSliceOmitEmpty struct { 49 A []int `json:"a,omitempty"` 50 } 51 type structSliceString struct { 52 A []int `json:"a,string"` 53 } 54 type structSlicePtr struct { 55 A *[]int `json:"a"` 56 } 57 type structSlicePtrOmitEmpty struct { 58 A *[]int `json:"a,omitempty"` 59 } 60 type structSlicePtrString struct { 61 A *[]int `json:"a,string"` 62 } 63 64 type structSlicePtrContent struct { 65 A []*int `json:"a"` 66 } 67 type structSliceOmitEmptyPtrContent struct { 68 A []*int `json:"a,omitempty"` 69 } 70 type structSliceStringPtrContent struct { 71 A []*int `json:"a,string"` 72 } 73 type structSlicePtrPtrContent struct { 74 A *[]*int `json:"a"` 75 } 76 type structSlicePtrOmitEmptyPtrContent struct { 77 A *[]*int `json:"a,omitempty"` 78 } 79 type structSlicePtrStringPtrContent struct { 80 A *[]*int `json:"a,string"` 81 } 82 83 tests := []struct { 84 name string 85 data interface{} 86 }{ 87 { 88 name: "SliceInt", 89 data: []int{1, 2, 3}, 90 }, 91 { 92 name: "SliceInt8", 93 data: []int8{1, 2, 3}, 94 }, 95 { 96 name: "SliceInt16", 97 data: []int16{1, 2, 3}, 98 }, 99 { 100 name: "SliceInt32", 101 data: []int32{1, 2, 3}, 102 }, 103 { 104 name: "SliceInt64", 105 data: []int64{1, 2, 3}, 106 }, 107 { 108 name: "SliceUint", 109 data: []uint{1, 2, 3}, 110 }, 111 { 112 name: "SliceUint8", 113 data: []uint8{1, 2, 3}, 114 }, 115 { 116 name: "SliceUint16", 117 data: []uint16{1, 2, 3}, 118 }, 119 { 120 name: "SliceUint32", 121 data: []uint32{1, 2, 3}, 122 }, 123 { 124 name: "SliceUint64", 125 data: []uint64{1, 2, 3}, 126 }, 127 { 128 name: "SliceFloat32", 129 data: []float32{1, 2, 3}, 130 }, 131 { 132 name: "SliceFloat64", 133 data: []float64{1, 2, 3}, 134 }, 135 { 136 name: "SliceString", 137 data: []string{"a", "b"}, 138 }, 139 { 140 name: "SliceBool", 141 data: []bool{false, true, false}, 142 }, 143 { 144 name: "SliceBytes", 145 data: [][]byte{[]byte("a"), []byte("b"), nil, []byte("c")}, 146 }, 147 { 148 name: "SliceSlice", 149 data: [][]int{[]int{1, 2, 3}, nil, []int{4, 5, 6}}, 150 }, 151 { 152 name: "SliceArray", 153 data: [][3]int{[3]int{1, 2, 3}, [3]int{4, 5, 6}}, 154 }, 155 { 156 name: "SliceMap", 157 data: []map[string]int{map[string]int{"a": 1}, nil, map[string]int{"b": 2}}, 158 }, 159 { 160 name: "SliceStruct", 161 data: []struct{ A int }{struct{ A int }{A: 1}, struct{ A int }{A: 2}}, 162 }, 163 { 164 name: "SliceMarshalJSON", 165 data: []coverSliceMarshalJSON{{A: 1}, {A: 2}}, 166 }, 167 { 168 name: "SliceMarshalJSONMap", 169 data: []coverSliceMarshalJSONMap{{"foo": "bar"}, {"some": 1}}, 170 }, 171 { 172 name: "SliceMarshalJSONMap", 173 data: []*coverSliceMarshalJSONMap{{"foo": "bar"}, {"some": 1}}, 174 }, 175 { 176 name: "SliceMarshalJSONMap", 177 data: []coverSliceMarshalJSONMapPtr{{"foo": "bar"}, {"some": 1}}, 178 }, 179 { 180 name: "SliceMarshalJSONMap", 181 data: []*coverSliceMarshalJSONMapPtr{{"foo": "bar"}, {"some": 1}}, 182 }, 183 { 184 name: "SliceMarshalText", 185 data: []coverSliceMarshalText{{A: 1}, {A: 2}}, 186 }, 187 { 188 name: "SliceIntPtr", 189 data: []*int{intptr(1), intptr(2), nil, intptr(3)}, 190 }, 191 { 192 name: "SliceInt8Ptr", 193 data: []*int8{int8ptr(1), int8ptr(2), nil, int8ptr(3)}, 194 }, 195 { 196 name: "SliceInt16Ptr", 197 data: []*int16{int16ptr(1), int16ptr(2), nil, int16ptr(3)}, 198 }, 199 { 200 name: "SliceInt32Ptr", 201 data: []*int32{int32ptr(1), int32ptr(2), nil, int32ptr(3)}, 202 }, 203 { 204 name: "SliceInt64Ptr", 205 data: []*int64{int64ptr(1), int64ptr(2), nil, int64ptr(3)}, 206 }, 207 { 208 name: "SliceUintPtr", 209 data: []*uint{uptr(1), uptr(2), nil, uptr(3)}, 210 }, 211 { 212 name: "SliceUint8Ptr", 213 data: []*uint8{uint8ptr(1), uint8ptr(2), nil, uint8ptr(3)}, 214 }, 215 { 216 name: "SliceUint16Ptr", 217 data: []*uint16{uint16ptr(1), uint16ptr(2), nil, uint16ptr(3)}, 218 }, 219 { 220 name: "SliceUint32Ptr", 221 data: []*uint32{uint32ptr(1), uint32ptr(2), nil, uint32ptr(3)}, 222 }, 223 { 224 name: "SliceUint64Ptr", 225 data: []*uint64{uint64ptr(1), uint64ptr(2), nil, uint64ptr(3)}, 226 }, 227 { 228 name: "SliceFloat32Ptr", 229 data: []*float32{float32ptr(1), float32ptr(2), nil, float32ptr(3)}, 230 }, 231 { 232 name: "SliceFloat64Ptr", 233 data: []*float64{float64ptr(1), float64ptr(2), nil, float64ptr(3)}, 234 }, 235 { 236 name: "SliceStringPtr", 237 data: []*string{stringptr("a"), nil, stringptr("b")}, 238 }, 239 { 240 name: "SliceBoolPtr", 241 data: []*bool{boolptr(false), boolptr(true), nil, boolptr(false)}, 242 }, 243 { 244 name: "SliceBytesPtr", 245 data: []*[]byte{bytesptr([]byte("a")), bytesptr([]byte("b")), nil, bytesptr([]byte("c"))}, 246 }, 247 { 248 name: "SliceSlicePtr", 249 data: []*[]int{sliceptr([]int{1, 2, 3}), nil, sliceptr([]int{4, 5, 6})}, 250 }, 251 { 252 name: "SliceArrayPtr", 253 data: []*[2]int{arrayptr([2]int{1, 2}), nil, arrayptr([2]int{4, 5})}, 254 }, 255 { 256 name: "SliceMapPtr", 257 data: []*map[string]int{mapptr(map[string]int{"a": 1}), nil, mapptr(map[string]int{"b": 2})}, 258 }, 259 { 260 name: "SliceStructPtr", 261 data: []*struct{ A int }{&struct{ A int }{A: 1}, &struct{ A int }{A: 2}}, 262 }, 263 { 264 name: "RecursiveSlice", 265 data: []*recursiveSlice{ 266 { 267 A: 1, B: []*recursiveSlice{ 268 { 269 A: 2, B: []*recursiveSlice{ 270 { 271 A: 3, 272 }, 273 }, 274 }, 275 }, 276 }, 277 { 278 A: 4, B: []*recursiveSlice{ 279 { 280 A: 5, B: []*recursiveSlice{ 281 { 282 A: 6, 283 }, 284 }, 285 }, 286 }, 287 }, 288 }, 289 }, 290 291 // HeadSliceZero 292 { 293 name: "HeadSliceZero", 294 data: struct { 295 A []int `json:"a"` 296 }{}, 297 }, 298 { 299 name: "HeadSliceZeroOmitEmpty", 300 data: struct { 301 A []int `json:"a,omitempty"` 302 }{}, 303 }, 304 { 305 name: "HeadSliceZeroString", 306 data: struct { 307 A []int `json:"a,string"` 308 }{}, 309 }, 310 311 // HeadSlice 312 { 313 name: "HeadSlice", 314 data: struct { 315 A []int `json:"a"` 316 }{A: []int{-1}}, 317 }, 318 { 319 name: "HeadSliceOmitEmpty", 320 data: struct { 321 A []int `json:"a,omitempty"` 322 }{A: []int{-1}}, 323 }, 324 { 325 name: "HeadSliceString", 326 data: struct { 327 A []int `json:"a,string"` 328 }{A: []int{-1}}, 329 }, 330 331 // HeadSlicePtr 332 { 333 name: "HeadSlicePtr", 334 data: struct { 335 A *[]int `json:"a"` 336 }{A: sliceptr([]int{-1})}, 337 }, 338 { 339 name: "HeadSlicePtrOmitEmpty", 340 data: struct { 341 A *[]int `json:"a,omitempty"` 342 }{A: sliceptr([]int{-1})}, 343 }, 344 { 345 name: "HeadSlicePtrString", 346 data: struct { 347 A *[]int `json:"a,string"` 348 }{A: sliceptr([]int{-1})}, 349 }, 350 351 // HeadSlicePtrNil 352 { 353 name: "HeadSlicePtrNil", 354 data: struct { 355 A *[]int `json:"a"` 356 }{A: nil}, 357 }, 358 { 359 name: "HeadSlicePtrNilOmitEmpty", 360 data: struct { 361 A *[]int `json:"a,omitempty"` 362 }{A: nil}, 363 }, 364 { 365 name: "HeadSlicePtrNilString", 366 data: struct { 367 A *[]int `json:"a,string"` 368 }{A: nil}, 369 }, 370 371 // PtrHeadSliceZero 372 { 373 name: "PtrHeadSliceZero", 374 data: &struct { 375 A []int `json:"a"` 376 }{}, 377 }, 378 { 379 name: "PtrHeadSliceZeroOmitEmpty", 380 data: &struct { 381 A []int `json:"a,omitempty"` 382 }{}, 383 }, 384 { 385 name: "PtrHeadSliceZeroString", 386 data: &struct { 387 A []int `json:"a,string"` 388 }{}, 389 }, 390 391 // PtrHeadSlice 392 { 393 name: "PtrHeadSlice", 394 data: &struct { 395 A []int `json:"a"` 396 }{A: []int{-1}}, 397 }, 398 { 399 name: "PtrHeadSliceOmitEmpty", 400 data: &struct { 401 A []int `json:"a,omitempty"` 402 }{A: []int{-1}}, 403 }, 404 { 405 name: "PtrHeadSliceString", 406 data: &struct { 407 A []int `json:"a,string"` 408 }{A: []int{-1}}, 409 }, 410 411 // PtrHeadSlicePtr 412 { 413 name: "PtrHeadSlicePtr", 414 data: &struct { 415 A *[]int `json:"a"` 416 }{A: sliceptr([]int{-1})}, 417 }, 418 { 419 name: "PtrHeadSlicePtrOmitEmpty", 420 data: &struct { 421 A *[]int `json:"a,omitempty"` 422 }{A: sliceptr([]int{-1})}, 423 }, 424 { 425 name: "PtrHeadSlicePtrString", 426 data: &struct { 427 A *[]int `json:"a,string"` 428 }{A: sliceptr([]int{-1})}, 429 }, 430 431 // PtrHeadSlicePtrNil 432 { 433 name: "PtrHeadSlicePtrNil", 434 data: &struct { 435 A *[]int `json:"a"` 436 }{A: nil}, 437 }, 438 { 439 name: "PtrHeadSlicePtrNilOmitEmpty", 440 data: &struct { 441 A *[]int `json:"a,omitempty"` 442 }{A: nil}, 443 }, 444 { 445 name: "PtrHeadSlicePtrNilString", 446 data: &struct { 447 A *[]int `json:"a,string"` 448 }{A: nil}, 449 }, 450 451 // PtrHeadSliceNil 452 { 453 name: "PtrHeadSliceNil", 454 data: (*struct { 455 A *[]int `json:"a"` 456 })(nil), 457 }, 458 { 459 name: "PtrHeadSliceNilOmitEmpty", 460 data: (*struct { 461 A *[]int `json:"a,omitempty"` 462 })(nil), 463 }, 464 { 465 name: "PtrHeadSliceNilString", 466 data: (*struct { 467 A *[]int `json:"a,string"` 468 })(nil), 469 }, 470 471 // HeadSliceZeroMultiFields 472 { 473 name: "HeadSliceZeroMultiFields", 474 data: struct { 475 A []int `json:"a"` 476 B []int `json:"b"` 477 C []int `json:"c"` 478 }{}, 479 }, 480 { 481 name: "HeadSliceZeroMultiFieldsOmitEmpty", 482 data: struct { 483 A []int `json:"a,omitempty"` 484 B []int `json:"b,omitempty"` 485 C []int `json:"c,omitempty"` 486 }{}, 487 }, 488 { 489 name: "HeadSliceZeroMultiFields", 490 data: struct { 491 A []int `json:"a,string"` 492 B []int `json:"b,string"` 493 C []int `json:"c,string"` 494 }{}, 495 }, 496 497 // HeadSliceMultiFields 498 { 499 name: "HeadSliceMultiFields", 500 data: struct { 501 A []int `json:"a"` 502 B []int `json:"b"` 503 C []int `json:"c"` 504 }{A: []int{-1}, B: []int{-2}, C: []int{-3}}, 505 }, 506 { 507 name: "HeadSliceMultiFieldsOmitEmpty", 508 data: struct { 509 A []int `json:"a,omitempty"` 510 B []int `json:"b,omitempty"` 511 C []int `json:"c,omitempty"` 512 }{A: []int{-1}, B: []int{-2}, C: []int{-3}}, 513 }, 514 { 515 name: "HeadSliceMultiFieldsString", 516 data: struct { 517 A []int `json:"a,string"` 518 B []int `json:"b,string"` 519 C []int `json:"c,string"` 520 }{A: []int{-1}, B: []int{-2}, C: []int{-3}}, 521 }, 522 523 // HeadSlicePtrMultiFields 524 { 525 name: "HeadSlicePtrMultiFields", 526 data: struct { 527 A *[]int `json:"a"` 528 B *[]int `json:"b"` 529 C *[]int `json:"c"` 530 }{A: sliceptr([]int{-1}), B: sliceptr([]int{-2}), C: sliceptr([]int{-3})}, 531 }, 532 { 533 name: "HeadSlicePtrMultiFieldsOmitEmpty", 534 data: struct { 535 A *[]int `json:"a,omitempty"` 536 B *[]int `json:"b,omitempty"` 537 C *[]int `json:"c,omitempty"` 538 }{A: sliceptr([]int{-1}), B: sliceptr([]int{-2}), C: sliceptr([]int{-3})}, 539 }, 540 { 541 name: "HeadSlicePtrMultiFieldsString", 542 data: struct { 543 A *[]int `json:"a,string"` 544 B *[]int `json:"b,string"` 545 C *[]int `json:"c,string"` 546 }{A: sliceptr([]int{-1}), B: sliceptr([]int{-2}), C: sliceptr([]int{-3})}, 547 }, 548 549 // HeadSlicePtrNilMultiFields 550 { 551 name: "HeadSlicePtrNilMultiFields", 552 data: struct { 553 A *[]int `json:"a"` 554 B *[]int `json:"b"` 555 C *[]int `json:"c"` 556 }{A: nil, B: nil, C: nil}, 557 }, 558 { 559 name: "HeadSlicePtrNilMultiFieldsOmitEmpty", 560 data: struct { 561 A *[]int `json:"a,omitempty"` 562 B *[]int `json:"b,omitempty"` 563 C *[]int `json:"c,omitempty"` 564 }{A: nil, B: nil, C: nil}, 565 }, 566 { 567 name: "HeadSlicePtrNilMultiFieldsString", 568 data: struct { 569 A *[]int `json:"a,string"` 570 B *[]int `json:"b,string"` 571 C *[]int `json:"c,string"` 572 }{A: nil, B: nil, C: nil}, 573 }, 574 575 // PtrHeadSliceZeroMultiFields 576 { 577 name: "PtrHeadSliceZeroMultiFields", 578 data: &struct { 579 A []int `json:"a"` 580 B []int `json:"b"` 581 }{}, 582 }, 583 { 584 name: "PtrHeadSliceZeroMultiFieldsOmitEmpty", 585 data: &struct { 586 A []int `json:"a,omitempty"` 587 B []int `json:"b,omitempty"` 588 }{}, 589 }, 590 { 591 name: "PtrHeadSliceZeroMultiFieldsString", 592 data: &struct { 593 A []int `json:"a,string"` 594 B []int `json:"b,string"` 595 }{}, 596 }, 597 598 // PtrHeadSliceMultiFields 599 { 600 name: "PtrHeadSliceMultiFields", 601 data: &struct { 602 A []int `json:"a"` 603 B []int `json:"b"` 604 }{A: []int{-1}, B: nil}, 605 }, 606 { 607 name: "PtrHeadSliceMultiFieldsOmitEmpty", 608 data: &struct { 609 A []int `json:"a,omitempty"` 610 B []int `json:"b,omitempty"` 611 }{A: []int{-1}, B: nil}, 612 }, 613 { 614 name: "PtrHeadSliceMultiFieldsString", 615 data: &struct { 616 A []int `json:"a,string"` 617 B []int `json:"b,string"` 618 }{A: []int{-1}, B: nil}, 619 }, 620 621 // PtrHeadSlicePtrMultiFields 622 { 623 name: "PtrHeadSlicePtrMultiFields", 624 data: &struct { 625 A *[]int `json:"a"` 626 B *[]int `json:"b"` 627 }{A: sliceptr([]int{-1}), B: sliceptr([]int{-2})}, 628 }, 629 { 630 name: "PtrHeadSlicePtrMultiFieldsOmitEmpty", 631 data: &struct { 632 A *[]int `json:"a,omitempty"` 633 B *[]int `json:"b,omitempty"` 634 }{A: sliceptr([]int{-1}), B: sliceptr([]int{-2})}, 635 }, 636 { 637 name: "PtrHeadSlicePtrMultiFieldsString", 638 data: &struct { 639 A *[]int `json:"a,string"` 640 B *[]int `json:"b,string"` 641 }{A: sliceptr([]int{-1}), B: sliceptr([]int{-2})}, 642 }, 643 644 // PtrHeadSlicePtrNilMultiFields 645 { 646 name: "PtrHeadSlicePtrNilMultiFields", 647 data: &struct { 648 A *[]int `json:"a"` 649 B *[]int `json:"b"` 650 }{A: nil, B: nil}, 651 }, 652 { 653 name: "PtrHeadSlicePtrNilMultiFieldsOmitEmpty", 654 data: &struct { 655 A *[]int `json:"a,omitempty"` 656 B *[]int `json:"b,omitempty"` 657 }{A: nil, B: nil}, 658 }, 659 { 660 name: "PtrHeadSlicePtrNilMultiFieldsString", 661 data: &struct { 662 A *[]int `json:"a,string"` 663 B *[]int `json:"b,string"` 664 }{A: nil, B: nil}, 665 }, 666 667 // PtrHeadSliceNilMultiFields 668 { 669 name: "PtrHeadSliceNilMultiFields", 670 data: (*struct { 671 A []int `json:"a"` 672 B []int `json:"b"` 673 })(nil), 674 }, 675 { 676 name: "PtrHeadSliceNilMultiFieldsOmitEmpty", 677 data: (*struct { 678 A []int `json:"a,omitempty"` 679 B []int `json:"b,omitempty"` 680 })(nil), 681 }, 682 { 683 name: "PtrHeadSliceNilMultiFieldsString", 684 data: (*struct { 685 A []int `json:"a,string"` 686 B []int `json:"b,string"` 687 })(nil), 688 }, 689 690 // PtrHeadSliceNilMultiFields 691 { 692 name: "PtrHeadSliceNilMultiFields", 693 data: (*struct { 694 A *[]int `json:"a"` 695 B *[]int `json:"b"` 696 })(nil), 697 }, 698 { 699 name: "PtrHeadSliceNilMultiFieldsOmitEmpty", 700 data: (*struct { 701 A *[]int `json:"a,omitempty"` 702 B *[]int `json:"b,omitempty"` 703 })(nil), 704 }, 705 { 706 name: "PtrHeadSliceNilMultiFieldsString", 707 data: (*struct { 708 A *[]int `json:"a,string"` 709 B *[]int `json:"b,string"` 710 })(nil), 711 }, 712 713 // HeadSliceZeroNotRoot 714 { 715 name: "HeadSliceZeroNotRoot", 716 data: struct { 717 A struct { 718 A []int `json:"a"` 719 } 720 }{}, 721 }, 722 { 723 name: "HeadSliceZeroNotRootOmitEmpty", 724 data: struct { 725 A struct { 726 A []int `json:"a,omitempty"` 727 } 728 }{}, 729 }, 730 { 731 name: "HeadSliceZeroNotRootString", 732 data: struct { 733 A struct { 734 A []int `json:"a,string"` 735 } 736 }{}, 737 }, 738 739 // HeadSliceNotRoot 740 { 741 name: "HeadSliceNotRoot", 742 data: struct { 743 A struct { 744 A []int `json:"a"` 745 } 746 }{A: struct { 747 A []int `json:"a"` 748 }{A: []int{-1}}}, 749 }, 750 { 751 name: "HeadSliceNotRootOmitEmpty", 752 data: struct { 753 A struct { 754 A []int `json:"a,omitempty"` 755 } 756 }{A: struct { 757 A []int `json:"a,omitempty"` 758 }{A: []int{-1}}}, 759 }, 760 { 761 name: "HeadSliceNotRootString", 762 data: struct { 763 A struct { 764 A []int `json:"a,string"` 765 } 766 }{A: struct { 767 A []int `json:"a,string"` 768 }{A: []int{-1}}}, 769 }, 770 771 // HeadSlicePtrNotRoot 772 { 773 name: "HeadSlicePtrNotRoot", 774 data: struct { 775 A struct { 776 A *[]int `json:"a"` 777 } 778 }{A: struct { 779 A *[]int `json:"a"` 780 }{sliceptr([]int{-1})}}, 781 }, 782 { 783 name: "HeadSlicePtrNotRootOmitEmpty", 784 data: struct { 785 A struct { 786 A *[]int `json:"a,omitempty"` 787 } 788 }{A: struct { 789 A *[]int `json:"a,omitempty"` 790 }{sliceptr([]int{-1})}}, 791 }, 792 { 793 name: "HeadSlicePtrNotRootString", 794 data: struct { 795 A struct { 796 A *[]int `json:"a,string"` 797 } 798 }{A: struct { 799 A *[]int `json:"a,string"` 800 }{sliceptr([]int{-1})}}, 801 }, 802 803 // HeadSlicePtrNilNotRoot 804 { 805 name: "HeadSlicePtrNilNotRoot", 806 data: struct { 807 A struct { 808 A *[]int `json:"a"` 809 } 810 }{}, 811 }, 812 { 813 name: "HeadSlicePtrNilNotRootOmitEmpty", 814 data: struct { 815 A struct { 816 A *[]int `json:"a,omitempty"` 817 } 818 }{}, 819 }, 820 { 821 name: "HeadSlicePtrNilNotRootString", 822 data: struct { 823 A struct { 824 A *[]int `json:"a,string"` 825 } 826 }{}, 827 }, 828 829 // PtrHeadSliceZeroNotRoot 830 { 831 name: "PtrHeadSliceZeroNotRoot", 832 data: struct { 833 A *struct { 834 A []int `json:"a"` 835 } 836 }{A: new(struct { 837 A []int `json:"a"` 838 })}, 839 }, 840 { 841 name: "PtrHeadSliceZeroNotRootOmitEmpty", 842 data: struct { 843 A *struct { 844 A []int `json:"a,omitempty"` 845 } 846 }{A: new(struct { 847 A []int `json:"a,omitempty"` 848 })}, 849 }, 850 { 851 name: "PtrHeadSliceZeroNotRootString", 852 data: struct { 853 A *struct { 854 A []int `json:"a,string"` 855 } 856 }{A: new(struct { 857 A []int `json:"a,string"` 858 })}, 859 }, 860 861 // PtrHeadSliceNotRoot 862 { 863 name: "PtrHeadSliceNotRoot", 864 data: struct { 865 A *struct { 866 A []int `json:"a"` 867 } 868 }{A: &(struct { 869 A []int `json:"a"` 870 }{A: []int{-1}})}, 871 }, 872 { 873 name: "PtrHeadSliceNotRootOmitEmpty", 874 data: struct { 875 A *struct { 876 A []int `json:"a,omitempty"` 877 } 878 }{A: &(struct { 879 A []int `json:"a,omitempty"` 880 }{A: []int{-1}})}, 881 }, 882 { 883 name: "PtrHeadSliceNotRootString", 884 data: struct { 885 A *struct { 886 A []int `json:"a,string"` 887 } 888 }{A: &(struct { 889 A []int `json:"a,string"` 890 }{A: []int{-1}})}, 891 }, 892 893 // PtrHeadSlicePtrNotRoot 894 { 895 name: "PtrHeadSlicePtrNotRoot", 896 data: struct { 897 A *struct { 898 A *[]int `json:"a"` 899 } 900 }{A: &(struct { 901 A *[]int `json:"a"` 902 }{A: sliceptr([]int{-1})})}, 903 }, 904 { 905 name: "PtrHeadSlicePtrNotRootOmitEmpty", 906 data: struct { 907 A *struct { 908 A *[]int `json:"a,omitempty"` 909 } 910 }{A: &(struct { 911 A *[]int `json:"a,omitempty"` 912 }{A: sliceptr([]int{-1})})}, 913 }, 914 { 915 name: "PtrHeadSlicePtrNotRootString", 916 data: struct { 917 A *struct { 918 A *[]int `json:"a,string"` 919 } 920 }{A: &(struct { 921 A *[]int `json:"a,string"` 922 }{A: sliceptr([]int{-1})})}, 923 }, 924 925 // PtrHeadSlicePtrNilNotRoot 926 { 927 name: "PtrHeadSlicePtrNilNotRoot", 928 data: struct { 929 A *struct { 930 A *[]int `json:"a"` 931 } 932 }{A: &(struct { 933 A *[]int `json:"a"` 934 }{A: nil})}, 935 }, 936 { 937 name: "PtrHeadSlicePtrNilNotRootOmitEmpty", 938 data: struct { 939 A *struct { 940 A *[]int `json:"a,omitempty"` 941 } 942 }{A: &(struct { 943 A *[]int `json:"a,omitempty"` 944 }{A: nil})}, 945 }, 946 { 947 name: "PtrHeadSlicePtrNilNotRootString", 948 data: struct { 949 A *struct { 950 A *[]int `json:"a,string"` 951 } 952 }{A: &(struct { 953 A *[]int `json:"a,string"` 954 }{A: nil})}, 955 }, 956 957 // PtrHeadSliceNilNotRoot 958 { 959 name: "PtrHeadSliceNilNotRoot", 960 data: struct { 961 A *struct { 962 A *[]int `json:"a"` 963 } 964 }{A: nil}, 965 }, 966 { 967 name: "PtrHeadSliceNilNotRootOmitEmpty", 968 data: struct { 969 A *struct { 970 A *[]int `json:"a,omitempty"` 971 } `json:",omitempty"` 972 }{A: nil}, 973 }, 974 { 975 name: "PtrHeadSliceNilNotRootString", 976 data: struct { 977 A *struct { 978 A *[]int `json:"a,string"` 979 } `json:",string"` 980 }{A: nil}, 981 }, 982 983 // HeadSliceZeroMultiFieldsNotRoot 984 { 985 name: "HeadSliceZeroMultiFieldsNotRoot", 986 data: struct { 987 A struct { 988 A []int `json:"a"` 989 } 990 B struct { 991 B []int `json:"b"` 992 } 993 }{}, 994 }, 995 { 996 name: "HeadSliceZeroMultiFieldsNotRootOmitEmpty", 997 data: struct { 998 A struct { 999 A []int `json:"a,omitempty"` 1000 } 1001 B struct { 1002 B []int `json:"b,omitempty"` 1003 } 1004 }{}, 1005 }, 1006 { 1007 name: "HeadSliceZeroMultiFieldsNotRootString", 1008 data: struct { 1009 A struct { 1010 A []int `json:"a,string"` 1011 } 1012 B struct { 1013 B []int `json:"b,string"` 1014 } 1015 }{}, 1016 }, 1017 1018 // HeadSliceMultiFieldsNotRoot 1019 { 1020 name: "HeadSliceMultiFieldsNotRoot", 1021 data: struct { 1022 A struct { 1023 A []int `json:"a"` 1024 } 1025 B struct { 1026 B []int `json:"b"` 1027 } 1028 }{A: struct { 1029 A []int `json:"a"` 1030 }{A: []int{-1}}, B: struct { 1031 B []int `json:"b"` 1032 }{B: []int{0}}}, 1033 }, 1034 { 1035 name: "HeadSliceMultiFieldsNotRootOmitEmpty", 1036 data: struct { 1037 A struct { 1038 A []int `json:"a,omitempty"` 1039 } 1040 B struct { 1041 B []int `json:"b,omitempty"` 1042 } 1043 }{A: struct { 1044 A []int `json:"a,omitempty"` 1045 }{A: []int{-1}}, B: struct { 1046 B []int `json:"b,omitempty"` 1047 }{B: []int{1}}}, 1048 }, 1049 { 1050 name: "HeadSliceMultiFieldsNotRootString", 1051 data: struct { 1052 A struct { 1053 A []int `json:"a,string"` 1054 } 1055 B struct { 1056 B []int `json:"b,string"` 1057 } 1058 }{A: struct { 1059 A []int `json:"a,string"` 1060 }{A: []int{-1}}, B: struct { 1061 B []int `json:"b,string"` 1062 }{B: []int{1}}}, 1063 }, 1064 1065 // HeadSlicePtrMultiFieldsNotRoot 1066 { 1067 name: "HeadSlicePtrMultiFieldsNotRoot", 1068 data: struct { 1069 A struct { 1070 A *[]int `json:"a"` 1071 } 1072 B struct { 1073 B *[]int `json:"b"` 1074 } 1075 }{A: struct { 1076 A *[]int `json:"a"` 1077 }{A: sliceptr([]int{-1})}, B: struct { 1078 B *[]int `json:"b"` 1079 }{B: sliceptr([]int{1})}}, 1080 }, 1081 { 1082 name: "HeadSlicePtrMultiFieldsNotRootOmitEmpty", 1083 data: struct { 1084 A struct { 1085 A *[]int `json:"a,omitempty"` 1086 } 1087 B struct { 1088 B *[]int `json:"b,omitempty"` 1089 } 1090 }{A: struct { 1091 A *[]int `json:"a,omitempty"` 1092 }{A: sliceptr([]int{-1})}, B: struct { 1093 B *[]int `json:"b,omitempty"` 1094 }{B: sliceptr([]int{1})}}, 1095 }, 1096 { 1097 name: "HeadSlicePtrMultiFieldsNotRootString", 1098 data: struct { 1099 A struct { 1100 A *[]int `json:"a,string"` 1101 } 1102 B struct { 1103 B *[]int `json:"b,string"` 1104 } 1105 }{A: struct { 1106 A *[]int `json:"a,string"` 1107 }{A: sliceptr([]int{-1})}, B: struct { 1108 B *[]int `json:"b,string"` 1109 }{B: sliceptr([]int{1})}}, 1110 }, 1111 1112 // HeadSlicePtrNilMultiFieldsNotRoot 1113 { 1114 name: "HeadSlicePtrNilMultiFieldsNotRoot", 1115 data: struct { 1116 A struct { 1117 A *[]int `json:"a"` 1118 } 1119 B struct { 1120 B *[]int `json:"b"` 1121 } 1122 }{A: struct { 1123 A *[]int `json:"a"` 1124 }{A: nil}, B: struct { 1125 B *[]int `json:"b"` 1126 }{B: nil}}, 1127 }, 1128 { 1129 name: "HeadSlicePtrNilMultiFieldsNotRootOmitEmpty", 1130 data: struct { 1131 A struct { 1132 A *[]int `json:"a,omitempty"` 1133 } 1134 B struct { 1135 B *[]int `json:"b,omitempty"` 1136 } 1137 }{A: struct { 1138 A *[]int `json:"a,omitempty"` 1139 }{A: nil}, B: struct { 1140 B *[]int `json:"b,omitempty"` 1141 }{B: nil}}, 1142 }, 1143 { 1144 name: "HeadSlicePtrNilMultiFieldsNotRootString", 1145 data: struct { 1146 A struct { 1147 A *[]int `json:"a,string"` 1148 } 1149 B struct { 1150 B *[]int `json:"b,string"` 1151 } 1152 }{A: struct { 1153 A *[]int `json:"a,string"` 1154 }{A: nil}, B: struct { 1155 B *[]int `json:"b,string"` 1156 }{B: nil}}, 1157 }, 1158 1159 // PtrHeadSliceZeroMultiFieldsNotRoot 1160 { 1161 name: "PtrHeadSliceZeroMultiFieldsNotRoot", 1162 data: &struct { 1163 A struct { 1164 A []int `json:"a"` 1165 } 1166 B struct { 1167 B []int `json:"b"` 1168 } 1169 }{}, 1170 }, 1171 { 1172 name: "PtrHeadSliceZeroMultiFieldsNotRootOmitEmpty", 1173 data: &struct { 1174 A struct { 1175 A []int `json:"a,omitempty"` 1176 } 1177 B struct { 1178 B []int `json:"b,omitempty"` 1179 } 1180 }{}, 1181 }, 1182 { 1183 name: "PtrHeadSliceZeroMultiFieldsNotRootString", 1184 data: &struct { 1185 A struct { 1186 A []int `json:"a,string"` 1187 } 1188 B struct { 1189 B []int `json:"b,string"` 1190 } 1191 }{}, 1192 }, 1193 1194 // PtrHeadSliceMultiFieldsNotRoot 1195 { 1196 name: "PtrHeadSliceMultiFieldsNotRoot", 1197 data: &struct { 1198 A struct { 1199 A []int `json:"a"` 1200 } 1201 B struct { 1202 B []int `json:"b"` 1203 } 1204 }{A: struct { 1205 A []int `json:"a"` 1206 }{A: []int{-1}}, B: struct { 1207 B []int `json:"b"` 1208 }{B: []int{1}}}, 1209 }, 1210 { 1211 name: "PtrHeadSliceMultiFieldsNotRootOmitEmpty", 1212 data: &struct { 1213 A struct { 1214 A []int `json:"a,omitempty"` 1215 } 1216 B struct { 1217 B []int `json:"b,omitempty"` 1218 } 1219 }{A: struct { 1220 A []int `json:"a,omitempty"` 1221 }{A: []int{-1}}, B: struct { 1222 B []int `json:"b,omitempty"` 1223 }{B: []int{1}}}, 1224 }, 1225 { 1226 name: "PtrHeadSliceMultiFieldsNotRootString", 1227 data: &struct { 1228 A struct { 1229 A []int `json:"a,string"` 1230 } 1231 B struct { 1232 B []int `json:"b,string"` 1233 } 1234 }{A: struct { 1235 A []int `json:"a,string"` 1236 }{A: []int{-1}}, B: struct { 1237 B []int `json:"b,string"` 1238 }{B: []int{1}}}, 1239 }, 1240 1241 // PtrHeadSlicePtrMultiFieldsNotRoot 1242 { 1243 name: "PtrHeadSlicePtrMultiFieldsNotRoot", 1244 data: &struct { 1245 A *struct { 1246 A *[]int `json:"a"` 1247 } 1248 B *struct { 1249 B *[]int `json:"b"` 1250 } 1251 }{A: &(struct { 1252 A *[]int `json:"a"` 1253 }{A: sliceptr([]int{-1})}), B: &(struct { 1254 B *[]int `json:"b"` 1255 }{B: sliceptr([]int{1})})}, 1256 }, 1257 { 1258 name: "PtrHeadSlicePtrMultiFieldsNotRootOmitEmpty", 1259 data: &struct { 1260 A *struct { 1261 A *[]int `json:"a,omitempty"` 1262 } 1263 B *struct { 1264 B *[]int `json:"b,omitempty"` 1265 } 1266 }{A: &(struct { 1267 A *[]int `json:"a,omitempty"` 1268 }{A: sliceptr([]int{-1})}), B: &(struct { 1269 B *[]int `json:"b,omitempty"` 1270 }{B: sliceptr([]int{1})})}, 1271 }, 1272 { 1273 name: "PtrHeadSlicePtrMultiFieldsNotRootString", 1274 data: &struct { 1275 A *struct { 1276 A *[]int `json:"a,string"` 1277 } 1278 B *struct { 1279 B *[]int `json:"b,string"` 1280 } 1281 }{A: &(struct { 1282 A *[]int `json:"a,string"` 1283 }{A: sliceptr([]int{-1})}), B: &(struct { 1284 B *[]int `json:"b,string"` 1285 }{B: sliceptr([]int{1})})}, 1286 }, 1287 1288 // PtrHeadSlicePtrNilMultiFieldsNotRoot 1289 { 1290 name: "PtrHeadSlicePtrNilMultiFieldsNotRoot", 1291 data: &struct { 1292 A *struct { 1293 A *[]int `json:"a"` 1294 } 1295 B *struct { 1296 B *[]int `json:"b"` 1297 } 1298 }{A: nil, B: nil}, 1299 }, 1300 { 1301 name: "PtrHeadSlicePtrNilMultiFieldsNotRootOmitEmpty", 1302 data: &struct { 1303 A *struct { 1304 A *[]int `json:"a,omitempty"` 1305 } `json:",omitempty"` 1306 B *struct { 1307 B *[]int `json:"b,omitempty"` 1308 } `json:",omitempty"` 1309 }{A: nil, B: nil}, 1310 }, 1311 { 1312 name: "PtrHeadSlicePtrNilMultiFieldsNotRootString", 1313 data: &struct { 1314 A *struct { 1315 A *[]int `json:"a,string"` 1316 } `json:",string"` 1317 B *struct { 1318 B *[]int `json:"b,string"` 1319 } `json:",string"` 1320 }{A: nil, B: nil}, 1321 }, 1322 1323 // PtrHeadSliceNilMultiFieldsNotRoot 1324 { 1325 name: "PtrHeadSliceNilMultiFieldsNotRoot", 1326 data: (*struct { 1327 A *struct { 1328 A *[]int `json:"a"` 1329 } 1330 B *struct { 1331 B *[]int `json:"b"` 1332 } 1333 })(nil), 1334 }, 1335 { 1336 name: "PtrHeadSliceNilMultiFieldsNotRootOmitEmpty", 1337 data: (*struct { 1338 A *struct { 1339 A *[]int `json:"a,omitempty"` 1340 } 1341 B *struct { 1342 B *[]int `json:"b,omitempty"` 1343 } 1344 })(nil), 1345 }, 1346 { 1347 name: "PtrHeadSliceNilMultiFieldsNotRootString", 1348 data: (*struct { 1349 A *struct { 1350 A *[]int `json:"a,string"` 1351 } 1352 B *struct { 1353 B *[]int `json:"b,string"` 1354 } 1355 })(nil), 1356 }, 1357 1358 // PtrHeadSliceDoubleMultiFieldsNotRoot 1359 { 1360 name: "PtrHeadSliceDoubleMultiFieldsNotRoot", 1361 data: &struct { 1362 A *struct { 1363 A []int `json:"a"` 1364 B []int `json:"b"` 1365 } 1366 B *struct { 1367 A []int `json:"a"` 1368 B []int `json:"b"` 1369 } 1370 }{A: &(struct { 1371 A []int `json:"a"` 1372 B []int `json:"b"` 1373 }{A: []int{-1}, B: []int{1}}), B: &(struct { 1374 A []int `json:"a"` 1375 B []int `json:"b"` 1376 }{A: []int{-1}, B: nil})}, 1377 }, 1378 { 1379 name: "PtrHeadSliceDoubleMultiFieldsNotRootOmitEmpty", 1380 data: &struct { 1381 A *struct { 1382 A []int `json:"a,omitempty"` 1383 B []int `json:"b,omitempty"` 1384 } 1385 B *struct { 1386 A []int `json:"a,omitempty"` 1387 B []int `json:"b,omitempty"` 1388 } 1389 }{A: &(struct { 1390 A []int `json:"a,omitempty"` 1391 B []int `json:"b,omitempty"` 1392 }{A: []int{-1}, B: []int{1}}), B: &(struct { 1393 A []int `json:"a,omitempty"` 1394 B []int `json:"b,omitempty"` 1395 }{A: []int{-1}, B: nil})}, 1396 }, 1397 { 1398 name: "PtrHeadSliceDoubleMultiFieldsNotRootString", 1399 data: &struct { 1400 A *struct { 1401 A []int `json:"a,string"` 1402 B []int `json:"b,string"` 1403 } 1404 B *struct { 1405 A []int `json:"a,string"` 1406 B []int `json:"b,string"` 1407 } 1408 }{A: &(struct { 1409 A []int `json:"a,string"` 1410 B []int `json:"b,string"` 1411 }{A: []int{-1}, B: []int{1}}), B: &(struct { 1412 A []int `json:"a,string"` 1413 B []int `json:"b,string"` 1414 }{A: []int{-1}, B: nil})}, 1415 }, 1416 1417 // PtrHeadSliceNilDoubleMultiFieldsNotRoot 1418 { 1419 name: "PtrHeadSliceNilDoubleMultiFieldsNotRoot", 1420 data: &struct { 1421 A *struct { 1422 A []int `json:"a"` 1423 B []int `json:"b"` 1424 } 1425 B *struct { 1426 A []int `json:"a"` 1427 B []int `json:"b"` 1428 } 1429 }{A: nil, B: nil}, 1430 }, 1431 { 1432 name: "PtrHeadSliceNilDoubleMultiFieldsNotRootOmitEmpty", 1433 data: &struct { 1434 A *struct { 1435 A []int `json:"a,omitempty"` 1436 B []int `json:"b,omitempty"` 1437 } `json:",omitempty"` 1438 B *struct { 1439 A []int `json:"a,omitempty"` 1440 B []int `json:"b,omitempty"` 1441 } `json:",omitempty"` 1442 }{A: nil, B: nil}, 1443 }, 1444 { 1445 name: "PtrHeadSliceNilDoubleMultiFieldsNotRootString", 1446 data: &struct { 1447 A *struct { 1448 A []int `json:"a,string"` 1449 B []int `json:"b,string"` 1450 } 1451 B *struct { 1452 A []int `json:"a,string"` 1453 B []int `json:"b,string"` 1454 } 1455 }{A: nil, B: nil}, 1456 }, 1457 1458 // PtrHeadSliceNilDoubleMultiFieldsNotRoot 1459 { 1460 name: "PtrHeadSliceNilDoubleMultiFieldsNotRoot", 1461 data: (*struct { 1462 A *struct { 1463 A []int `json:"a"` 1464 B []int `json:"b"` 1465 } 1466 B *struct { 1467 A []int `json:"a"` 1468 B []int `json:"b"` 1469 } 1470 })(nil), 1471 }, 1472 { 1473 name: "PtrHeadSliceNilDoubleMultiFieldsNotRootOmitEmpty", 1474 data: (*struct { 1475 A *struct { 1476 A []int `json:"a,omitempty"` 1477 B []int `json:"b,omitempty"` 1478 } 1479 B *struct { 1480 A []int `json:"a,omitempty"` 1481 B []int `json:"b,omitempty"` 1482 } 1483 })(nil), 1484 }, 1485 { 1486 name: "PtrHeadSliceNilDoubleMultiFieldsNotRootString", 1487 data: (*struct { 1488 A *struct { 1489 A []int `json:"a,string"` 1490 B []int `json:"b,string"` 1491 } 1492 B *struct { 1493 A []int `json:"a,string"` 1494 B []int `json:"b,string"` 1495 } 1496 })(nil), 1497 }, 1498 1499 // PtrHeadSlicePtrDoubleMultiFieldsNotRoot 1500 { 1501 name: "PtrHeadSlicePtrDoubleMultiFieldsNotRoot", 1502 data: &struct { 1503 A *struct { 1504 A *[]int `json:"a"` 1505 B *[]int `json:"b"` 1506 } 1507 B *struct { 1508 A *[]int `json:"a"` 1509 B *[]int `json:"b"` 1510 } 1511 }{A: &(struct { 1512 A *[]int `json:"a"` 1513 B *[]int `json:"b"` 1514 }{A: sliceptr([]int{-1}), B: sliceptr([]int{1})}), B: &(struct { 1515 A *[]int `json:"a"` 1516 B *[]int `json:"b"` 1517 }{A: nil, B: nil})}, 1518 }, 1519 { 1520 name: "PtrHeadSlicePtrDoubleMultiFieldsNotRootOmitEmpty", 1521 data: &struct { 1522 A *struct { 1523 A *[]int `json:"a,omitempty"` 1524 B *[]int `json:"b,omitempty"` 1525 } 1526 B *struct { 1527 A *[]int `json:"a,omitempty"` 1528 B *[]int `json:"b,omitempty"` 1529 } 1530 }{A: &(struct { 1531 A *[]int `json:"a,omitempty"` 1532 B *[]int `json:"b,omitempty"` 1533 }{A: sliceptr([]int{-1}), B: sliceptr([]int{1})}), B: &(struct { 1534 A *[]int `json:"a,omitempty"` 1535 B *[]int `json:"b,omitempty"` 1536 }{A: nil, B: nil})}, 1537 }, 1538 { 1539 name: "PtrHeadSlicePtrDoubleMultiFieldsNotRootString", 1540 data: &struct { 1541 A *struct { 1542 A *[]int `json:"a,string"` 1543 B *[]int `json:"b,string"` 1544 } 1545 B *struct { 1546 A *[]int `json:"a,string"` 1547 B *[]int `json:"b,string"` 1548 } 1549 }{A: &(struct { 1550 A *[]int `json:"a,string"` 1551 B *[]int `json:"b,string"` 1552 }{A: sliceptr([]int{-1}), B: sliceptr([]int{1})}), B: &(struct { 1553 A *[]int `json:"a,string"` 1554 B *[]int `json:"b,string"` 1555 }{A: nil, B: nil})}, 1556 }, 1557 1558 // PtrHeadSlicePtrNilDoubleMultiFieldsNotRoot 1559 { 1560 name: "PtrHeadSlicePtrNilDoubleMultiFieldsNotRoot", 1561 data: &struct { 1562 A *struct { 1563 A *[]int `json:"a"` 1564 B *[]int `json:"b"` 1565 } 1566 B *struct { 1567 A *[]int `json:"a"` 1568 B *[]int `json:"b"` 1569 } 1570 }{A: nil, B: nil}, 1571 }, 1572 { 1573 name: "PtrHeadSlicePtrNilDoubleMultiFieldsNotRootOmitEmpty", 1574 data: &struct { 1575 A *struct { 1576 A *[]int `json:"a,omitempty"` 1577 B *[]int `json:"b,omitempty"` 1578 } `json:",omitempty"` 1579 B *struct { 1580 A *[]int `json:"a,omitempty"` 1581 B *[]int `json:"b,omitempty"` 1582 } `json:",omitempty"` 1583 }{A: nil, B: nil}, 1584 }, 1585 { 1586 name: "PtrHeadSlicePtrNilDoubleMultiFieldsNotRootString", 1587 data: &struct { 1588 A *struct { 1589 A *[]int `json:"a,string"` 1590 B *[]int `json:"b,string"` 1591 } 1592 B *struct { 1593 A *[]int `json:"a,string"` 1594 B *[]int `json:"b,string"` 1595 } 1596 }{A: nil, B: nil}, 1597 }, 1598 1599 // PtrHeadSlicePtrNilDoubleMultiFieldsNotRoot 1600 { 1601 name: "PtrHeadSlicePtrNilDoubleMultiFieldsNotRoot", 1602 data: (*struct { 1603 A *struct { 1604 A *[]int `json:"a"` 1605 B *[]int `json:"b"` 1606 } 1607 B *struct { 1608 A *[]int `json:"a"` 1609 B *[]int `json:"b"` 1610 } 1611 })(nil), 1612 }, 1613 { 1614 name: "PtrHeadSlicePtrNilDoubleMultiFieldsNotRootOmitEmpty", 1615 data: (*struct { 1616 A *struct { 1617 A *[]int `json:"a,omitempty"` 1618 B *[]int `json:"b,omitempty"` 1619 } 1620 B *struct { 1621 A *[]int `json:"a,omitempty"` 1622 B *[]int `json:"b,omitempty"` 1623 } 1624 })(nil), 1625 }, 1626 { 1627 name: "PtrHeadSlicePtrNilDoubleMultiFieldsNotRootString", 1628 data: (*struct { 1629 A *struct { 1630 A *[]int `json:"a,string"` 1631 B *[]int `json:"b,string"` 1632 } 1633 B *struct { 1634 A *[]int `json:"a,string"` 1635 B *[]int `json:"b,string"` 1636 } 1637 })(nil), 1638 }, 1639 1640 // AnonymousHeadSlice 1641 { 1642 name: "AnonymousHeadSlice", 1643 data: struct { 1644 structSlice 1645 B []int `json:"b"` 1646 }{ 1647 structSlice: structSlice{A: []int{-1}}, 1648 B: nil, 1649 }, 1650 }, 1651 { 1652 name: "AnonymousHeadSliceOmitEmpty", 1653 data: struct { 1654 structSliceOmitEmpty 1655 B []int `json:"b,omitempty"` 1656 }{ 1657 structSliceOmitEmpty: structSliceOmitEmpty{A: []int{-1}}, 1658 B: nil, 1659 }, 1660 }, 1661 { 1662 name: "AnonymousHeadSliceString", 1663 data: struct { 1664 structSliceString 1665 B []int `json:"b,string"` 1666 }{ 1667 structSliceString: structSliceString{A: []int{-1}}, 1668 B: nil, 1669 }, 1670 }, 1671 1672 // PtrAnonymousHeadSlice 1673 { 1674 name: "PtrAnonymousHeadSlice", 1675 data: struct { 1676 *structSlice 1677 B []int `json:"b"` 1678 }{ 1679 structSlice: &structSlice{A: []int{-1}}, 1680 B: nil, 1681 }, 1682 }, 1683 { 1684 name: "PtrAnonymousHeadSliceOmitEmpty", 1685 data: struct { 1686 *structSliceOmitEmpty 1687 B []int `json:"b,omitempty"` 1688 }{ 1689 structSliceOmitEmpty: &structSliceOmitEmpty{A: []int{-1}}, 1690 B: nil, 1691 }, 1692 }, 1693 { 1694 name: "PtrAnonymousHeadSliceString", 1695 data: struct { 1696 *structSliceString 1697 B []int `json:"b,string"` 1698 }{ 1699 structSliceString: &structSliceString{A: []int{-1}}, 1700 B: nil, 1701 }, 1702 }, 1703 1704 // PtrAnonymousHeadSliceNil 1705 { 1706 name: "PtrAnonymousHeadSliceNil", 1707 data: struct { 1708 *structSlice 1709 B []int `json:"b"` 1710 }{ 1711 structSlice: &structSlice{A: nil}, 1712 B: nil, 1713 }, 1714 }, 1715 { 1716 name: "PtrAnonymousHeadSliceNilOmitEmpty", 1717 data: struct { 1718 *structSliceOmitEmpty 1719 B []int `json:"b,omitempty"` 1720 }{ 1721 structSliceOmitEmpty: &structSliceOmitEmpty{A: nil}, 1722 B: nil, 1723 }, 1724 }, 1725 { 1726 name: "PtrAnonymousHeadSliceNilString", 1727 data: struct { 1728 *structSliceString 1729 B []int `json:"b,string"` 1730 }{ 1731 structSliceString: &structSliceString{A: nil}, 1732 B: nil, 1733 }, 1734 }, 1735 1736 // NilPtrAnonymousHeadSlice 1737 { 1738 name: "NilPtrAnonymousHeadSlice", 1739 data: struct { 1740 *structSlice 1741 B []int `json:"b"` 1742 }{ 1743 structSlice: nil, 1744 B: []int{-1}, 1745 }, 1746 }, 1747 { 1748 name: "NilPtrAnonymousHeadSliceOmitEmpty", 1749 data: struct { 1750 *structSliceOmitEmpty 1751 B []int `json:"b,omitempty"` 1752 }{ 1753 structSliceOmitEmpty: nil, 1754 B: []int{-1}, 1755 }, 1756 }, 1757 { 1758 name: "NilPtrAnonymousHeadSliceString", 1759 data: struct { 1760 *structSliceString 1761 B []int `json:"b,string"` 1762 }{ 1763 structSliceString: nil, 1764 B: []int{-1}, 1765 }, 1766 }, 1767 1768 // AnonymousHeadSlicePtr 1769 { 1770 name: "AnonymousHeadSlicePtr", 1771 data: struct { 1772 structSlicePtr 1773 B *[]int `json:"b"` 1774 }{ 1775 structSlicePtr: structSlicePtr{A: sliceptr([]int{-1})}, 1776 B: nil, 1777 }, 1778 }, 1779 { 1780 name: "AnonymousHeadSlicePtrOmitEmpty", 1781 data: struct { 1782 structSlicePtrOmitEmpty 1783 B *[]int `json:"b,omitempty"` 1784 }{ 1785 structSlicePtrOmitEmpty: structSlicePtrOmitEmpty{A: sliceptr([]int{-1})}, 1786 B: nil, 1787 }, 1788 }, 1789 { 1790 name: "AnonymousHeadSlicePtrString", 1791 data: struct { 1792 structSlicePtrString 1793 B *[]int `json:"b,string"` 1794 }{ 1795 structSlicePtrString: structSlicePtrString{A: sliceptr([]int{-1})}, 1796 B: nil, 1797 }, 1798 }, 1799 1800 // AnonymousHeadSlicePtrNil 1801 { 1802 name: "AnonymousHeadSlicePtrNil", 1803 data: struct { 1804 structSlicePtr 1805 B *[]int `json:"b"` 1806 }{ 1807 structSlicePtr: structSlicePtr{A: nil}, 1808 B: sliceptr([]int{-1}), 1809 }, 1810 }, 1811 { 1812 name: "AnonymousHeadSlicePtrNilOmitEmpty", 1813 data: struct { 1814 structSlicePtrOmitEmpty 1815 B *[]int `json:"b,omitempty"` 1816 }{ 1817 structSlicePtrOmitEmpty: structSlicePtrOmitEmpty{A: nil}, 1818 B: sliceptr([]int{-1}), 1819 }, 1820 }, 1821 { 1822 name: "AnonymousHeadSlicePtrNilString", 1823 data: struct { 1824 structSlicePtrString 1825 B *[]int `json:"b,string"` 1826 }{ 1827 structSlicePtrString: structSlicePtrString{A: nil}, 1828 B: sliceptr([]int{-1}), 1829 }, 1830 }, 1831 1832 // PtrAnonymousHeadSlicePtr 1833 { 1834 name: "PtrAnonymousHeadSlicePtr", 1835 data: struct { 1836 *structSlicePtr 1837 B *[]int `json:"b"` 1838 }{ 1839 structSlicePtr: &structSlicePtr{A: sliceptr([]int{-1})}, 1840 B: nil, 1841 }, 1842 }, 1843 { 1844 name: "PtrAnonymousHeadSlicePtrOmitEmpty", 1845 data: struct { 1846 *structSlicePtrOmitEmpty 1847 B *[]int `json:"b,omitempty"` 1848 }{ 1849 structSlicePtrOmitEmpty: &structSlicePtrOmitEmpty{A: sliceptr([]int{-1})}, 1850 B: nil, 1851 }, 1852 }, 1853 { 1854 name: "PtrAnonymousHeadSlicePtrString", 1855 data: struct { 1856 *structSlicePtrString 1857 B *[]int `json:"b,string"` 1858 }{ 1859 structSlicePtrString: &structSlicePtrString{A: sliceptr([]int{-1})}, 1860 B: nil, 1861 }, 1862 }, 1863 1864 // NilPtrAnonymousHeadSlicePtr 1865 { 1866 name: "NilPtrAnonymousHeadSlicePtr", 1867 data: struct { 1868 *structSlicePtr 1869 B *[]int `json:"b"` 1870 }{ 1871 structSlicePtr: nil, 1872 B: sliceptr([]int{-1}), 1873 }, 1874 }, 1875 { 1876 name: "NilPtrAnonymousHeadSlicePtrOmitEmpty", 1877 data: struct { 1878 *structSlicePtrOmitEmpty 1879 B *[]int `json:"b,omitempty"` 1880 }{ 1881 structSlicePtrOmitEmpty: nil, 1882 B: sliceptr([]int{-1}), 1883 }, 1884 }, 1885 { 1886 name: "NilPtrAnonymousHeadSlicePtrString", 1887 data: struct { 1888 *structSlicePtrString 1889 B *[]int `json:"b,string"` 1890 }{ 1891 structSlicePtrString: nil, 1892 B: sliceptr([]int{-1}), 1893 }, 1894 }, 1895 1896 // AnonymousHeadSliceOnly 1897 { 1898 name: "AnonymousHeadSliceOnly", 1899 data: struct { 1900 structSlice 1901 }{ 1902 structSlice: structSlice{A: []int{-1}}, 1903 }, 1904 }, 1905 { 1906 name: "AnonymousHeadSliceOnlyOmitEmpty", 1907 data: struct { 1908 structSliceOmitEmpty 1909 }{ 1910 structSliceOmitEmpty: structSliceOmitEmpty{A: []int{-1}}, 1911 }, 1912 }, 1913 { 1914 name: "AnonymousHeadSliceOnlyString", 1915 data: struct { 1916 structSliceString 1917 }{ 1918 structSliceString: structSliceString{A: []int{-1}}, 1919 }, 1920 }, 1921 1922 // PtrAnonymousHeadSliceOnly 1923 { 1924 name: "PtrAnonymousHeadSliceOnly", 1925 data: struct { 1926 *structSlice 1927 }{ 1928 structSlice: &structSlice{A: []int{-1}}, 1929 }, 1930 }, 1931 { 1932 name: "PtrAnonymousHeadSliceOnlyOmitEmpty", 1933 data: struct { 1934 *structSliceOmitEmpty 1935 }{ 1936 structSliceOmitEmpty: &structSliceOmitEmpty{A: []int{-1}}, 1937 }, 1938 }, 1939 { 1940 name: "PtrAnonymousHeadSliceOnlyString", 1941 data: struct { 1942 *structSliceString 1943 }{ 1944 structSliceString: &structSliceString{A: []int{-1}}, 1945 }, 1946 }, 1947 1948 // NilPtrAnonymousHeadSliceOnly 1949 { 1950 name: "NilPtrAnonymousHeadSliceOnly", 1951 data: struct { 1952 *structSlice 1953 }{ 1954 structSlice: nil, 1955 }, 1956 }, 1957 { 1958 name: "NilPtrAnonymousHeadSliceOnlyOmitEmpty", 1959 data: struct { 1960 *structSliceOmitEmpty 1961 }{ 1962 structSliceOmitEmpty: nil, 1963 }, 1964 }, 1965 { 1966 name: "NilPtrAnonymousHeadSliceOnlyString", 1967 data: struct { 1968 *structSliceString 1969 }{ 1970 structSliceString: nil, 1971 }, 1972 }, 1973 1974 // AnonymousHeadSlicePtrOnly 1975 { 1976 name: "AnonymousHeadSlicePtrOnly", 1977 data: struct { 1978 structSlicePtr 1979 }{ 1980 structSlicePtr: structSlicePtr{A: sliceptr([]int{-1})}, 1981 }, 1982 }, 1983 { 1984 name: "AnonymousHeadSlicePtrOnlyOmitEmpty", 1985 data: struct { 1986 structSlicePtrOmitEmpty 1987 }{ 1988 structSlicePtrOmitEmpty: structSlicePtrOmitEmpty{A: sliceptr([]int{-1})}, 1989 }, 1990 }, 1991 { 1992 name: "AnonymousHeadSlicePtrOnlyString", 1993 data: struct { 1994 structSlicePtrString 1995 }{ 1996 structSlicePtrString: structSlicePtrString{A: sliceptr([]int{-1})}, 1997 }, 1998 }, 1999 2000 // AnonymousHeadSlicePtrNilOnly 2001 { 2002 name: "AnonymousHeadSlicePtrNilOnly", 2003 data: struct { 2004 structSlicePtr 2005 }{ 2006 structSlicePtr: structSlicePtr{A: nil}, 2007 }, 2008 }, 2009 { 2010 name: "AnonymousHeadSlicePtrNilOnlyOmitEmpty", 2011 data: struct { 2012 structSlicePtrOmitEmpty 2013 }{ 2014 structSlicePtrOmitEmpty: structSlicePtrOmitEmpty{A: nil}, 2015 }, 2016 }, 2017 { 2018 name: "AnonymousHeadSlicePtrNilOnlyString", 2019 data: struct { 2020 structSlicePtrString 2021 }{ 2022 structSlicePtrString: structSlicePtrString{A: nil}, 2023 }, 2024 }, 2025 2026 // PtrAnonymousHeadSlicePtrOnly 2027 { 2028 name: "PtrAnonymousHeadSlicePtrOnly", 2029 data: struct { 2030 *structSlicePtr 2031 }{ 2032 structSlicePtr: &structSlicePtr{A: sliceptr([]int{-1})}, 2033 }, 2034 }, 2035 { 2036 name: "PtrAnonymousHeadSlicePtrOnlyOmitEmpty", 2037 data: struct { 2038 *structSlicePtrOmitEmpty 2039 }{ 2040 structSlicePtrOmitEmpty: &structSlicePtrOmitEmpty{A: sliceptr([]int{-1})}, 2041 }, 2042 }, 2043 { 2044 name: "PtrAnonymousHeadSlicePtrOnlyString", 2045 data: struct { 2046 *structSlicePtrString 2047 }{ 2048 structSlicePtrString: &structSlicePtrString{A: sliceptr([]int{-1})}, 2049 }, 2050 }, 2051 2052 // NilPtrAnonymousHeadSlicePtrOnly 2053 { 2054 name: "NilPtrAnonymousHeadSlicePtrOnly", 2055 data: struct { 2056 *structSlicePtr 2057 }{ 2058 structSlicePtr: nil, 2059 }, 2060 }, 2061 { 2062 name: "NilPtrAnonymousHeadSlicePtrOnlyOmitEmpty", 2063 data: struct { 2064 *structSlicePtrOmitEmpty 2065 }{ 2066 structSlicePtrOmitEmpty: nil, 2067 }, 2068 }, 2069 { 2070 name: "NilPtrAnonymousHeadSlicePtrOnlyString", 2071 data: struct { 2072 *structSlicePtrString 2073 }{ 2074 structSlicePtrString: nil, 2075 }, 2076 }, 2077 } 2078 for _, test := range tests { 2079 for _, indent := range []bool{true, false} { 2080 for _, htmlEscape := range []bool{true, false} { 2081 t.Run(fmt.Sprintf("%s_indent_%t_escape_%t", test.name, indent, htmlEscape), func(t *testing.T) { 2082 var buf bytes.Buffer 2083 enc := json.NewEncoder(&buf) 2084 enc.SetEscapeHTML(htmlEscape) 2085 if indent { 2086 enc.SetIndent("", " ") 2087 } 2088 if err := enc.Encode(test.data); err != nil { 2089 t.Fatalf("%s(htmlEscape:%v,indent:%v): %+v: %s", test.name, htmlEscape, indent, test.data, err) 2090 } 2091 stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) 2092 if buf.String() != stdresult { 2093 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()) 2094 } 2095 }) 2096 } 2097 } 2098 } 2099 }