| 1 | use fast_float2rust-analyzer cargo fast-float2 0.2.3 crate/::{parserust-analyzer cargo fast-float2 0.2.3 parse/, parse_partialrust-analyzer cargo fast-float2 0.2.3 parse_partial()., FastFloatrust-analyzer cargo fast-float2 0.2.3 FastFloat#}; |
| 2 | |
| 3 | macro_rules! check_okrust-analyzer cargo fast-float2 0.2.3 check_ok! { |
| 4 | ($s:expr, $x:expr) => { |
| 5 | let s = $s; |
| 6 | check_ok!(s, $x, f32); |
| 7 | check_ok!(s.as_bytes(), $x, f32); |
| 8 | check_ok!(s, $x, f64); |
| 9 | check_ok!(s.as_bytes(), $x, f64); |
| 10 | }; |
| 11 | ($s:expr, $x:expr, $ty:ty) => { |
| 12 | assert_eq!(<$ty>::parse_float($s).unwrap(), $x); |
| 13 | assert_eq!(<$ty>::parse_float_partial($s).unwrap(), ($x, $s.len())); |
| 14 | assert_eq!(parse::<$ty, _>($s).unwrap(), $x); |
| 15 | assert_eq!(parse_partial::<$ty, _>($s).unwrap(), ($x, $s.len())); |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | macro_rules! check_ok_partialrust-analyzer cargo fast-float2 0.2.3 check_ok_partial! { |
| 20 | ($s:expr, $x:expr, $n:expr) => { |
| 21 | let s = $s; |
| 22 | check_ok_partial!(s, $x, $n, f32); |
| 23 | check_ok_partial!(s.as_bytes(), $x, $n, f32); |
| 24 | check_ok_partial!(s, $x, $n, f64); |
| 25 | check_ok_partial!(s.as_bytes(), $x, $n, f64); |
| 26 | }; |
| 27 | ($s:expr, $x:expr, $n:expr, $ty:ty) => { |
| 28 | assert!(<$ty>::parse_float($s).is_err()); |
| 29 | assert_eq!(<$ty>::parse_float_partial($s).unwrap(), ($x, $n)); |
| 30 | assert!(parse::<$ty, _>($s).is_err()); |
| 31 | assert_eq!(parse_partial::<$ty, _>($s).unwrap(), ($x, $n)); |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | macro_rules! check_errrust-analyzer cargo fast-float2 0.2.3 check_err! { |
| 36 | ($s:expr) => { |
| 37 | let s = $s; |
| 38 | check_err!(s, f32); |
| 39 | check_err!(s.as_bytes(), f32); |
| 40 | check_err!(s, f64); |
| 41 | check_err!(s.as_bytes(), f64); |
| 42 | }; |
| 43 | ($s:expr, $ty:ty) => { |
| 44 | assert!(<$ty>::parse_float($s).is_err()); |
| 45 | assert!(<$ty>::parse_float_partial($s).is_err()); |
| 46 | assert!(parse::<$ty, _>($s).is_err()); |
| 47 | assert!(parse_partial::<$ty, _>($s).is_err()); |
| 48 | }; |
| 49 | } |
| 50 | |
| 51 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 52 | fn test_apirust-analyzer cargo fast-float2 0.2.3 test_api().() { |
| 53 | check_okrust-analyzer cargo fast-float2 0.2.3 check_ok!!("1.23", 1.23); |
| 54 | check_okrust-analyzer cargo fast-float2 0.2.3 check_ok!!("0.", 0.); |
| 55 | check_okrust-analyzer cargo fast-float2 0.2.3 check_ok!!("-0", 0.); |
| 56 | check_okrust-analyzer cargo fast-float2 0.2.3 check_ok!!("+00", 0.); |
| 57 | check_okrust-analyzer cargo fast-float2 0.2.3 check_ok!!("-0001e-02", -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.01); |
| 58 | check_okrust-analyzer cargo fast-float2 0.2.3 check_ok!!("345", 345.); |
| 59 | |
| 60 | check_ok_partialrust-analyzer cargo fast-float2 0.2.3 check_ok_partial!!("1a", 1., 1); |
| 61 | check_ok_partialrust-analyzer cargo fast-float2 0.2.3 check_ok_partial!!("-2e-1x", -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.2, 5); |
| 62 | check_ok_partialrust-analyzer cargo fast-float2 0.2.3 check_ok_partial!!("2e2.", 200., 3); |
| 63 | check_ok_partialrust-analyzer cargo fast-float2 0.2.3 check_ok_partial!!("2ea", 2., 1); |
| 64 | |
| 65 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!(""); |
| 66 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!(" "); |
| 67 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!("."); |
| 68 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!(".e1"); |
| 69 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!("+"); |
| 70 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!("-"); |
| 71 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!("x"); |
| 72 | check_errrust-analyzer cargo fast-float2 0.2.3 check_err!!("a123"); |
| 73 | } |