Skip to content

Commit 0e0440a

Browse files
committed
test: add property tests
1 parent 6b0eb20 commit 0e0440a

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-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
@@ -20,6 +20,7 @@ arbitrary = { version = "1", features = ["derive"], optional = true }
2020
serde = { version = "1", optional = true }
2121

2222
[dev-dependencies]
23+
quickcheck = "1"
2324
serde = { version = "1", features = ["derive"] }
2425
serde_json = "1"
2526
toml = "0.8"

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,32 @@ where
335335
}
336336
}
337337

338+
#[cfg(test)]
339+
mod property_tests {
340+
use super::*;
341+
342+
impl quickcheck::Arbitrary for ByteSize {
343+
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
344+
Self(u64::arbitrary(g))
345+
}
346+
}
347+
348+
quickcheck::quickcheck! {
349+
fn to_string_never_blank(size: ByteSize) -> bool {
350+
!size.to_string().is_empty()
351+
}
352+
353+
fn to_string_never_large(size: ByteSize) -> bool {
354+
size.to_string().len() < 10
355+
}
356+
357+
// // currently fails on input like "14.0 EiB"
358+
// fn string_round_trip(size: ByteSize) -> bool {
359+
// size.to_string().parse::<ByteSize>().unwrap() == size
360+
// }
361+
}
362+
}
363+
338364
#[cfg(test)]
339365
mod tests {
340366
use super::*;

0 commit comments

Comments
 (0)