encode_number_int_test.go (18983B)
1 package gojay 2 3 import ( 4 "math" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestEncoderInt64(t *testing.T) { 12 var testCasesBasic = []struct { 13 name string 14 v int64 15 expectedJSON string 16 }{ 17 { 18 name: "basic", 19 v: int64(1), 20 expectedJSON: "[1,1]", 21 }, 22 { 23 name: "big", 24 v: math.MaxInt64, 25 expectedJSON: "[9223372036854775807,9223372036854775807]", 26 }, 27 { 28 name: "big", 29 v: int64(0), 30 expectedJSON: "[0,0]", 31 }, 32 } 33 for _, testCase := range testCasesBasic { 34 t.Run(testCase.name, func(t *testing.T) { 35 var b = &strings.Builder{} 36 var enc = NewEncoder(b) 37 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 38 enc.Int64(testCase.v) 39 enc.AddInt64(testCase.v) 40 })) 41 assert.Equal(t, testCase.expectedJSON, b.String()) 42 }) 43 } 44 45 var testCasesOmitEmpty = []struct { 46 name string 47 v int64 48 expectedJSON string 49 }{ 50 { 51 name: "basic", 52 v: int64(1), 53 expectedJSON: "[1,1]", 54 }, 55 { 56 name: "big", 57 v: math.MaxInt64, 58 expectedJSON: "[9223372036854775807,9223372036854775807]", 59 }, 60 { 61 name: "big", 62 v: int64(0), 63 expectedJSON: "[]", 64 }, 65 } 66 for _, testCase := range testCasesOmitEmpty { 67 t.Run(testCase.name, func(t *testing.T) { 68 var b = &strings.Builder{} 69 var enc = NewEncoder(b) 70 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 71 enc.Int64OmitEmpty(testCase.v) 72 enc.AddInt64OmitEmpty(testCase.v) 73 })) 74 assert.Equal(t, testCase.expectedJSON, b.String()) 75 }) 76 } 77 var testCasesKeyBasic = []struct { 78 name string 79 v int64 80 expectedJSON string 81 }{ 82 { 83 name: "basic", 84 v: int64(1), 85 expectedJSON: `{"foo":1,"bar":1}`, 86 }, 87 { 88 name: "big", 89 v: math.MaxInt64, 90 expectedJSON: `{"foo":9223372036854775807,"bar":9223372036854775807}`, 91 }, 92 { 93 name: "big", 94 v: int64(0), 95 expectedJSON: `{"foo":0,"bar":0}`, 96 }, 97 } 98 for _, testCase := range testCasesKeyBasic { 99 t.Run(testCase.name, func(t *testing.T) { 100 var b = &strings.Builder{} 101 var enc = NewEncoder(b) 102 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 103 enc.Int64Key("foo", testCase.v) 104 enc.AddInt64Key("bar", testCase.v) 105 })) 106 assert.Equal(t, testCase.expectedJSON, b.String()) 107 }) 108 } 109 110 var testCasesKeyOmitEmpty = []struct { 111 name string 112 v int64 113 expectedJSON string 114 }{ 115 { 116 name: "basic", 117 v: int64(1), 118 expectedJSON: `{"foo":1,"bar":1}`, 119 }, 120 { 121 name: "big", 122 v: math.MaxInt64, 123 expectedJSON: `{"foo":9223372036854775807,"bar":9223372036854775807}`, 124 }, 125 { 126 name: "big", 127 v: int64(0), 128 expectedJSON: `{}`, 129 }, 130 } 131 for _, testCase := range testCasesKeyOmitEmpty { 132 t.Run(testCase.name, func(t *testing.T) { 133 var b = &strings.Builder{} 134 var enc = NewEncoder(b) 135 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 136 enc.Int64KeyOmitEmpty("foo", testCase.v) 137 enc.AddInt64KeyOmitEmpty("bar", testCase.v) 138 })) 139 assert.Equal(t, testCase.expectedJSON, b.String()) 140 }) 141 } 142 } 143 144 func TestEncoderInt32(t *testing.T) { 145 var testCasesBasic = []struct { 146 name string 147 v int32 148 expectedJSON string 149 }{ 150 { 151 name: "basic", 152 v: int32(1), 153 expectedJSON: "[1,1]", 154 }, 155 { 156 name: "big", 157 v: math.MaxInt32, 158 expectedJSON: "[2147483647,2147483647]", 159 }, 160 { 161 name: "big", 162 v: int32(0), 163 expectedJSON: "[0,0]", 164 }, 165 } 166 for _, testCase := range testCasesBasic { 167 t.Run(testCase.name, func(t *testing.T) { 168 var b = &strings.Builder{} 169 var enc = NewEncoder(b) 170 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 171 enc.Int32(testCase.v) 172 enc.AddInt32(testCase.v) 173 })) 174 assert.Equal(t, testCase.expectedJSON, b.String()) 175 }) 176 } 177 var testCasesOmitEmpty = []struct { 178 name string 179 v int32 180 expectedJSON string 181 }{ 182 { 183 name: "basic", 184 v: int32(1), 185 expectedJSON: "[1,1]", 186 }, 187 { 188 name: "big", 189 v: math.MaxInt32, 190 expectedJSON: "[2147483647,2147483647]", 191 }, 192 { 193 name: "big", 194 v: int32(0), 195 expectedJSON: "[]", 196 }, 197 } 198 for _, testCase := range testCasesOmitEmpty { 199 t.Run(testCase.name, func(t *testing.T) { 200 var b = &strings.Builder{} 201 var enc = NewEncoder(b) 202 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 203 enc.Int32OmitEmpty(testCase.v) 204 enc.AddInt32OmitEmpty(testCase.v) 205 })) 206 assert.Equal(t, testCase.expectedJSON, b.String()) 207 }) 208 } 209 var testCasesKeyBasic = []struct { 210 name string 211 v int32 212 expectedJSON string 213 }{ 214 { 215 name: "basic", 216 v: int32(1), 217 expectedJSON: `{"foo":1,"bar":1}`, 218 }, 219 { 220 name: "big", 221 v: math.MaxInt32, 222 expectedJSON: `{"foo":2147483647,"bar":2147483647}`, 223 }, 224 { 225 name: "big", 226 v: int32(0), 227 expectedJSON: `{"foo":0,"bar":0}`, 228 }, 229 } 230 for _, testCase := range testCasesKeyBasic { 231 t.Run(testCase.name, func(t *testing.T) { 232 var b = &strings.Builder{} 233 var enc = NewEncoder(b) 234 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 235 enc.Int32Key("foo", testCase.v) 236 enc.AddInt32Key("bar", testCase.v) 237 })) 238 assert.Equal(t, testCase.expectedJSON, b.String()) 239 }) 240 } 241 242 var testCasesKeyOmitEmpty = []struct { 243 name string 244 v int32 245 expectedJSON string 246 }{ 247 { 248 name: "basic", 249 v: int32(1), 250 expectedJSON: `{"foo":1,"bar":1}`, 251 }, 252 { 253 name: "big", 254 v: math.MaxInt32, 255 expectedJSON: `{"foo":2147483647,"bar":2147483647}`, 256 }, 257 { 258 name: "big", 259 v: int32(0), 260 expectedJSON: `{}`, 261 }, 262 } 263 for _, testCase := range testCasesKeyOmitEmpty { 264 t.Run(testCase.name, func(t *testing.T) { 265 var b = &strings.Builder{} 266 var enc = NewEncoder(b) 267 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 268 enc.Int32KeyOmitEmpty("foo", testCase.v) 269 enc.AddInt32KeyOmitEmpty("bar", testCase.v) 270 })) 271 assert.Equal(t, testCase.expectedJSON, b.String()) 272 }) 273 } 274 } 275 276 func TestEncoderInt16(t *testing.T) { 277 var testCasesBasic = []struct { 278 name string 279 v int16 280 expectedJSON string 281 }{ 282 { 283 name: "basic", 284 v: int16(1), 285 expectedJSON: "[1,1]", 286 }, 287 { 288 name: "big", 289 v: math.MaxInt16, 290 expectedJSON: "[32767,32767]", 291 }, 292 { 293 name: "big", 294 v: int16(0), 295 expectedJSON: "[0,0]", 296 }, 297 } 298 for _, testCase := range testCasesBasic { 299 t.Run(testCase.name, func(t *testing.T) { 300 var b = &strings.Builder{} 301 var enc = NewEncoder(b) 302 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 303 enc.Int16(testCase.v) 304 enc.AddInt16(testCase.v) 305 })) 306 assert.Equal(t, testCase.expectedJSON, b.String()) 307 }) 308 } 309 var testCasesOmitEmpty = []struct { 310 name string 311 v int16 312 expectedJSON string 313 }{ 314 { 315 name: "basic", 316 v: int16(1), 317 expectedJSON: "[1,1]", 318 }, 319 { 320 name: "big", 321 v: math.MaxInt16, 322 expectedJSON: "[32767,32767]", 323 }, 324 { 325 name: "big", 326 v: int16(0), 327 expectedJSON: "[]", 328 }, 329 } 330 for _, testCase := range testCasesOmitEmpty { 331 t.Run(testCase.name, func(t *testing.T) { 332 var b = &strings.Builder{} 333 var enc = NewEncoder(b) 334 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 335 enc.Int16OmitEmpty(testCase.v) 336 enc.AddInt16OmitEmpty(testCase.v) 337 })) 338 assert.Equal(t, testCase.expectedJSON, b.String()) 339 }) 340 } 341 var testCasesKeyBasic = []struct { 342 name string 343 v int16 344 expectedJSON string 345 }{ 346 { 347 name: "basic", 348 v: int16(1), 349 expectedJSON: `{"foo":1,"bar":1}`, 350 }, 351 { 352 name: "big", 353 v: math.MaxInt16, 354 expectedJSON: `{"foo":32767,"bar":32767}`, 355 }, 356 { 357 name: "big", 358 v: int16(0), 359 expectedJSON: `{"foo":0,"bar":0}`, 360 }, 361 } 362 for _, testCase := range testCasesKeyBasic { 363 t.Run(testCase.name, func(t *testing.T) { 364 var b = &strings.Builder{} 365 var enc = NewEncoder(b) 366 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 367 enc.Int16Key("foo", testCase.v) 368 enc.AddInt16Key("bar", testCase.v) 369 })) 370 assert.Equal(t, testCase.expectedJSON, b.String()) 371 }) 372 } 373 374 var testCasesKeyOmitEmpty = []struct { 375 name string 376 v int16 377 expectedJSON string 378 }{ 379 { 380 name: "basic", 381 v: int16(1), 382 expectedJSON: `{"foo":1,"bar":1}`, 383 }, 384 { 385 name: "big", 386 v: math.MaxInt16, 387 expectedJSON: `{"foo":32767,"bar":32767}`, 388 }, 389 { 390 name: "big", 391 v: int16(0), 392 expectedJSON: `{}`, 393 }, 394 } 395 for _, testCase := range testCasesKeyOmitEmpty { 396 t.Run(testCase.name, func(t *testing.T) { 397 var b = &strings.Builder{} 398 var enc = NewEncoder(b) 399 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 400 enc.Int16KeyOmitEmpty("foo", testCase.v) 401 enc.AddInt16KeyOmitEmpty("bar", testCase.v) 402 })) 403 assert.Equal(t, testCase.expectedJSON, b.String()) 404 }) 405 } 406 } 407 408 func TestEncoderInt8(t *testing.T) { 409 var testCasesBasic = []struct { 410 name string 411 v int8 412 expectedJSON string 413 }{ 414 { 415 name: "basic", 416 v: int8(1), 417 expectedJSON: "[1,1]", 418 }, 419 { 420 name: "big", 421 v: math.MaxInt8, 422 expectedJSON: "[127,127]", 423 }, 424 { 425 name: "big", 426 v: int8(0), 427 expectedJSON: "[0,0]", 428 }, 429 } 430 for _, testCase := range testCasesBasic { 431 t.Run(testCase.name, func(t *testing.T) { 432 var b = &strings.Builder{} 433 var enc = NewEncoder(b) 434 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 435 enc.Int8(testCase.v) 436 enc.AddInt8(testCase.v) 437 })) 438 assert.Equal(t, testCase.expectedJSON, b.String()) 439 }) 440 } 441 var testCasesOmitEmpty = []struct { 442 name string 443 v int8 444 expectedJSON string 445 }{ 446 { 447 name: "basic", 448 v: int8(1), 449 expectedJSON: "[1,1]", 450 }, 451 { 452 name: "big", 453 v: math.MaxInt8, 454 expectedJSON: "[127,127]", 455 }, 456 { 457 name: "big", 458 v: int8(0), 459 expectedJSON: "[]", 460 }, 461 } 462 for _, testCase := range testCasesOmitEmpty { 463 t.Run(testCase.name, func(t *testing.T) { 464 var b = &strings.Builder{} 465 var enc = NewEncoder(b) 466 enc.Encode(EncodeArrayFunc(func(enc *Encoder) { 467 enc.Int8OmitEmpty(testCase.v) 468 enc.AddInt8OmitEmpty(testCase.v) 469 })) 470 assert.Equal(t, testCase.expectedJSON, b.String()) 471 }) 472 } 473 var testCasesKeyBasic = []struct { 474 name string 475 v int8 476 expectedJSON string 477 }{ 478 { 479 name: "basic", 480 v: int8(1), 481 expectedJSON: `{"foo":1,"bar":1}`, 482 }, 483 { 484 name: "big", 485 v: math.MaxInt8, 486 expectedJSON: `{"foo":127,"bar":127}`, 487 }, 488 { 489 name: "big", 490 v: int8(0), 491 expectedJSON: `{"foo":0,"bar":0}`, 492 }, 493 } 494 for _, testCase := range testCasesKeyBasic { 495 t.Run(testCase.name, func(t *testing.T) { 496 var b = &strings.Builder{} 497 var enc = NewEncoder(b) 498 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 499 enc.Int8Key("foo", testCase.v) 500 enc.AddInt8Key("bar", testCase.v) 501 })) 502 assert.Equal(t, testCase.expectedJSON, b.String()) 503 }) 504 } 505 506 var testCasesKeyOmitEmpty = []struct { 507 name string 508 v int8 509 expectedJSON string 510 }{ 511 { 512 name: "basic", 513 v: int8(1), 514 expectedJSON: `{"foo":1,"bar":1}`, 515 }, 516 { 517 name: "big", 518 v: math.MaxInt8, 519 expectedJSON: `{"foo":127,"bar":127}`, 520 }, 521 { 522 name: "big", 523 v: int8(0), 524 expectedJSON: `{}`, 525 }, 526 } 527 for _, testCase := range testCasesKeyOmitEmpty { 528 t.Run(testCase.name, func(t *testing.T) { 529 var b = &strings.Builder{} 530 var enc = NewEncoder(b) 531 enc.Encode(EncodeObjectFunc(func(enc *Encoder) { 532 enc.Int8KeyOmitEmpty("foo", testCase.v) 533 enc.AddInt8KeyOmitEmpty("bar", testCase.v) 534 })) 535 assert.Equal(t, testCase.expectedJSON, b.String()) 536 }) 537 } 538 } 539 540 func TestEncoderIntNullEmpty(t *testing.T) { 541 var testCases = []struct { 542 name string 543 baseJSON string 544 expectedJSON string 545 }{ 546 { 547 name: "basic 1st elem", 548 baseJSON: "[", 549 expectedJSON: `[null,1`, 550 }, 551 { 552 name: "basic 2nd elem", 553 baseJSON: `["test"`, 554 expectedJSON: `["test",null,1`, 555 }, 556 } 557 for _, testCase := range testCases { 558 t.Run("true", func(t *testing.T) { 559 var b strings.Builder 560 var enc = NewEncoder(&b) 561 enc.writeString(testCase.baseJSON) 562 enc.IntNullEmpty(0) 563 enc.AddIntNullEmpty(1) 564 enc.Write() 565 assert.Equal(t, testCase.expectedJSON, b.String()) 566 }) 567 } 568 } 569 570 func TestEncoderIntKeyNullEmpty(t *testing.T) { 571 var testCases = []struct { 572 name string 573 baseJSON string 574 expectedJSON string 575 }{ 576 { 577 name: "basic 1st elem", 578 baseJSON: "{", 579 expectedJSON: `{"foo":null,"bar":1`, 580 }, 581 { 582 name: "basic 2nd elem", 583 baseJSON: `{"test":"test"`, 584 expectedJSON: `{"test":"test","foo":null,"bar":1`, 585 }, 586 } 587 for _, testCase := range testCases { 588 t.Run(testCase.name, func(t *testing.T) { 589 var b strings.Builder 590 var enc = NewEncoder(&b) 591 enc.writeString(testCase.baseJSON) 592 enc.IntKeyNullEmpty("foo", 0) 593 enc.AddIntKeyNullEmpty("bar", 1) 594 enc.Write() 595 assert.Equal(t, testCase.expectedJSON, b.String()) 596 }) 597 } 598 } 599 600 func TestEncoderInt64NullEmpty(t *testing.T) { 601 var testCases = []struct { 602 name string 603 baseJSON string 604 expectedJSON string 605 }{ 606 { 607 name: "basic 1st elem", 608 baseJSON: "[", 609 expectedJSON: `[null,1`, 610 }, 611 { 612 name: "basic 2nd elem", 613 baseJSON: `["test"`, 614 expectedJSON: `["test",null,1`, 615 }, 616 } 617 for _, testCase := range testCases { 618 t.Run("true", func(t *testing.T) { 619 var b strings.Builder 620 var enc = NewEncoder(&b) 621 enc.writeString(testCase.baseJSON) 622 enc.Int64NullEmpty(0) 623 enc.AddInt64NullEmpty(1) 624 enc.Write() 625 assert.Equal(t, testCase.expectedJSON, b.String()) 626 }) 627 } 628 } 629 630 func TestEncoderInt64KeyNullEmpty(t *testing.T) { 631 var testCases = []struct { 632 name string 633 baseJSON string 634 expectedJSON string 635 }{ 636 { 637 name: "basic 1st elem", 638 baseJSON: "{", 639 expectedJSON: `{"foo":null,"bar":1`, 640 }, 641 { 642 name: "basic 2nd elem", 643 baseJSON: `{"test":"test"`, 644 expectedJSON: `{"test":"test","foo":null,"bar":1`, 645 }, 646 } 647 for _, testCase := range testCases { 648 t.Run(testCase.name, func(t *testing.T) { 649 var b strings.Builder 650 var enc = NewEncoder(&b) 651 enc.writeString(testCase.baseJSON) 652 enc.Int64KeyNullEmpty("foo", 0) 653 enc.AddInt64KeyNullEmpty("bar", 1) 654 enc.Write() 655 assert.Equal(t, testCase.expectedJSON, b.String()) 656 }) 657 } 658 } 659 660 func TestEncoderInt32NullEmpty(t *testing.T) { 661 var testCases = []struct { 662 name string 663 baseJSON string 664 expectedJSON string 665 }{ 666 { 667 name: "basic 1st elem", 668 baseJSON: "[", 669 expectedJSON: `[null,1`, 670 }, 671 { 672 name: "basic 2nd elem", 673 baseJSON: `["test"`, 674 expectedJSON: `["test",null,1`, 675 }, 676 } 677 for _, testCase := range testCases { 678 t.Run("true", func(t *testing.T) { 679 var b strings.Builder 680 var enc = NewEncoder(&b) 681 enc.writeString(testCase.baseJSON) 682 enc.Int32NullEmpty(0) 683 enc.AddInt32NullEmpty(1) 684 enc.Write() 685 assert.Equal(t, testCase.expectedJSON, b.String()) 686 }) 687 } 688 } 689 690 func TestEncoderInt32KeyNullEmpty(t *testing.T) { 691 var testCases = []struct { 692 name string 693 baseJSON string 694 expectedJSON string 695 }{ 696 { 697 name: "basic 1st elem", 698 baseJSON: "{", 699 expectedJSON: `{"foo":null,"bar":1`, 700 }, 701 { 702 name: "basic 2nd elem", 703 baseJSON: `{"test":"test"`, 704 expectedJSON: `{"test":"test","foo":null,"bar":1`, 705 }, 706 } 707 for _, testCase := range testCases { 708 t.Run(testCase.name, func(t *testing.T) { 709 var b strings.Builder 710 var enc = NewEncoder(&b) 711 enc.writeString(testCase.baseJSON) 712 enc.Int32KeyNullEmpty("foo", 0) 713 enc.Int32KeyNullEmpty("bar", int32(1)) 714 enc.Write() 715 assert.Equal(t, testCase.expectedJSON, b.String()) 716 }) 717 } 718 } 719 720 func TestEncoderInt16NullEmpty(t *testing.T) { 721 var testCases = []struct { 722 name string 723 baseJSON string 724 expectedJSON string 725 }{ 726 { 727 name: "basic 1st elem", 728 baseJSON: "[", 729 expectedJSON: `[null,1`, 730 }, 731 { 732 name: "basic 2nd elem", 733 baseJSON: `["test"`, 734 expectedJSON: `["test",null,1`, 735 }, 736 } 737 for _, testCase := range testCases { 738 t.Run("true", func(t *testing.T) { 739 var b strings.Builder 740 var enc = NewEncoder(&b) 741 enc.writeString(testCase.baseJSON) 742 enc.Int16NullEmpty(0) 743 enc.Int16NullEmpty(1) 744 enc.Write() 745 assert.Equal(t, testCase.expectedJSON, b.String()) 746 }) 747 } 748 } 749 750 func TestEncoderInt16KeyNullEmpty(t *testing.T) { 751 var testCases = []struct { 752 name string 753 baseJSON string 754 expectedJSON string 755 }{ 756 { 757 name: "basic 1st elem", 758 baseJSON: "{", 759 expectedJSON: `{"foo":null,"bar":1`, 760 }, 761 { 762 name: "basic 2nd elem", 763 baseJSON: `{"test":"test"`, 764 expectedJSON: `{"test":"test","foo":null,"bar":1`, 765 }, 766 } 767 for _, testCase := range testCases { 768 t.Run(testCase.name, func(t *testing.T) { 769 var b strings.Builder 770 var enc = NewEncoder(&b) 771 enc.writeString(testCase.baseJSON) 772 enc.AddInt16KeyNullEmpty("foo", 0) 773 enc.Int16KeyNullEmpty("bar", int16(1)) 774 enc.Write() 775 assert.Equal(t, testCase.expectedJSON, b.String()) 776 }) 777 } 778 } 779 780 func TestEncoderInt8NullEmpty(t *testing.T) { 781 var testCases = []struct { 782 name string 783 baseJSON string 784 expectedJSON string 785 }{ 786 { 787 name: "basic 1st elem", 788 baseJSON: "[", 789 expectedJSON: `[null,1`, 790 }, 791 { 792 name: "basic 2nd elem", 793 baseJSON: `["test"`, 794 expectedJSON: `["test",null,1`, 795 }, 796 } 797 for _, testCase := range testCases { 798 t.Run("true", func(t *testing.T) { 799 var b strings.Builder 800 var enc = NewEncoder(&b) 801 enc.writeString(testCase.baseJSON) 802 enc.AddInt8NullEmpty(0) 803 enc.Int8NullEmpty(1) 804 enc.Write() 805 assert.Equal(t, testCase.expectedJSON, b.String()) 806 }) 807 } 808 } 809 810 func TestEncoderInt8KeyNullEmpty(t *testing.T) { 811 var testCases = []struct { 812 name string 813 baseJSON string 814 expectedJSON string 815 }{ 816 { 817 name: "basic 1st elem", 818 baseJSON: "{", 819 expectedJSON: `{"foo":null,"bar":1`, 820 }, 821 { 822 name: "basic 2nd elem", 823 baseJSON: `{"test":"test"`, 824 expectedJSON: `{"test":"test","foo":null,"bar":1`, 825 }, 826 } 827 for _, testCase := range testCases { 828 t.Run(testCase.name, func(t *testing.T) { 829 var b strings.Builder 830 var enc = NewEncoder(&b) 831 enc.writeString(testCase.baseJSON) 832 enc.AddInt8KeyNullEmpty("foo", 0) 833 enc.Int8KeyNullEmpty("bar", int8(1)) 834 enc.Write() 835 assert.Equal(t, testCase.expectedJSON, b.String()) 836 }) 837 } 838 }