@@ -3425,3 +3425,63 @@ impl From<char> for String {
34253425 c. to_string ( )
34263426 }
34273427}
3428+
3429+ #[ cfg( test) ]
3430+ mod tests {
3431+ use std:: str:: FromStr ;
3432+
3433+ fn assert_nb < Int : ToString + FromStr > ( value : Int ) {
3434+ let s = value. to_string ( ) ;
3435+ let s2 = format ! ( "{}" , value) ;
3436+
3437+ assert_eq ! ( s, s2) ;
3438+ let ret = Int :: from_str ( & s) . unwrap ( ) ;
3439+ assert_eq ! ( ret, int) ;
3440+ }
3441+
3442+ macro_rules! uint_to_s {
3443+ ( $( $fn_name: ident, $int: ident, ) +) => {
3444+ $(
3445+ #[ test]
3446+ fn $fn_name( ) {
3447+ assert_nb:: <$int>( $int:: MIN ) ;
3448+ assert_nb:: <$int>( $int:: MAX ) ;
3449+ assert_nb:: <$int>( 1 ) ;
3450+ assert_nb:: <$int>( $int:: MIN / 2 ) ;
3451+ assert_nb:: <$int>( $int:: MAX / 2 ) ;
3452+ }
3453+ ) +
3454+ }
3455+ }
3456+ macro_rules! int_to_s {
3457+ ( $( $fn_name: ident, $int: ident, ) +) => {
3458+ $(
3459+ #[ test]
3460+ fn $fn_name( ) {
3461+ assert_nb:: <$int>( $int:: MIN ) ;
3462+ assert_nb:: <$int>( $int:: MAX ) ;
3463+ assert_nb:: <$int>( 1 ) ;
3464+ assert_nb:: <$int>( 0 ) ;
3465+ assert_nb:: <$int>( -1 ) ;
3466+ assert_nb:: <$int>( $int:: MIN / 2 ) ;
3467+ assert_nb:: <$int>( $int:: MAX / 2 ) ;
3468+ }
3469+ ) +
3470+ }
3471+ }
3472+
3473+ int_to_s ! (
3474+ test_i8_to_string, i8 ,
3475+ test_i16_to_string, i16 ,
3476+ test_i32_to_string, i32 ,
3477+ test_i64_to_string, i64 ,
3478+ test_i128_to_string, i128 ,
3479+ ) ;
3480+ uint_to_s ! (
3481+ test_u8_to_string, u8 ,
3482+ test_u16_to_string, u16 ,
3483+ test_u32_to_string, u32 ,
3484+ test_u64_to_string, u64 ,
3485+ test_u128_to_string, u128 ,
3486+ ) ;
3487+ }
0 commit comments