mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-25 14:20:31 +08:00
Merge remote-tracking branch 'origin/generators-port'
* origin/generators-port: git-ext/t: Port `gen_oid*` generator methods
This commit is contained in:
@@ -14,13 +14,21 @@ doc = false
|
||||
[features]
|
||||
test = []
|
||||
|
||||
[dependencies]
|
||||
proptest = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.5"
|
||||
minicbor = "0.13"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
|
||||
[dev-dependencies.radicle-git-ext]
|
||||
[dependencies.git2]
|
||||
version = "0.15.0"
|
||||
default-features = false
|
||||
features = ["vendored-libgit2"]
|
||||
|
||||
[dependencies.radicle-git-ext]
|
||||
path = ".."
|
||||
features = ["minicbor", "serde"]
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright © 2019-2022 The Radicle Foundation <hello@radicle.foundation>
|
||||
//
|
||||
// This file is part of radicle-git, distributed under the GPLv3 with Radicle
|
||||
// Linking Exception. For full terms see the included LICENSE file.
|
||||
|
||||
//! Provides proptest generators
|
||||
|
||||
pub mod urn;
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright © 2019-2022 The Radicle Foundation <hello@radicle.foundation>
|
||||
//
|
||||
// This file is part of radicle-git, distributed under the GPLv3 with Radicle
|
||||
// Linking Exception. For full terms see the included LICENSE file.
|
||||
|
||||
use proptest::prelude::*;
|
||||
use radicle_git_ext::Oid;
|
||||
|
||||
/// A proptest strategy that generates [`radicle_git_ext::oid::Oid`] values
|
||||
/// of the type indicated in parameter `kind`
|
||||
pub fn gen_oid(kind: git2::ObjectType) -> impl Strategy<Value = Oid> {
|
||||
any::<Vec<u8>>()
|
||||
.prop_map(move |bytes| git2::Oid::hash_object(kind, &bytes).map(Oid::from).unwrap())
|
||||
}
|
||||
|
||||
/// A proptest strategy that generates [`radicle_git_ext::oid::Oid`] values
|
||||
/// of the type indicated in parameter `kind` or a zeroed `Oid` with
|
||||
/// equal probability
|
||||
pub fn gen_oid_with_zero(kind: git2::ObjectType) -> impl Strategy<Value = Oid> {
|
||||
prop_oneof![gen_oid(kind), Just(git2::Oid::zero().into()),]
|
||||
}
|
||||
@@ -5,5 +5,8 @@
|
||||
#[macro_use]
|
||||
extern crate assert_matches;
|
||||
|
||||
#[cfg(any(test, feature = "test"))]
|
||||
pub mod gen;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
Reference in New Issue
Block a user