@@ -578,6 +578,30 @@ class SerdesOctetTests {
578578 body = await content . toBuffer ( ) ;
579579 expect ( body ) . to . deep . equal ( Buffer . from ( [ 0x80 , 0x44 ] ) ) ;
580580
581+ content = await ContentSerdes . valueToContent (
582+ 255 ,
583+ { type : "uint8" } ,
584+ `application/octet-stream;byteSeq=${ Endianness . LITTLE_ENDIAN } ;length=1;`
585+ ) ;
586+ body = await content . toBuffer ( ) ;
587+ expect ( body ) . to . deep . equal ( Buffer . from ( [ 0xff ] ) ) ;
588+
589+ content = await ContentSerdes . valueToContent (
590+ 127 ,
591+ { type : "int8" } ,
592+ `application/octet-stream;signed=true;length=1;`
593+ ) ;
594+ body = await content . toBuffer ( ) ;
595+ expect ( body ) . to . deep . equal ( Buffer . from ( [ 0x7f ] ) ) ;
596+
597+ content = await ContentSerdes . valueToContent (
598+ - 128 ,
599+ { type : "int8" } ,
600+ `application/octet-stream;signed=true;length=1;`
601+ ) ;
602+ body = await content . toBuffer ( ) ;
603+ expect ( body ) . to . deep . equal ( Buffer . from ( [ 0x80 ] ) ) ;
604+
581605 content = ContentSerdes . valueToContent (
582606 2345 ,
583607 { type : "integer" , "ex:bitLength" : 24 } ,
@@ -742,15 +766,27 @@ class SerdesOctetTests {
742766 }
743767
744768 @test "value to OctetStream should throw" ( ) {
745- // @ts -ignore new dataschema types are not yet supported in the td type definitions
746- expect ( ( ) => ContentSerdes . valueToContent ( 2345 , { type : "int8" } , "application/octet-stream" ) ) . to . throw (
769+ expect ( ( ) => ContentSerdes . valueToContent ( 256 , { type : "uint8" } , "application/octet-stream" ) ) . to . throw (
770+ Error ,
771+ "Integer overflow when representing 256 as an unsigned integer using 8 bit(s)"
772+ ) ;
773+ expect ( ( ) => ContentSerdes . valueToContent ( - 1 , { type : "uint8" } , "application/octet-stream" ) ) . to . throw (
774+ Error ,
775+ "Integer overflow when representing -1 as an unsigned integer using 8 bit(s)"
776+ ) ;
777+ expect ( ( ) => ContentSerdes . valueToContent ( 128 , { type : "int8" } , "application/octet-stream" ) ) . to . throw (
778+ Error ,
779+ "Integer overflow when representing 128 as a signed integer using 8 bit(s)"
780+ ) ;
781+ expect ( ( ) => ContentSerdes . valueToContent ( - 129 , { type : "int8" } , "application/octet-stream" ) ) . to . throw (
747782 Error ,
748- "Integer overflow when representing signed 2345 in 8 bit(s)"
783+ "Integer overflow when representing -129 as a signed integer using 8 bit(s)"
749784 ) ;
785+
750786 // @ts -ignore new dataschema types are not yet supported in the td type definitions
751787 expect ( ( ) => ContentSerdes . valueToContent ( 23450000 , { type : "int16" } , "application/octet-stream" ) ) . to . throw (
752788 Error ,
753- "Integer overflow when representing signed 23450000 in 16 bit(s)"
789+ "Integer overflow when representing 23450000 as a signed integer using 16 bit(s)"
754790 ) ;
755791 expect ( ( ) => ContentSerdes . valueToContent ( 2345 , { type : "foo" } , "application/octet-stream" ) ) . to . throw (
756792 Error ,
@@ -768,14 +804,14 @@ class SerdesOctetTests {
768804 { type : "integer" , "ex:bitOffset" : 0 , "ex:bitLength" : 10 } ,
769805 "application/octet-stream"
770806 )
771- ) . to . throw ( Error , "Integer overflow when representing signed -2345 in 10 bit(s)" ) ;
807+ ) . to . throw ( Error , "Integer overflow when representing -2345 as a signed integer using 10 bit(s)" ) ;
772808 expect ( ( ) =>
773809 ContentSerdes . valueToContent (
774810 - 32769 ,
775811 { type : "integer" , "ex:bitOffset" : 0 , "ex:bitLength" : 16 } ,
776812 "application/octet-stream"
777813 )
778- ) . to . throw ( Error , "Integer overflow when representing signed -32769 in 16 bit(s)" ) ;
814+ ) . to . throw ( Error , "Integer overflow when representing -32769 as a signed integer using 16 bit(s)" ) ;
779815 expect ( ( ) =>
780816 ContentSerdes . valueToContent (
781817 { flag1 : true , flag2 : false , numberProperty : 99 , stringProperty : "Web" } ,
0 commit comments