@@ -437,4 +437,59 @@ test('osc: MIDI type decoding with insufficient buffer data', (t) => {
437437 fromBuffer ( malformedBuffer ) ;
438438 } , / N o t e n o u g h b y t e s f o r M I D I m e s s a g e / , 'should throw error when MIDI data is truncated' ) ;
439439 t . end ( ) ;
440+ } ) ;
441+
442+ test ( 'osc: MIDI type with falsy status and data1 values' , ( t ) => {
443+ // Test MIDI type with object having undefined/falsy status and data1 (should default to 0)
444+ const message = {
445+ oscType : 'message' ,
446+ address : '/midi' ,
447+ args : [
448+ {
449+ type : 'm' ,
450+ value : {
451+ port : 5 ,
452+ data2 : 0x40
453+ // status and data1 are undefined, should default to 0
454+ }
455+ }
456+ ]
457+ } ;
458+
459+ const buffer = toBuffer ( message ) ;
460+ const decoded = fromBuffer ( buffer ) ;
461+
462+ t . equal ( decoded . args [ 0 ] . value [ 0 ] , 5 , 'port should match' ) ;
463+ t . equal ( decoded . args [ 0 ] . value [ 1 ] , 0 , 'status should default to 0' ) ;
464+ t . equal ( decoded . args [ 0 ] . value [ 2 ] , 0 , 'data1 should default to 0' ) ;
465+ t . equal ( decoded . args [ 0 ] . value [ 3 ] , 0x40 , 'data2 should match' ) ;
466+ t . end ( ) ;
467+ } ) ;
468+
469+ test ( 'osc: MIDI type with explicit zero status and data1 values' , ( t ) => {
470+ // Test MIDI type with object having explicit 0 values for status and data1
471+ const message = {
472+ oscType : 'message' ,
473+ address : '/midi' ,
474+ args : [
475+ {
476+ type : 'm' ,
477+ value : {
478+ port : 3 ,
479+ status : 0 ,
480+ data1 : 0 ,
481+ data2 : 0x60
482+ }
483+ }
484+ ]
485+ } ;
486+
487+ const buffer = toBuffer ( message ) ;
488+ const decoded = fromBuffer ( buffer ) ;
489+
490+ t . equal ( decoded . args [ 0 ] . value [ 0 ] , 3 , 'port should match' ) ;
491+ t . equal ( decoded . args [ 0 ] . value [ 1 ] , 0 , 'status should be 0' ) ;
492+ t . equal ( decoded . args [ 0 ] . value [ 2 ] , 0 , 'data1 should be 0' ) ;
493+ t . equal ( decoded . args [ 0 ] . value [ 3 ] , 0x60 , 'data2 should match' ) ;
494+ t . end ( ) ;
440495} ) ;
0 commit comments