@@ -13,7 +13,7 @@ describe("encode", () => {
1313 assert . deepStrictEqual ( encode ( 3.14 ) , Uint8Array . from ( [ 0xcb , 0x40 , 0x9 , 0x1e , 0xb8 , 0x51 , 0xeb , 0x85 , 0x1f ] ) ) ;
1414 } ) ;
1515
16- it ( "encodes numbers in float32 when forceFloate32 =true" , ( ) => {
16+ it ( "encodes numbers in float32 when forceFloat32 =true" , ( ) => {
1717 assert . deepStrictEqual ( encode ( 3.14 , { forceFloat32 : true } ) , Uint8Array . from ( [ 0xca , 0x40 , 0x48 , 0xf5 , 0xc3 ] ) ) ;
1818 } ) ;
1919
@@ -25,6 +25,30 @@ describe("encode", () => {
2525 } ) ;
2626 } ) ;
2727
28+ context ( "forceFloat" , ( ) => {
29+ it ( "encodes integers as integers without forceIntegerToFloat" , ( ) => {
30+ assert . deepStrictEqual ( encode ( 3 ) , Uint8Array . from ( [ 0x3 ] ) ) ;
31+ } ) ;
32+
33+ it ( "encodes integers as floating point when forceIntegerToFloat=true" , ( ) => {
34+ assert . deepStrictEqual (
35+ encode ( 3 , { forceIntegerToFloat : true } ) ,
36+ Uint8Array . from ( [ 0xcb , 0x40 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
37+ ) ;
38+ } ) ;
39+
40+ it ( "encodes integers as float32 when forceIntegerToFloat=true and forceFloat32=true" , ( ) => {
41+ assert . deepStrictEqual (
42+ encode ( 3 , { forceIntegerToFloat : true , forceFloat32 : true } ) ,
43+ Uint8Array . from ( [ 0xca , 0x40 , 0x40 , 0x00 , 0x00 ] ) ,
44+ ) ;
45+ } ) ;
46+
47+ it ( "encodes integers as integers when forceIntegerToFloat=false" , ( ) => {
48+ assert . deepStrictEqual ( encode ( 3 , { forceIntegerToFloat : false } ) , Uint8Array . from ( [ 0x3 ] ) ) ;
49+ } ) ;
50+ } ) ;
51+
2852 context ( "ignoreUndefined" , ( ) => {
2953 it ( "encodes { foo: undefined } as is by default" , ( ) => {
3054 assert . deepStrictEqual ( decode ( encode ( { foo : undefined , bar : 42 } ) ) , { foo : null , bar : 42 } ) ;
0 commit comments