github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/streamer_int_test.go (about) 1 package jzon 2 3 import ( 4 "math" 5 "testing" 6 ) 7 8 func TestStreamer_Int_ChainError(t *testing.T) { 9 t.Run("int8", func(t *testing.T) { 10 testStreamerChainError(t, func(s *Streamer) { 11 s.Int8(1) 12 }) 13 }) 14 t.Run("int16", func(t *testing.T) { 15 testStreamerChainError(t, func(s *Streamer) { 16 s.Int16(1) 17 }) 18 }) 19 t.Run("int32", func(t *testing.T) { 20 testStreamerChainError(t, func(s *Streamer) { 21 s.Int32(1) 22 }) 23 }) 24 t.Run("int64", func(t *testing.T) { 25 testStreamerChainError(t, func(s *Streamer) { 26 s.Int64(1) 27 }) 28 }) 29 t.Run("uint8", func(t *testing.T) { 30 testStreamerChainError(t, func(s *Streamer) { 31 s.Uint8(1) 32 }) 33 }) 34 t.Run("uint16", func(t *testing.T) { 35 testStreamerChainError(t, func(s *Streamer) { 36 s.Uint16(1) 37 }) 38 }) 39 t.Run("uint32", func(t *testing.T) { 40 testStreamerChainError(t, func(s *Streamer) { 41 s.Uint32(1) 42 }) 43 }) 44 t.Run("uint64", func(t *testing.T) { 45 testStreamerChainError(t, func(s *Streamer) { 46 s.Uint64(1) 47 }) 48 }) 49 } 50 51 func TestStreamer_Int8(t *testing.T) { 52 f := func(t *testing.T, i int8) { 53 checkEncodeWithStandard(t, i, func(s *Streamer) { 54 s.Int8(i) 55 }, nil) 56 } 57 t.Run("max", func(t *testing.T) { 58 f(t, math.MaxInt8) 59 }) 60 t.Run("min", func(t *testing.T) { 61 f(t, math.MinInt8) 62 }) 63 } 64 65 func TestStreamer_Uint8(t *testing.T) { 66 f := func(t *testing.T, i uint8) { 67 checkEncodeWithStandard(t, i, func(s *Streamer) { 68 s.Uint8(i) 69 }, nil) 70 } 71 t.Run("max", func(t *testing.T) { 72 f(t, math.MaxUint8) 73 }) 74 t.Run("min", func(t *testing.T) { 75 f(t, 0) 76 }) 77 } 78 79 func TestStreamer_Int16(t *testing.T) { 80 f := func(t *testing.T, i int16) { 81 checkEncodeWithStandard(t, i, func(s *Streamer) { 82 s.Int16(i) 83 }, nil) 84 } 85 t.Run("max", func(t *testing.T) { 86 f(t, math.MaxInt16) 87 }) 88 t.Run("min", func(t *testing.T) { 89 f(t, math.MinInt16) 90 }) 91 } 92 93 func TestStreamer_Uint16(t *testing.T) { 94 f := func(t *testing.T, i uint16) { 95 checkEncodeWithStandard(t, i, func(s *Streamer) { 96 s.Uint16(i) 97 }, nil) 98 } 99 t.Run("max", func(t *testing.T) { 100 f(t, math.MaxUint16) 101 }) 102 t.Run("min", func(t *testing.T) { 103 f(t, 0) 104 }) 105 } 106 107 func TestStreamer_Int32(t *testing.T) { 108 f := func(t *testing.T, i int32) { 109 checkEncodeWithStandard(t, i, func(s *Streamer) { 110 s.Int32(i) 111 }, nil) 112 } 113 t.Run("max", func(t *testing.T) { 114 f(t, math.MaxInt32) 115 }) 116 t.Run("min", func(t *testing.T) { 117 f(t, math.MinInt32) 118 }) 119 } 120 121 func TestStreamer_Uint32(t *testing.T) { 122 f := func(t *testing.T, i uint32) { 123 checkEncodeWithStandard(t, i, func(s *Streamer) { 124 s.Uint32(i) 125 }, nil) 126 } 127 t.Run("max", func(t *testing.T) { 128 f(t, math.MaxUint32) 129 }) 130 t.Run("min", func(t *testing.T) { 131 f(t, 0) 132 }) 133 t.Run("1023", func(t *testing.T) { 134 f(t, 1023) 135 }) 136 t.Run("1023045", func(t *testing.T) { 137 f(t, 1023045) 138 }) 139 } 140 141 func TestStreamer_Int64(t *testing.T) { 142 f := func(t *testing.T, i int64) { 143 checkEncodeWithStandard(t, i, func(s *Streamer) { 144 s.Int64(i) 145 }, nil) 146 } 147 t.Run("max", func(t *testing.T) { 148 f(t, math.MaxInt64) 149 }) 150 t.Run("min", func(t *testing.T) { 151 f(t, math.MinInt64) 152 }) 153 } 154 155 func TestStreamer_Uint64(t *testing.T) { 156 f := func(t *testing.T, i uint64) { 157 checkEncodeWithStandard(t, i, func(s *Streamer) { 158 s.Uint64(i) 159 }, nil) 160 } 161 t.Run("max", func(t *testing.T) { 162 f(t, math.MaxUint64) 163 }) 164 t.Run("min", func(t *testing.T) { 165 f(t, 0) 166 }) 167 t.Run("1023", func(t *testing.T) { 168 f(t, 1023) 169 }) 170 t.Run("1023045", func(t *testing.T) { 171 f(t, 1023045) 172 }) 173 t.Run("1023045067", func(t *testing.T) { 174 f(t, 1023045067) 175 }) 176 t.Run("1023045067089", func(t *testing.T) { 177 f(t, 1023045067089) 178 }) 179 t.Run("1023045067089000", func(t *testing.T) { 180 f(t, 1023045067089000) 181 }) 182 } 183 184 func TestStreamer_Int(t *testing.T) { 185 f := func(t *testing.T, i int) { 186 checkEncodeWithStandard(t, i, func(s *Streamer) { 187 s.Int(i) 188 }, nil) 189 } 190 t.Run("test", func(t *testing.T) { 191 f(t, math.MaxInt32) 192 }) 193 } 194 195 func TestStreamer_Uint(t *testing.T) { 196 f := func(t *testing.T, i uint) { 197 checkEncodeWithStandard(t, i, func(s *Streamer) { 198 s.Uint(i) 199 }, nil) 200 } 201 t.Run("test", func(t *testing.T) { 202 f(t, math.MaxUint32) 203 }) 204 }