@@ -141,6 +141,24 @@ var (
141141 {input : `0xbbb` , want : uint64 (0xbbb )},
142142 {input : `0xffffffffffffffff` , want : uint64 (0xffffffffffffffff )},
143143 }
144+
145+ decodeUint16Tests = []unmarshalTest {
146+ // invalid
147+ {input : `0` , wantErr : ErrMissingPrefix },
148+ {input : `0x` , wantErr : ErrEmptyNumber },
149+ {input : `0x01` , wantErr : ErrLeadingZero },
150+ {input : `0xfffff` , wantErr : ErrUint16Range },
151+ {input : `0xz1` , wantErr : ErrSyntax },
152+ // valid
153+ {input : `0x0` , want : uint16 (0 )},
154+ {input : `0x2` , want : uint16 (0x2 )},
155+ {input : `0x2F2` , want : uint16 (0x2f2 )},
156+ {input : `0X2F2` , want : uint16 (0x2f2 )},
157+ {input : `0xff` , want : uint16 (0xff )},
158+ {input : `0x12af` , want : uint16 (0x12af )},
159+ {input : `0xbbb` , want : uint16 (0xbbb )},
160+ {input : `0xffff` , want : uint16 (0xffff )},
161+ }
144162)
145163
146164func TestEncode (t * testing.T ) {
@@ -218,6 +236,19 @@ func TestDecodeUint64(t *testing.T) {
218236 }
219237}
220238
239+ func TestDecodeUint16 (t * testing.T ) {
240+ for _ , test := range decodeUint16Tests {
241+ dec , err := DecodeUint16 (test .input )
242+ if ! checkError (t , test .input , err , test .wantErr ) {
243+ continue
244+ }
245+ if dec != test .want .(uint16 ) {
246+ t .Errorf ("input %s: value mismatch: got %x, want %x" , test .input , dec , test .want )
247+ continue
248+ }
249+ }
250+ }
251+
221252func BenchmarkEncodeBig (b * testing.B ) {
222253 for _ , bench := range encodeBigTests {
223254 b .Run (bench .want , func (b * testing.B ) {
0 commit comments