Skip to content

Commit

Permalink
test: add property tests (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede authored Feb 12, 2025
1 parent 81d19ce commit 58146e4
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
113 changes: 113 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ arbitrary = { version = "1", features = ["derive"], optional = true }
serde = { version = "1", optional = true }

[dev-dependencies]
quickcheck = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.8"
31 changes: 31 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,37 @@ where
}
}

#[cfg(test)]
mod property_tests {
use super::*;

impl quickcheck::Arbitrary for ByteSize {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self(u64::arbitrary(g))
}
}

quickcheck::quickcheck! {
fn parsing_never_panics(size: String) -> bool {
let _ = size.parse::<ByteSize>();
true
}

fn to_string_never_blank(size: ByteSize) -> bool {
!size.to_string().is_empty()
}

fn to_string_never_large(size: ByteSize) -> bool {
size.to_string().len() < 10
}

// // currently fails on input like "14.0 EiB"
// fn string_round_trip(size: ByteSize) -> bool {
// size.to_string().parse::<ByteSize>().unwrap() == size
// }
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 58146e4

Please sign in to comment.