| 1 | use lexical_util::format::{NumberFormat, NumberFormatBuilder}; |
| 2 | |
| 3 | #[test] |
| 4 | fn decimal_test() { |
| 5 | const FORMAT: u128 = NumberFormatBuilder::decimal(); |
| 6 | let format = NumberFormat::<FORMAT> {}; |
| 7 | assert!(format.is_valid()); |
| 8 | assert_eq!(format.radix(), 10); |
| 9 | assert_eq!(format.mantissa_radix(), 10); |
| 10 | assert_eq!(format.exponent_base(), 10); |
| 11 | assert_eq!(format.exponent_radix(), 10); |
| 12 | } |
| 13 | |
| 14 | #[test] |
| 15 | #[cfg(feature = "power-of-two")] |
| 16 | fn binary_test() { |
| 17 | const FORMAT: u128 = NumberFormatBuilder::binary(); |
| 18 | let format = NumberFormat::<FORMAT> {}; |
| 19 | assert!(format.is_valid()); |
| 20 | assert_eq!(format.radix(), 2); |
| 21 | assert_eq!(format.mantissa_radix(), 2); |
| 22 | assert_eq!(format.exponent_base(), 2); |
| 23 | assert_eq!(format.exponent_radix(), 2); |
| 24 | } |
| 25 | |
| 26 | #[test] |
| 27 | #[cfg(feature = "power-of-two")] |
| 28 | fn octal_test() { |
| 29 | const FORMAT: u128 = NumberFormatBuilder::octal(); |
| 30 | let format = NumberFormat::<FORMAT> {}; |
| 31 | assert!(format.is_valid()); |
| 32 | assert_eq!(format.radix(), 8); |
| 33 | assert_eq!(format.mantissa_radix(), 8); |
| 34 | assert_eq!(format.exponent_base(), 8); |
| 35 | assert_eq!(format.exponent_radix(), 8); |
| 36 | } |
| 37 | |
| 38 | #[test] |
| 39 | #[cfg(feature = "power-of-two")] |
| 40 | fn hexadecimal_test() { |
| 41 | const FORMAT: u128 = NumberFormatBuilder::hexadecimal(); |
| 42 | let format = NumberFormat::<FORMAT> {}; |
| 43 | assert!(format.is_valid()); |
| 44 | assert_eq!(format.radix(), 16); |
| 45 | assert_eq!(format.mantissa_radix(), 16); |
| 46 | assert_eq!(format.exponent_base(), 16); |
| 47 | assert_eq!(format.exponent_radix(), 16); |
| 48 | } |
| 49 | |
| 50 | #[test] |
| 51 | #[cfg(feature = "power-of-two")] |
| 52 | fn from_radix_test() { |
| 53 | const FORMAT: u128 = NumberFormatBuilder::from_radix(32); |
| 54 | let format = NumberFormat::<FORMAT> {}; |
| 55 | assert!(format.is_valid()); |
| 56 | assert_eq!(format.radix(), 32); |
| 57 | assert_eq!(format.mantissa_radix(), 32); |
| 58 | assert_eq!(format.exponent_base(), 32); |
| 59 | assert_eq!(format.exponent_radix(), 32); |
| 60 | } |