@@ -11,57 +11,57 @@ import
1111 unittest2, bigints, ./ utils, ../ cbor_serialization, ../ cbor_serialization/ pkg/ bigints
1212
1313suite " Test BigInt" :
14- test " Spec unsigned bignum tag encode" :
14+ dualTest " Spec unsigned bignum tag encode" :
1515 let val = " 18446744073709551616" .initBigInt
1616 let cbor = Cbor .encode (val)
1717 check cbor == " 0xc249010000000000000000" .unhex
1818
19- test " Spec negative bignum tag encode" :
19+ dualTest " Spec negative bignum tag encode" :
2020 let val = " -18446744073709551617" .initBigInt
2121 let cbor = Cbor .encode (val)
2222 check cbor == " 0xc349010000000000000000" .unhex
2323
24- test " Spec unsigned bignum tag decode" :
24+ dualTest " Spec unsigned bignum tag decode" :
2525 let val = " 0xc249010000000000000000" .unhex
2626 let cbor = Cbor .decode (val, BigInt )
2727 check cbor == " 18446744073709551616" .initBigInt
2828
29- test " Spec negative bignum tag decode" :
29+ dualTest " Spec negative bignum tag decode" :
3030 let val = " 0xc349010000000000000000" .unhex
3131 let cbor = Cbor .decode (val, BigInt )
3232 check cbor == " -18446744073709551617" .initBigInt
3333
34- test " Spec unsigned int encode" :
34+ dualTest " Spec unsigned int encode" :
3535 let val = " 18446744073709551615" .initBigInt
3636 let cbor = Cbor .encode (val)
3737 check cbor == " 0x1bffffffffffffffff" .unhex
3838
39- test " Spec negative int encode" :
39+ dualTest " Spec negative int encode" :
4040 let val = " -18446744073709551616" .initBigInt
4141 let cbor = Cbor .encode (val)
4242 check cbor == " 0x3bffffffffffffffff" .unhex
4343
44- test " Spec unsigned int decode" :
44+ dualTest " Spec unsigned int decode" :
4545 let val = " 0x1bffffffffffffffff" .unhex
4646 let cbor = Cbor .decode (val, BigInt )
4747 check cbor == " 18446744073709551615" .initBigInt
4848
49- test " Spec negative int decode" :
49+ dualTest " Spec negative int decode" :
5050 let val = " 0x3bffffffffffffffff" .unhex
5151 let cbor = Cbor .decode (val, BigInt )
5252 check cbor == " -18446744073709551616" .initBigInt
5353
54- test " Spec small int encode" :
54+ dualTest " Spec small int encode" :
5555 let val = " 1" .initBigInt
5656 let cbor = Cbor .encode (val)
5757 check cbor == " 0x01" .unhex
5858
59- test " Spec small int decode" :
59+ dualTest " Spec small int decode" :
6060 let val = " 0x01" .unhex
6161 let cbor = Cbor .decode (val, BigInt )
6262 check cbor == " 1" .initBigInt
6363
64- test " Tag Bignum bigNumBytesLimit" :
64+ dualTest " Tag Bignum bigNumBytesLimit" :
6565 let val = (initBigInt (1 ) shl 128 ) - initBigInt (1 )
6666 let cbor = Cbor .encode (val)
6767 check:
@@ -70,21 +70,21 @@ suite "Test BigInt":
7070 expect UnexpectedValueError :
7171 discard Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 15 ))
7272
73- test " Tag negative Bignum bigNumBytesLimit" :
74- var val = (initBigInt (1 ) shl 128 ) - initBigInt (1 )
75- val *= - 1 .initBigInt
76- let cbor = Cbor .encode (val)
77- check:
78- Cbor .decode (cbor, BigInt ) == val
79- Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 16 )) == val
80- expect UnexpectedValueError :
81- discard Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 15 ))
73+ dualTest " Tag negative Bignum bigNumBytesLimit" :
74+ var val = (initBigInt (1 ) shl 128 ) - initBigInt (1 )
75+ val *= - 1 .initBigInt
76+ let cbor = Cbor .encode (val)
77+ check:
78+ Cbor .decode (cbor, BigInt ) == val
79+ Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 16 )) == val
80+ expect UnexpectedValueError :
81+ discard Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 15 ))
8282
83- test " Tag negative Bignum bigNumBytesLimit" :
84- # this triggers the limit check for negativeTag
85- var val = (initBigInt (1 ) shl 128 ) # - initBigInt(1)
86- val *= - 1 .initBigInt
87- let cbor = Cbor .encode (val)
88- check Cbor .decode (cbor, BigInt ) == val
89- expect UnexpectedValueError :
90- discard Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 16 ))
83+ dualTest " Tag negative Bignum bigNumBytesLimit" :
84+ # this triggers the limit check for negativeTag
85+ var val = (initBigInt (1 ) shl 128 ) # - initBigInt(1)
86+ val *= - 1 .initBigInt
87+ let cbor = Cbor .encode (val)
88+ check Cbor .decode (cbor, BigInt ) == val
89+ expect UnexpectedValueError :
90+ discard Cbor .decode (cbor, BigInt , conf = CborReaderConf (bigNumBytesLimit: 16 ))
0 commit comments