treewide/test: Use `impl Arbitrary for Oid`

Many usages of `Oid::from_sha1` are actually in the context of
generating arbitrary `Oid`s. In these cases, `impl Arbitrary for Oid`
may be used directly.
This commit is contained in:
Lorenz Leutgeb 2026-04-23 23:48:20 +02:00 committed by Lorenz Leutgeb
parent 88a7252e33
commit 7b07e57b9c
4 changed files with 8 additions and 16 deletions

View File

@ -313,10 +313,7 @@ pub mod arbitrary {
#[cfg(feature = "qcheck")]
impl qcheck::Arbitrary for RepoId {
fn arbitrary(g: &mut qcheck::Gen) -> Self {
let bytes = <[u8; 20]>::arbitrary(g);
let oid = radicle_oid::Oid::from_sha1(bytes);
RepoId::from(oid)
RepoId::from(radicle_oid::Oid::arbitrary(g))
}
}

View File

@ -624,8 +624,8 @@ mod tests {
}
#[quickcheck]
fn prop_oid(input: [u8; git::Oid::SHA1_LEN]) {
roundtrip(git::Oid::from_sha1(input));
fn prop_oid(input: git::Oid) {
roundtrip(input);
}
#[test]

View File

@ -17,7 +17,7 @@ where
if bool::arbitrary(g) {
level = Some(FeatureLevel::Parent);
let parent = Oid::from_sha1(Arbitrary::arbitrary(g));
let parent = Oid::arbitrary(g);
refs.insert(SIGREFS_PARENT.to_ref_string(), parent);
}
@ -28,13 +28,12 @@ where
id: *signer.node_id(),
level: level.unwrap_or_else(|| FeatureLevel::arbitrary(g)),
parent: Arbitrary::arbitrary(g),
at: Oid::from_sha1(Arbitrary::arbitrary(g)),
at: Oid::arbitrary(g),
}
}
impl Arbitrary for Refs {
fn arbitrary(g: &mut qcheck::Gen) -> Self {
let mut bytes: [u8; 20] = [0; 20];
let names = &[
"heads/master",
"heads/feature/1",
@ -49,10 +48,7 @@ impl Arbitrary for Refs {
let mut refs = Self::new();
for _ in 0..g.size().min(names.len()) {
if let Some(name) = g.choose(names) {
for byte in &mut bytes {
*byte = u8::arbitrary(g);
}
let oid = storage::Oid::from_sha1(bytes);
let oid = storage::Oid::arbitrary(g);
let name = git::fmt::RefString::try_from(*name).unwrap();
refs.insert(name, oid);
@ -66,7 +62,7 @@ impl Arbitrary for RefsAt {
fn arbitrary(g: &mut qcheck::Gen) -> Self {
Self {
remote: PublicKey::arbitrary(g),
at: Oid::from_sha1(Arbitrary::arbitrary(g)),
at: Oid::arbitrary(g),
}
}
}

View File

@ -25,8 +25,7 @@ use crate::test::storage::{MockRepository, MockStorage};
use crate::{cob, git};
pub fn oid() -> storage::Oid {
let oid_bytes: [u8; 20] = r#gen(1);
storage::Oid::from_sha1(oid_bytes)
r#gen(1)
}
pub fn entry_id() -> cob::EntryId {