@@ -261,7 +261,7 @@ impl FromStr for Numeric {
261
261
integer. pop_front ( ) ;
262
262
}
263
263
264
- let mut weight = if integer. is_empty ( ) || integer == b"0" {
264
+ let mut weight = if integer. is_empty ( ) {
265
265
-1
266
266
} else {
267
267
integer. len ( ) . div_ceil ( 4 ) as i16 - 1
@@ -365,6 +365,15 @@ mod test {
365
365
#[ test]
366
366
fn test_string_deserialization_and_serialization ( ) {
367
367
let cases = & [
368
+ (
369
+ "0" ,
370
+ Numeric {
371
+ sign : NumericSign :: Positive ,
372
+ scale : 0 ,
373
+ weight : 0 ,
374
+ digits : vec ! [ ] ,
375
+ } ,
376
+ ) ,
368
377
(
369
378
"1" ,
370
379
Numeric {
@@ -810,4 +819,22 @@ mod test {
810
819
assert_eq ! ( num. to_string( ) , * str , "{e} back to string" ) ;
811
820
}
812
821
}
822
+
823
+ use proptest:: prelude:: * ;
824
+ proptest ! {
825
+ #[ test]
826
+ fn test_arbitrary_f64_from_string_and_back( value in any:: <f64 >( ) ) {
827
+ let prop_val = value. to_string( ) ;
828
+ let numeric = Numeric :: from_str( & prop_val) . expect( "parse numeric" ) ;
829
+ let str_val = numeric. to_string( ) ;
830
+ assert_eq!( prop_val, str_val, "proprty test value {value}" ) ;
831
+ }
832
+ #[ test]
833
+ fn test_arbitrary_i64_from_string_and_back( value in any:: <i64 >( ) ) {
834
+ let prop_val = value. to_string( ) ;
835
+ let numeric = Numeric :: from_str( & prop_val) . expect( "parse numeric" ) ;
836
+ let str_val = numeric. to_string( ) ;
837
+ assert_eq!( prop_val, str_val, "proprty test value {value}" ) ;
838
+ }
839
+ }
813
840
}
0 commit comments