Skip to content

Commit 58146e4

Browse files
authored
test: add property tests (#65)
1 parent 81d19ce commit 58146e4

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

Cargo.lock

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ arbitrary = { version = "1", features = ["derive"], optional = true }
2424
serde = { version = "1", optional = true }
2525

2626
[dev-dependencies]
27+
quickcheck = "1"
2728
serde = { version = "1", features = ["derive"] }
2829
serde_json = "1"
2930
toml = "0.8"

src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,37 @@ where
379379
}
380380
}
381381

382+
#[cfg(test)]
383+
mod property_tests {
384+
use super::*;
385+
386+
impl quickcheck::Arbitrary for ByteSize {
387+
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
388+
Self(u64::arbitrary(g))
389+
}
390+
}
391+
392+
quickcheck::quickcheck! {
393+
fn parsing_never_panics(size: String) -> bool {
394+
let _ = size.parse::<ByteSize>();
395+
true
396+
}
397+
398+
fn to_string_never_blank(size: ByteSize) -> bool {
399+
!size.to_string().is_empty()
400+
}
401+
402+
fn to_string_never_large(size: ByteSize) -> bool {
403+
size.to_string().len() < 10
404+
}
405+
406+
// // currently fails on input like "14.0 EiB"
407+
// fn string_round_trip(size: ByteSize) -> bool {
408+
// size.to_string().parse::<ByteSize>().unwrap() == size
409+
// }
410+
}
411+
}
412+
382413
#[cfg(test)]
383414
mod tests {
384415
use super::*;

0 commit comments

Comments
 (0)