@@ -16,16 +16,16 @@ describe("BufferDecoder", () => {
1616 const setNegAndPosIntAtOnce = exp => {
1717 let offset = exp / 8 ;
1818 let method = exp < 64 ? `setUint${ exp } ` : `setBigUint${ exp } ` ;
19- let number = exp < 64 ? Math . pow ( 2 , exp ) - 1 : 2n ** 64n - 1n ;
19+ let number = exp < 64 ? Math . pow ( 2 , exp ) - 1 : BigInt ( Math . pow ( 2 , 42 ) ) ;
2020
2121 // set positive
2222 dv . setUint8 ( 1 , marks [ `DEFAULT_MARK_UINT${ exp } ` ] ) ;
2323 dv [ method ] ( 2 , number ) ;
2424 // set negative
2525 dv . setUint8 ( 2 + offset , marks [ `DEFAULT_MARK_INT${ exp } ` ] ) ;
2626 dv [ method ] ( 3 + offset , number ) ;
27- decodeAndExpect ( 1 + offset , number , 0 , [ 0 ] ) ;
28- decodeAndExpect ( ( 1 + offset ) * 2 , - number , 1 , [ 1 ] ) ;
27+ decodeAndExpect ( 1 + offset , exp < 64 ? number : Number ( number ) , 0 , [ 0 ] ) ;
28+ decodeAndExpect ( ( 1 + offset ) * 2 , exp < 64 ? - number : - ( Number ( number ) ) , 1 , [ 1 ] ) ;
2929 } ;
3030
3131 beforeEach ( ( ) => {
@@ -65,6 +65,18 @@ describe("BufferDecoder", () => {
6565 decodeAndExpect ( 9 , 1.23456789012 , 0 ) ;
6666 } ) ;
6767
68+ it ( "decodes bigint correctly" , ( ) => {
69+ dv . setUint8 ( 1 , marks . DEFAULT_MARK_BIGINT ) ;
70+ dv . setBigUint64 ( 2 , 2n ) ;
71+ decodeAndExpect ( 9 , - 2n , 0 ) ;
72+ } ) ;
73+
74+ it ( "decodes ubigint correctly" , ( ) => {
75+ dv . setUint8 ( 1 , marks . DEFAULT_MARK_UBIGINT ) ;
76+ dv . setBigUint64 ( 2 , 2n ) ;
77+ decodeAndExpect ( 9 , 2n , 0 ) ;
78+ } ) ;
79+
6880 it ( "decodes boolean (both: true and false) correctly" , ( ) => {
6981 dv . setUint8 ( 1 , marks . DEFAULT_MARK_FBOOL ) ;
7082 dv . setUint8 ( 2 , marks . DEFAULT_MARK_TBOOL ) ;
0 commit comments