From d43b38fadaecfd4280e262dc84066b489459535f Mon Sep 17 00:00:00 2001 From: Mike Cronce Date: Fri, 15 Apr 2022 13:02:45 -0400 Subject: [PATCH] + (optional, feature-gated) proptest::Arbitrary implementation --- Cargo.toml | 2 ++ src/lib.rs | 2 ++ src/proptest_impls.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/proptest_impls.rs diff --git a/Cargo.toml b/Cargo.toml index 536e686263..655c2dc8e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,9 @@ exclude = [".cargo/**/*", ".github/**/*"] all-features = true [dependencies] +proptest = { version = "1.0.0", optional = true } serde = { version = "1", features = ["derive"], optional = true } [features] serde1 = ["serde"] +proptest1 = ["proptest"] diff --git a/src/lib.rs b/src/lib.rs index 5dc863e513..3f286e5452 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,8 @@ use std::{ sync::Arc, }; +#[cfg(feature = "proptest1")] +mod proptest_impls; #[cfg(feature = "serde1")] mod serde_impls; #[cfg(test)] diff --git a/src/proptest_impls.rs b/src/proptest_impls.rs new file mode 100644 index 0000000000..c36d122042 --- /dev/null +++ b/src/proptest_impls.rs @@ -0,0 +1,28 @@ +// Copyright (c) The camino Contributors +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! [proptest::Arbitrary](Arbitrary) implementation for `Utf8PathBuf` and `Box`. Note +//! that implementions for `Rc` and `Arc` are not currently possible due to +//! orphan rules - this crate doesn't define `Rc`/`Arc` nor `Arbitrary`, so it can't define those +//! implementations. + +use proptest::arbitrary::{any_with, Arbitrary, StrategyFor}; +use proptest::strategy::{MapInto, Strategy}; + +use crate::{Utf8Path, Utf8PathBuf}; + +impl Arbitrary for Utf8PathBuf { + type Parameters = ::Parameters; + type Strategy = MapInto, Self>; + fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { + any_with::(args).prop_map_into() + } +} + +impl Arbitrary for Box { + type Parameters = ::Parameters; + type Strategy = MapInto, Self>; + fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { + any_with::(args).prop_map_into() + } +}