Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/serde_json/tests/lexical/num.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / serde_json / tests / lexical / num.rs` 75 lines ยท 1602 bytes Raw Blame History 1 // Adapted from https://github.com/Alexhuszagh/rust-lexical. 2 3 use crate::lexical::num::{AsPrimitive, Float, Integer, Number}; 4 5 fn check_as_primitive(t: T) { 6 let _: u32 = t.as_u32(); 7 let _: u64 = t.as_u64(); 8 let _: u128 = t.as_u128(); 9 let _: usize = t.as_usize(); 10 let _: f32 = t.as_f32(); 11 let _: f64 = t.as_f64(); 12 } 13 14 #[test] 15 fn as_primitive_test() { 16 check_as_primitive(1u32); 17 check_as_primitive(1u64); 18 check_as_primitive(1u128); 19 check_as_primitive(1usize); 20 check_as_primitive(1f32); 21 check_as_primitive(1f64); 22 } 23 24 fn check_number(x: T, y: T) { 25 // Copy, partialeq, partialord 26 let _ = x; 27 assert!(x < y); 28 assert!(x != y); 29 30 // Operations 31 let _ = y + x; 32 33 // Conversions already tested. 34 } 35 36 #[test] 37 fn number_test() { 38 check_number(1u32, 5); 39 check_number(1u64, 5); 40 check_number(1u128, 5); 41 check_number(1usize, 5); 42 check_number(1f32, 5.0); 43 check_number(1f64, 5.0); 44 } 45 46 fn check_integer(x: T) { 47 // Bitwise operations 48 let _ = x & T::ZERO; 49 } 50 51 #[test] 52 fn integer_test() { 53 check_integer(65u32); 54 check_integer(65u64); 55 check_integer(65u128); 56 check_integer(65usize); 57 } 58 59 fn check_float(x: T) { 60 // Check functions 61 let _ = x.pow10(5); 62 let _ = x.to_bits(); 63 assert!(T::from_bits(x.to_bits()) == x); 64 65 // Check properties 66 let _ = x.to_bits() & T::EXPONENT_MASK; 67 let _ = x.to_bits() & T::HIDDEN_BIT_MASK; 68 let _ = x.to_bits() & T::MANTISSA_MASK; 69 } 70 71 #[test] 72 fn float_test() { 73 check_float(123f32); 74 check_float(123f64); 75 }