Skip to content

Commit

Permalink
Combine number PartialEq tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 7, 2024
1 parent b4fc245 commit fdf99c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::env;
fn main() {
println!("cargo:rerun-if-changed=build.rs");

println!("cargo:rustc-check-cfg=cfg(integer128)");
println!("cargo:rustc-check-cfg=cfg(limb_width_32)");
println!("cargo:rustc-check-cfg=cfg(limb_width_64)");

Expand Down
32 changes: 14 additions & 18 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,20 +2100,20 @@ fn issue_220() {
assert_eq!(from_str::<E>(r#"{"V": 0}"#).unwrap(), E::V(0));
}

macro_rules! number_partialeq_ok {
($($n:expr)*) => {
$(
let value = to_value($n).unwrap();
let s = $n.to_string();
assert_eq!(value, $n);
assert_eq!($n, value);
assert_ne!(value, s);
)*
}
}

#[test]
fn test_partialeq_number() {
macro_rules! number_partialeq_ok {
($($n:expr)*) => {
$(
let value = to_value($n).unwrap();
let s = $n.to_string();
assert_eq!(value, $n);
assert_eq!($n, value);
assert_ne!(value, s);
)*
};
}

number_partialeq_ok!(0 1 100
i8::MIN i8::MAX i16::MIN i16::MAX i32::MIN i32::MAX i64::MIN i64::MAX
u8::MIN u8::MAX u16::MIN u16::MAX u32::MIN u32::MAX u64::MIN u64::MAX
Expand All @@ -2122,13 +2122,9 @@ fn test_partialeq_number() {
f32::consts::E f32::consts::PI f32::consts::LN_2 f32::consts::LOG2_E
f64::consts::E f64::consts::PI f64::consts::LN_2 f64::consts::LOG2_E
);
}

#[test]
#[cfg(integer128)]
#[cfg(feature = "arbitrary_precision")]
fn test_partialeq_integer128() {
number_partialeq_ok!(i128::MIN i128::MAX u128::MIN u128::MAX)
#[cfg(feature = "arbitrary_precision")]
number_partialeq_ok!(i128::MIN i128::MAX u128::MIN u128::MAX);
}

#[test]
Expand Down

0 comments on commit fdf99c7

Please sign in to comment.