From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/camino/src/proptest_impls.rs | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 third_party/rust/camino/src/proptest_impls.rs (limited to 'third_party/rust/camino/src/proptest_impls.rs') diff --git a/third_party/rust/camino/src/proptest_impls.rs b/third_party/rust/camino/src/proptest_impls.rs new file mode 100644 index 0000000000..81776f226f --- /dev/null +++ b/third_party/rust/camino/src/proptest_impls.rs @@ -0,0 +1,60 @@ +// 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. + +// NOTE: #[cfg(feature = "proptest1")] is specified here to work with `doc_cfg`. + +use crate::{Utf8Path, Utf8PathBuf}; +use proptest::{arbitrary::StrategyFor, prelude::*, strategy::MapInto}; + +/// The [`Arbitrary`] impl for `Utf8PathBuf` returns a path with between 0 and 8 components, +/// joined by the [`MAIN_SEPARATOR`](std::path::MAIN_SEPARATOR) for the platform. (Each component is +/// randomly generated, and may itself contain one or more separators.) +/// +/// On Unix, this generates an absolute path half of the time and a relative path the other half. +/// +/// On Windows, this implementation doesn't currently generate +/// [`Utf8PrefixComponent`](crate::Utf8PrefixComponent) instances, though in the future it might. +#[cfg(feature = "proptest1")] +impl Arbitrary for Utf8PathBuf { + type Parameters = ::Parameters; + type Strategy = BoxedStrategy; + + fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { + ( + any::(), + prop::collection::vec(any_with::(args), 0..8), + ) + .prop_map(|(is_relative, components)| { + let initial_component = + is_relative.then(|| format!("{}", std::path::MAIN_SEPARATOR)); + initial_component + .into_iter() + .chain(components.into_iter()) + .collect() + }) + .boxed() + } +} + +/// The [`Arbitrary`] impl for `Box` returns a path with between 0 and 8 components, +/// joined by the [`MAIN_SEPARATOR`](std::path::MAIN_SEPARATOR) for the platform. (Each component is +/// randomly generated, and may itself contain one or more separators.) +/// +/// On Unix, this generates an absolute path half of the time and a relative path the other half. +/// +/// On Windows, this implementation doesn't currently generate +/// [`Utf8PrefixComponent`](crate::Utf8PrefixComponent) instances, though in the future it might. +#[cfg(feature = "proptest1")] +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() + } +} -- cgit v1.2.3