@@ -366,3 +366,35 @@ test_impl_try_from_same_sign_err! { test_try_i32i16, i32, i16 }
366
366
test_impl_try_from_same_sign_err ! { test_try_i64i8, i64 , i8 }
367
367
test_impl_try_from_same_sign_err ! { test_try_i64i16, i64 , i16 }
368
368
test_impl_try_from_same_sign_err ! { test_try_i64i32, i64 , i32 }
369
+
370
+ macro_rules! test_impl_try_from_signed_to_unsigned_err {
371
+ ( $fn_name: ident, $source: ty, $target: ty) => {
372
+ #[ test]
373
+ fn $fn_name( ) {
374
+ let max = <$source>:: max_value( ) ;
375
+ let min = <$source>:: min_value( ) ;
376
+ let zero: $source = 0 ;
377
+ let t_max = <$target>:: max_value( ) ;
378
+ let t_min = <$target>:: min_value( ) ;
379
+ assert!( <$target as TryFrom <$source>>:: try_from( max) . is_err( ) ) ;
380
+ assert!( <$target as TryFrom <$source>>:: try_from( min) . is_err( ) ) ;
381
+ assert_eq!( <$target as TryFrom <$source>>:: try_from( zero) . unwrap( ) ,
382
+ zero as $target) ;
383
+ assert_eq!( <$target as TryFrom <$source>>:: try_from( t_max as $source)
384
+ . unwrap( ) ,
385
+ t_max as $target) ;
386
+ assert_eq!( <$target as TryFrom <$source>>:: try_from( t_min as $source)
387
+ . unwrap( ) ,
388
+ t_min as $target) ;
389
+ }
390
+ }
391
+ }
392
+
393
+ test_impl_try_from_signed_to_unsigned_err ! { test_try_i16u8, i16 , u8 }
394
+
395
+ test_impl_try_from_signed_to_unsigned_err ! { test_try_i32u8, i32 , u8 }
396
+ test_impl_try_from_signed_to_unsigned_err ! { test_try_i32u16, i32 , u16 }
397
+
398
+ test_impl_try_from_signed_to_unsigned_err ! { test_try_i64u8, i64 , u8 }
399
+ test_impl_try_from_signed_to_unsigned_err ! { test_try_i64u16, i64 , u16 }
400
+ test_impl_try_from_signed_to_unsigned_err ! { test_try_i64u32, i64 , u32 }
0 commit comments