@@ -166,6 +166,14 @@ pub struct DataValueIterator<'a> {
166
166
167
167
impl < ' a > DataValueIterator < ' a > {
168
168
pub fn new ( data : & ' a [ u8 ] , data_type : DataType ) -> Result < Self , Error > {
169
+ // Check if the data type is supported for iteration
170
+ match data_type {
171
+ DataType :: String | DataType :: URL => {
172
+ return Err ( Error :: NotImplemented ) ;
173
+ }
174
+ _ => { }
175
+ }
176
+
169
177
let ( input, count) =
170
178
be_u32 ( data) . map_err ( |_: nom:: Err < nom:: error:: Error < _ > > | Error :: ParseError ) ?;
171
179
let ( input, count_2) =
@@ -219,8 +227,10 @@ impl<'a> Iterator for DataValueIterator<'a> {
219
227
DataType :: Float64 => be_f64 ( self . input )
220
228
. map_err ( |_: nom:: Err < nom:: error:: Error < _ > > | Error :: ParseError )
221
229
. map_or ( None , |( input, f) | Some ( ( input, DataValue :: Float64 ( f) ) ) ) ,
222
- DataType :: String => return None , // TODO: Implement string parsing
223
- DataType :: URL => return None , // TODO: Implement URL parsing
230
+ DataType :: String | DataType :: URL => {
231
+ // These types are not supported for iteration and should be caught in new()
232
+ unreachable ! ( "String and URL types should be rejected in DataValueIterator::new()" )
233
+ }
224
234
} ?;
225
235
226
236
self . input = input;
@@ -278,14 +288,14 @@ impl DataArray {
278
288
Ok ( ( input, Self :: Float64 ( values) ) )
279
289
}
280
290
DataType :: String => {
281
- // TODO: Implement string array parsing
291
+ // String array parsing is not implemented
282
292
Err ( nom:: Err :: Error ( nom:: error:: Error :: new (
283
293
input,
284
294
nom:: error:: ErrorKind :: Tag ,
285
295
) ) )
286
296
}
287
297
DataType :: URL => {
288
- // TODO: Implement URL array parsing
298
+ // URL array parsing is not implemented
289
299
Err ( nom:: Err :: Error ( nom:: error:: Error :: new (
290
300
input,
291
301
nom:: error:: ErrorKind :: Tag ,
@@ -365,20 +375,30 @@ impl TryInto<Vec<f64>> for DataArray {
365
375
366
376
#[ cfg( test) ]
367
377
mod tests {
368
- use super :: DataType ;
378
+ use super :: * ;
369
379
370
380
#[ test]
371
381
fn parse_data_type ( ) {
372
- let input = "Int32" ;
373
- let ( _, dtype) = DataType :: parse ( input) . unwrap ( ) ;
374
- assert_eq ! ( dtype, DataType :: Int32 ) ;
382
+ let ( _, data_type) = DataType :: parse ( "Int32" ) . unwrap ( ) ;
383
+ assert_eq ! ( data_type, DataType :: Int32 ) ;
375
384
376
- let input = "Float32" ;
377
- let ( _ , dtype ) = DataType :: parse ( input ) . unwrap ( ) ;
378
- assert_eq ! ( dtype , DataType :: Float32 ) ;
385
+ let ( _ , data_type ) = DataType :: parse ( "Float32" ) . unwrap ( ) ;
386
+ assert_eq ! ( data_type , DataType :: Float32 ) ;
387
+ }
379
388
380
- let input = "String" ;
381
- let ( _, dtype) = DataType :: parse ( input) . unwrap ( ) ;
382
- assert_eq ! ( dtype, DataType :: String ) ;
389
+ #[ test]
390
+ fn test_not_implemented_data_value_iterator ( ) {
391
+ // Test that String and URL types return NotImplemented error
392
+ let dummy_data = [ 0u8 ; 16 ] ; // Some dummy data
393
+
394
+ let result = DataValueIterator :: new ( & dummy_data, DataType :: String ) ;
395
+ assert ! ( matches!( result, Err ( Error :: NotImplemented ) ) ) ;
396
+
397
+ let result = DataValueIterator :: new ( & dummy_data, DataType :: URL ) ;
398
+ assert ! ( matches!( result, Err ( Error :: NotImplemented ) ) ) ;
399
+
400
+ // Test that supported types work
401
+ let result = DataValueIterator :: new ( & dummy_data, DataType :: Int32 ) ;
402
+ assert ! ( result. is_ok( ) ) ;
383
403
}
384
404
}
0 commit comments