@@ -13,7 +13,7 @@ describe("encode", () => {
13
13
assert . deepStrictEqual ( encode ( 3.14 ) , Uint8Array . from ( [ 0xcb , 0x40 , 0x9 , 0x1e , 0xb8 , 0x51 , 0xeb , 0x85 , 0x1f ] ) ) ;
14
14
} ) ;
15
15
16
- it ( "encodes numbers in float32 when forceFloate32 =true" , ( ) => {
16
+ it ( "encodes numbers in float32 when forceFloat32 =true" , ( ) => {
17
17
assert . deepStrictEqual ( encode ( 3.14 , { forceFloat32 : true } ) , Uint8Array . from ( [ 0xca , 0x40 , 0x48 , 0xf5 , 0xc3 ] ) ) ;
18
18
} ) ;
19
19
@@ -25,6 +25,36 @@ describe("encode", () => {
25
25
} ) ;
26
26
} ) ;
27
27
28
+ context ( "forceFloat" , ( ) => {
29
+ it ( "encodes integers as integers without forceFloat" , ( ) => {
30
+ assert . deepStrictEqual ( encode ( 3 ) , Uint8Array . from ( [ 0x3 ] ) ) ;
31
+ } ) ;
32
+
33
+ it ( "encodes integers as floating point when forceFloat=true" , ( ) => {
34
+ assert . deepStrictEqual (
35
+ encode ( 3 , { forceFloat : true } ) ,
36
+ Uint8Array . from ( [ 0xcb , 0x40 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
37
+ ) ;
38
+ } ) ;
39
+
40
+ it ( "encodes integers as floating point when forceFloat=true" , ( ) => {
41
+ assert . deepStrictEqual (
42
+ encode ( 3 , { forceFloat : true } ) ,
43
+ Uint8Array . from ( [ 0xcb , 0x40 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
44
+ ) ;
45
+ } ) ;
46
+
47
+ it ( "encodes integers as float32 when forceFloat=true and forceFloat32=true" , ( ) => {
48
+ assert . deepStrictEqual (
49
+ encode ( 3 , { forceFloat : true , forceFloat32 : true } ) ,
50
+ Uint8Array . from ( [ 0xca , 0x40 , 0x40 , 0x00 , 0x00 ] ) ) ;
51
+ } ) ;
52
+
53
+ it ( "encodes integers as integers when forceFloat=false" , ( ) => {
54
+ assert . deepStrictEqual ( encode ( 3 , { forceFloat : false } ) , Uint8Array . from ( [ 0x3 ] ) ) ;
55
+ } ) ;
56
+ } ) ;
57
+
28
58
context ( "ignoreUndefined" , ( ) => {
29
59
it ( "encodes { foo: undefined } as is by default" , ( ) => {
30
60
assert . deepStrictEqual ( decode ( encode ( { foo : undefined , bar : 42 } ) ) , { foo : null , bar : 42 } ) ;
0 commit comments