@@ -9,6 +9,7 @@ import { cbor } from "./cbor";
99import { bytesToFloat16 } from "./cbor-decode" ;
1010import { tagSymbol } from "./cbor-types" ;
1111import { dateToTag } from "./parseCborBody" ;
12+ import { nv } from "../serde" ;
1213
1314// syntax is ESM but the test target is CJS.
1415const here = __dirname ;
@@ -219,12 +220,23 @@ describe("cbor", () => {
219220 name : "object containing big numbers" ,
220221 data : {
221222 map : {
222- items : [ BigInt ( 1e80 ) ] ,
223+ items : [ BigInt ( 1e80 ) , BigInt ( 1e80 ) , nv ( "0.0000000001234000000001234" ) , nv ( "0.0000000001234000000001234" ) ] ,
224+ bigint : BigInt ( 1e80 ) ,
225+ bigDecimal : nv ( "0.0000000001234000000001234" ) ,
223226 } ,
224227 } ,
225228 cbor : allocByteArray ( [
226- 161 , 99 , 109 , 97 , 112 , 161 , 101 , 105 , 116 , 101 , 109 , 115 , 129 , 194 , 88 , 34 , 3 , 95 , 157 , 234 , 62 , 31 , 107 , 224 ,
227- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
229+ 161 , 99 , 109 , 97 , 112 , 163 , 101 , 105 , 116 , 101 , 109 , 115 , 132 , 194 , 88 , 34 , 3 , 95 , 157 , 234 , 62 , 31 , 107 , 224 ,
230+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 194 , 88 , 34 , 3 , 95 , 157 , 234 , 62 ,
231+ 31 , 107 , 224 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 162 , 102 , 115 , 116 ,
232+ 114 , 105 , 110 , 103 , 120 , 27 , 48 , 46 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 49 , 50 , 51 , 52 , 48 , 48 , 48 , 48 , 48 , 48 ,
233+ 48 , 48 , 49 , 50 , 51 , 52 , 100 , 116 , 121 , 112 , 101 , 106 , 98 , 105 , 103 , 68 , 101 , 99 , 105 , 109 , 97 , 108 , 162 , 102 ,
234+ 115 , 116 , 114 , 105 , 110 , 103 , 120 , 27 , 48 , 46 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 49 , 50 , 51 , 52 , 48 , 48 , 48 ,
235+ 48 , 48 , 48 , 48 , 48 , 49 , 50 , 51 , 52 , 100 , 116 , 121 , 112 , 101 , 106 , 98 , 105 , 103 , 68 , 101 , 99 , 105 , 109 , 97 , 108 ,
236+ 102 , 98 , 105 , 103 , 105 , 110 , 116 , 194 , 88 , 34 , 3 , 95 , 157 , 234 , 62 , 31 , 107 , 224 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
237+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 106 , 98 , 105 , 103 , 68 , 101 , 99 , 105 , 109 , 97 , 108 , 162 , 102 ,
238+ 115 , 116 , 114 , 105 , 110 , 103 , 120 , 27 , 48 , 46 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 49 , 50 , 51 , 52 , 48 , 48 , 48 ,
239+ 48 , 48 , 48 , 48 , 48 , 49 , 50 , 51 , 52 , 100 , 116 , 121 , 112 , 101 , 106 , 98 , 105 , 103 , 68 , 101 , 99 , 105 , 109 , 97 , 108 ,
228240 ] ) ,
229241 } ,
230242 ] ;
@@ -305,6 +317,60 @@ describe("cbor", () => {
305317 }
306318 } ) ;
307319
320+ it . only ( "should round-trip sequences of big numbers" , ( ) => {
321+ const sequence = {
322+ map : {
323+ items1 : [
324+ BigInt ( 1e20 ) ,
325+ BigInt ( 2e30 ) ,
326+ BigInt ( 3e40 ) ,
327+ BigInt ( 4e50 ) ,
328+ BigInt ( 5e60 ) ,
329+ BigInt ( 6e70 ) ,
330+ BigInt ( 7e80 ) ,
331+ BigInt ( 8e90 ) ,
332+ ] ,
333+ items2 : [ BigInt ( 1e20 ) , BigInt ( 2e30 ) , nv ( "0.0000000001123434" ) , nv ( "0.000000000126781234" ) ] ,
334+ items3 : [ nv ( "0.0000000001234000000001234" ) , nv ( "0.00000000678678001234" ) , BigInt ( 1e20 ) , BigInt ( 2e30 ) ] ,
335+ items4 : [
336+ BigInt ( 1e20 ) ,
337+ BigInt ( 2e30 ) ,
338+ nv ( "0.0000000001234000000001234" ) ,
339+ nv ( "0.0000067867867801234" ) ,
340+ BigInt ( 1e20 ) ,
341+ BigInt ( 2e30 ) ,
342+ nv ( "0.0000000001234000000001234" ) ,
343+ nv ( "0.000000000123678678678234" ) ,
344+ ] ,
345+ items5 : [
346+ nv ( "0.0000000001234000000001234" ) ,
347+ nv ( "0.00006786781234678678678" ) ,
348+ BigInt ( 1e20 ) ,
349+ BigInt ( 2e30 ) ,
350+ nv ( "0.0000000001234000000001234" ) ,
351+ nv ( "0.000000000123400000087678634" ) ,
352+ BigInt ( 1e20 ) ,
353+ BigInt ( 2e30 ) ,
354+ ] ,
355+ items6 : [
356+ nv ( "0.0000000001234000000001234" ) ,
357+ nv ( "0.00006786781234678678678" ) ,
358+ nv ( "0.0000000001234000000001234" ) ,
359+ nv ( "0.000000000123400000087678634" ) ,
360+ nv ( "0.0000000001234000000001234" ) ,
361+ nv ( "0.00006786781234678678678" ) ,
362+ nv ( "0.0000000001234000000001234" ) ,
363+ nv ( "0.000000000123400000087678634" ) ,
364+ ] ,
365+ } ,
366+ } ;
367+
368+ const serialized = cbor . serialize ( sequence ) ;
369+ const deserialized = cbor . deserialize ( serialized ) ;
370+
371+ expect ( deserialized ) . toEqual ( sequence ) ;
372+ } ) ;
373+
308374 it ( "should throw an error if serializing a tag with missing properties" , ( ) => {
309375 expect ( ( ) =>
310376 cbor . serialize ( {
0 commit comments