Skip to content

Commit

Permalink
Fix is_nan, is_finite visibility (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunjhongwu authored May 13, 2024
1 parent 4e97f5d commit b2f3bc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion strong-type-derive/src/detail/nan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ pub(crate) fn implement_nan(name: &syn::Ident, value_type: &syn::Ident) -> Token
impl #name {
pub const NAN: Self = Self(#value_type::NAN);

fn is_nan(&self) -> bool {
pub fn is_nan(&self) -> bool {
self.0.is_nan()
}

pub fn is_finite(&self) -> bool {
self.0.is_finite()
}
}
}
}
16 changes: 14 additions & 2 deletions strong-type-tests/tests/strong_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,29 @@ mod tests {
}

#[test]
fn test_float_nan() {
fn test_float_nan_and_infinity() {
#[derive(StrongType)]
struct Meter(f64);

let y = Meter::NAN;
assert!(y.is_nan());
assert!(y.value().is_nan());
assert!(!y.is_finite());

let z = Meter(0.0);
let z = Meter::new(0.0);
assert!(!z.is_nan());
assert!(!z.value().is_nan());
assert!(z.is_finite());

let w = Meter::INFINITY;
assert!(!w.is_nan());
assert!(!w.value().is_nan());
assert!(!w.is_finite());

let u = Meter::NEG_INFINITY;
assert!(!u.is_nan());
assert!(!u.value().is_nan());
assert!(!u.is_finite());
}

#[test]
Expand Down

0 comments on commit b2f3bc9

Please sign in to comment.