@@ -612,3 +612,40 @@ impl Radix {
612612 }
613613 }
614614}
615+
616+ #[ cfg( test) ]
617+ mod tests {
618+ use crate :: ast:: { make, FloatNumber , IntNumber } ;
619+
620+ fn check_float_suffix < ' a > ( lit : & str , expected : impl Into < Option < & ' a str > > ) {
621+ assert_eq ! ( FloatNumber { syntax: make:: tokens:: literal( lit) } . suffix( ) , expected. into( ) ) ;
622+ }
623+
624+ fn check_int_suffix < ' a > ( lit : & str , expected : impl Into < Option < & ' a str > > ) {
625+ assert_eq ! ( IntNumber { syntax: make:: tokens:: literal( lit) } . suffix( ) , expected. into( ) ) ;
626+ }
627+
628+ #[ test]
629+ fn test_float_number_suffix ( ) {
630+ check_float_suffix ( "123.0" , None ) ;
631+ check_float_suffix ( "123f32" , "f32" ) ;
632+ check_float_suffix ( "123.0e" , None ) ;
633+ check_float_suffix ( "123.0e4" , None ) ;
634+ check_float_suffix ( "123.0ef32" , "f32" ) ;
635+ check_float_suffix ( "123.0E4f32" , "f32" ) ;
636+ check_float_suffix ( "1_2_3.0_f32" , "f32" ) ;
637+ }
638+
639+ #[ test]
640+ fn test_int_number_suffix ( ) {
641+ check_int_suffix ( "123" , None ) ;
642+ check_int_suffix ( "123i32" , "i32" ) ;
643+ check_int_suffix ( "1_0_1_l_o_l" , "l_o_l" ) ;
644+ check_int_suffix ( "0b11" , None ) ;
645+ check_int_suffix ( "0o11" , None ) ;
646+ check_int_suffix ( "0xff" , None ) ;
647+ check_int_suffix ( "0b11u32" , "u32" ) ;
648+ check_int_suffix ( "0o11u32" , "u32" ) ;
649+ check_int_suffix ( "0xffu32" , "u32" ) ;
650+ }
651+ }
0 commit comments