@@ -59,12 +59,13 @@ impl IntoByte<u8> for u8 {
5959 }
6060}
6161
62- fn test_case < B , M > ( data : & InputData , mut message : M , index : usize )
62+ fn test_case < B , M , R > ( data : & InputData , mut message : M , range : R )
6363where
6464 B : midi2:: buffer:: Buffer + midi2:: buffer:: BufferTryResize + midi2:: buffer:: BufferMut ,
6565 M : midi2:: Sysex < B > ,
6666 <M as Sysex < B > >:: Byte : Eq + core:: fmt:: Debug ,
6767 u8 : IntoByte < <M as Sysex < B > >:: Byte > ,
68+ R : core:: ops:: RangeBounds < usize > + Clone ,
6869{
6970 let Ok ( ( ) ) = message. try_set_payload ( data. initial_data . iter ( ) . map ( u8:: byte) ) else {
7071 return ;
@@ -78,14 +79,16 @@ where
7879 ) ;
7980 }
8081
81- let Ok ( ( ) ) = message. try_insert_payload ( data. data_to_insert . iter ( ) . map ( u8:: byte) , index) else {
82+ let Ok ( ( ) ) =
83+ message. try_splice_payload ( data. data_to_insert . iter ( ) . map ( u8:: byte) , range. clone ( ) )
84+ else {
8285 return ;
8386 } ;
8487
8588 let actual = message. payload ( ) . collect :: < Vec < _ > > ( ) ;
8689 let expected = {
8790 let mut ret = data. initial_data . clone ( ) ;
88- ret. splice ( index..index , data. data_to_insert . clone ( ) ) ;
91+ ret. splice ( range , data. data_to_insert . clone ( ) ) ;
8992 ret. iter ( ) . map ( u8:: byte) . collect :: < Vec < _ > > ( )
9093 } ;
9194 assert_eq ! ( actual, expected) ;
@@ -94,33 +97,41 @@ where
9497fuzz_target ! ( |data: InputData | {
9598 let mut rng = rand:: rngs:: StdRng :: seed_from_u64( data. seed) ;
9699 let fized_size_buffer_size = rng. random_range( 4 ..MAX_BUFFER_SIZE ) ;
97- let index = if data. initial_data. is_empty( ) {
98- 0
99- } else {
100- rng. random_range( 0 ..data. initial_data. len( ) )
100+ let range = {
101+ if data. initial_data. is_empty( ) {
102+ 0 ..0
103+ } else {
104+ let lower = rng. random_range( 0 ..data. initial_data. len( ) ) ;
105+ if lower == data. initial_data. len( ) {
106+ lower..lower
107+ } else {
108+ let upper = rng. random_range( lower..data. initial_data. len( ) ) ;
109+ lower..upper
110+ }
111+ }
101112 } ;
102113 test_case(
103114 & data,
104115 midi2:: sysex8:: Sysex8 :: <FixedSizeBuffer <u32 >>:: try_new_with_buffer(
105116 FixedSizeBuffer :: <u32 >:: new( fized_size_buffer_size) ,
106117 )
107118 . unwrap( ) ,
108- index ,
119+ range . clone ( ) ,
109120 ) ;
110121 test_case(
111122 & data,
112123 midi2:: sysex7:: Sysex7 :: <FixedSizeBuffer <u32 >>:: try_new_with_buffer(
113124 FixedSizeBuffer :: <u32 >:: new( fized_size_buffer_size) ,
114125 )
115126 . unwrap( ) ,
116- index ,
127+ range . clone ( ) ,
117128 ) ;
118129 test_case(
119130 & data,
120131 midi2:: sysex7:: Sysex7 :: <FixedSizeBuffer <u8 >>:: try_new_with_buffer(
121132 FixedSizeBuffer :: <u8 >:: new( fized_size_buffer_size) ,
122133 )
123134 . unwrap( ) ,
124- index ,
135+ range . clone ( ) ,
125136 ) ;
126137} ) ;
0 commit comments