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