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() + } +}