Skip to content

Commit d42cd18

Browse files
committed
feat: migrate license size tests to proptest
1 parent 1423f09 commit d42cd18

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

crates/league-modpkg/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ rmp-serde = "1.3.0"
1212
twox-hash = { version = "2.0.1", features = ["xxhash64"] }
1313
binrw = "0.14.1"
1414
itertools = "0.14.0"
15+
proptest = "1.6.0"
16+
17+
[dev-dependencies]
18+
proptest-derive = "0.5.1"
Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use binrw::{binrw, NullString};
21
use binrw::binrw;
32

43
use crate::utils::{nullstr_read, nullstr_write};
@@ -40,59 +39,27 @@ impl ModpkgLicense {
4039
}
4140
}
4241

43-
// TODO: use proptest here
4442
#[cfg(test)]
4543
mod tests {
4644
use std::io::Cursor;
4745

4846
use binrw::BinWrite;
4947

5048
use super::*;
51-
52-
#[test]
53-
fn test_none_size() {
54-
let license = ModpkgLicense::default();
55-
let mut buf = Cursor::new(Vec::with_capacity(license.size() + 512));
56-
license.write(&mut buf).unwrap();
57-
println!("{:x?}", buf.clone().into_inner());
58-
59-
assert_eq!(
60-
license.size(),
61-
buf.into_inner().len(),
62-
"comparing reported size with real size"
63-
);
64-
}
65-
49+
use proptest::prelude::*;
50+
proptest! {
6651
#[test]
67-
fn test_spdx_size() {
68-
let license = ModpkgLicense::Spdx {
69-
spdx_id: "test".to_string().into(),
70-
};
52+
fn test_license_size(license: ModpkgLicense) {
53+
let mut buf = Cursor::new(Vec::with_capacity(license.size() + 64));
54+
license.write(&mut buf).unwrap();
7155

72-
let mut buf = Cursor::new(Vec::with_capacity(license.size() + 512));
73-
license.write(&mut buf).unwrap();
56+
println!("{:x?}", buf.clone().into_inner());
7457

75-
assert_eq!(
76-
license.size(),
77-
buf.into_inner().len(),
78-
"comparing reported size with real size"
79-
);
80-
}
81-
#[test]
82-
fn test_custom_size() {
83-
let license = ModpkgLicense::Custom {
84-
name: "customName".into(),
85-
url: "http://fake.url/".into(),
86-
};
87-
let mut buf = Cursor::new(Vec::with_capacity(license.size() + 512));
88-
license.write(&mut buf).unwrap();
89-
90-
println!("{:x?}", buf.clone().into_inner());
91-
92-
assert_eq!(
93-
license.size(),
94-
buf.into_inner().len(),
95-
"comparing reported size with real size"
96-
);
58+
assert_eq!(
59+
license.size(),
60+
buf.into_inner().len(),
61+
"comparing reported size with real size"
62+
);
63+
}
9764
}
9865
}

0 commit comments

Comments
 (0)