File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
lexical-parse-float/tests
lexical-parse-integer/tests Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1399,6 +1399,30 @@ fn base_prefix_no_digit_separator_test() {
13991399 assert_eq ! ( value, Ok ( 12345.6 ) ) ;
14001400}
14011401
1402+ #[ test]
1403+ #[ cfg( all( feature = "format" , feature = "power-of-two" ) ) ]
1404+ fn base_prefix_leading_zeros_test ( ) {
1405+ use core:: num;
1406+
1407+ const OPTIONS : Options = Options :: new ( ) ;
1408+ const OPT_PREFIX : u128 = NumberFormatBuilder :: new ( )
1409+ . base_prefix ( num:: NonZeroU8 :: new ( b'd' ) )
1410+ . no_float_leading_zeros ( true )
1411+ . build_strict ( ) ;
1412+
1413+ let value = f64:: from_lexical_with_options :: < OPT_PREFIX > ( b"1.2" , & OPTIONS ) ;
1414+ assert_eq ! ( value, Ok ( 1.2 ) ) ;
1415+
1416+ let value = f64:: from_lexical_with_options :: < OPT_PREFIX > ( b"01.2" , & OPTIONS ) ;
1417+ assert_eq ! ( value, Err ( Error :: InvalidLeadingZeros ( 0 ) ) ) ;
1418+
1419+ let value = f64:: from_lexical_with_options :: < OPT_PREFIX > ( b"0d1.2" , & OPTIONS ) ;
1420+ assert_eq ! ( value, Ok ( 1.2 ) ) ;
1421+
1422+ let value = f64:: from_lexical_with_options :: < OPT_PREFIX > ( b"0d01.2" , & OPTIONS ) ;
1423+ assert_eq ! ( value, Ok ( 1.2 ) ) ;
1424+ }
1425+
14021426#[ test]
14031427#[ cfg( all( feature = "format" , feature = "power-of-two" ) ) ]
14041428fn base_prefix_l_digit_separator_test ( ) {
Original file line number Diff line number Diff line change @@ -514,6 +514,30 @@ fn base_prefix_no_digit_separator_test() {
514514 assert_eq ! ( value, Ok ( 12345 ) ) ;
515515}
516516
517+ #[ test]
518+ #[ cfg( all( feature = "format" , feature = "power-of-two" ) ) ]
519+ fn base_prefix_leading_zeros_test ( ) {
520+ use core:: num;
521+
522+ const OPTIONS : Options = Options :: new ( ) ;
523+ const OPT_PREFIX : u128 = NumberFormatBuilder :: new ( )
524+ . base_prefix ( num:: NonZeroU8 :: new ( b'd' ) )
525+ . no_integer_leading_zeros ( true )
526+ . build_strict ( ) ;
527+
528+ let value = i64:: from_lexical_with_options :: < OPT_PREFIX > ( b"1" , & OPTIONS ) ;
529+ assert_eq ! ( value, Ok ( 1 ) ) ;
530+
531+ let value = i64:: from_lexical_with_options :: < OPT_PREFIX > ( b"01" , & OPTIONS ) ;
532+ assert_eq ! ( value, Err ( Error :: InvalidLeadingZeros ( 0 ) ) ) ;
533+
534+ let value = i64:: from_lexical_with_options :: < OPT_PREFIX > ( b"0d1" , & OPTIONS ) ;
535+ assert_eq ! ( value, Ok ( 1 ) ) ;
536+
537+ let value = i64:: from_lexical_with_options :: < OPT_PREFIX > ( b"0d01" , & OPTIONS ) ;
538+ assert_eq ! ( value, Ok ( 1 ) ) ;
539+ }
540+
517541#[ test]
518542#[ cfg( all( feature = "format" , feature = "power-of-two" ) ) ]
519543fn base_prefix_l_digit_separator_test ( ) {
You can’t perform that action at this time.
0 commit comments