File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -940,3 +940,32 @@ test('readTaggedFields', () => {
940940 // Position should be at the end
941941 strictEqual ( reader . position , buffer . length )
942942} )
943+
944+ test ( 'readNullableStruct - null' , ( ) => {
945+ const buffer = Buffer . from ( [
946+ 255 // -1 indicates null
947+ ] )
948+ const reader = new Reader ( new DynamicBuffer ( buffer ) )
949+ strictEqual (
950+ reader . readNullableStruct ( ( ) => {
951+ return { a : reader . readInt8 ( ) , b : reader . readInt8 ( ) }
952+ } ) ,
953+ null
954+ )
955+ } )
956+
957+ test ( 'readNullableStruct - non-null' , ( ) => {
958+ const buffer = Buffer . from ( [
959+ 1 , // 1 indicates non-null
960+ 42 , // first value
961+ 43 // second value
962+ ] )
963+
964+ const reader = new Reader ( new DynamicBuffer ( buffer ) )
965+ deepStrictEqual (
966+ reader . readNullableStruct ( ( ) => {
967+ return { a : reader . readInt8 ( ) , b : reader . readInt8 ( ) }
968+ } ) ,
969+ { a : 42 , b : 43 }
970+ )
971+ } )
You can’t perform that action at this time.
0 commit comments