github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_encoder_native_uint_test.go (about) 1 package jzon 2 3 import ( 4 "math" 5 "testing" 6 ) 7 8 func TestValEncoder_Uint(t *testing.T) { 9 f := func(t *testing.T, i uint) { 10 checkEncodeValueWithStandard(t, i, nil) 11 } 12 t.Run("test", func(t *testing.T) { 13 f(t, math.MaxUint32) 14 }) 15 t.Run("nil pointer", func(t *testing.T) { 16 checkEncodeValueWithStandard(t, (*uint)(nil), nil) 17 }) 18 t.Run("pointer", func(t *testing.T) { 19 i := uint(math.MaxUint32) 20 checkEncodeValueWithStandard(t, &i, nil) 21 }) 22 } 23 24 func TestValEncoder_Uint8(t *testing.T) { 25 f := func(t *testing.T, i uint8) { 26 checkEncodeValueWithStandard(t, i, nil) 27 } 28 t.Run("test", func(t *testing.T) { 29 f(t, math.MaxUint8) 30 }) 31 t.Run("nil pointer", func(t *testing.T) { 32 checkEncodeValueWithStandard(t, (*uint8)(nil), nil) 33 }) 34 t.Run("pointer", func(t *testing.T) { 35 i := uint8(math.MaxUint8) 36 checkEncodeValueWithStandard(t, &i, nil) 37 }) 38 } 39 40 func TestValEncoder_Uint16(t *testing.T) { 41 f := func(t *testing.T, i uint16) { 42 checkEncodeValueWithStandard(t, i, nil) 43 } 44 t.Run("test", func(t *testing.T) { 45 f(t, math.MaxUint16) 46 }) 47 t.Run("nil pointer", func(t *testing.T) { 48 checkEncodeValueWithStandard(t, (*uint16)(nil), nil) 49 }) 50 t.Run("pointer", func(t *testing.T) { 51 i := uint16(math.MaxUint16) 52 checkEncodeValueWithStandard(t, &i, nil) 53 }) 54 } 55 56 func TestValEncoder_Uint32(t *testing.T) { 57 f := func(t *testing.T, i uint32) { 58 checkEncodeValueWithStandard(t, i, nil) 59 } 60 t.Run("test", func(t *testing.T) { 61 f(t, math.MaxUint32) 62 }) 63 t.Run("nil pointer", func(t *testing.T) { 64 checkEncodeValueWithStandard(t, (*uint32)(nil), nil) 65 }) 66 t.Run("pointer", func(t *testing.T) { 67 i := uint32(math.MaxUint32) 68 checkEncodeValueWithStandard(t, &i, nil) 69 }) 70 } 71 72 func TestValEncoder_Uint64(t *testing.T) { 73 f := func(t *testing.T, i uint64) { 74 checkEncodeValueWithStandard(t, i, nil) 75 } 76 t.Run("test", func(t *testing.T) { 77 f(t, math.MaxUint64) 78 }) 79 t.Run("nil pointer", func(t *testing.T) { 80 checkEncodeValueWithStandard(t, (*uint64)(nil), nil) 81 }) 82 t.Run("pointer", func(t *testing.T) { 83 i := uint64(math.MaxUint64) 84 checkEncodeValueWithStandard(t, &i, nil) 85 }) 86 } 87 88 func TestValEncoder_Uint_OmitEmpty(t *testing.T) { 89 type st struct { 90 U uint `json:",omitempty"` 91 U8 uint8 `json:",omitempty"` 92 U16 uint16 `json:",omitempty"` 93 U32 uint32 `json:",omitempty"` 94 U64 uint64 `json:",omitempty"` 95 Uptr uintptr `json:",omitempty"` 96 } 97 checkEncodeValueWithStandard(t, st{}, nil) 98 }