smartstring/
proptest.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5//! `proptest` strategies (requires the `proptest` feature flag).
6
7use crate::{SmartString, SmartStringMode};
8use proptest::proptest;
9use proptest::strategy::{BoxedStrategy, Strategy};
10use proptest::string::Error;
11
12/// Creates a strategy which generates [`SmartString`][SmartString]s matching the given regular expression.
13///
14/// [SmartString]: ../struct.SmartString.html
15pub fn string_regex<Mode: SmartStringMode>(
16    regex: &str,
17) -> Result<BoxedStrategy<SmartString<Mode>>, Error>
18where
19    Mode: 'static,
20{
21    proptest::string::string_regex(regex).map(|g| g.prop_map(SmartString::from).boxed())
22}
23
24proptest! {
25    #[test]
26    fn strategy(string in string_regex(".+").unwrap()) {
27        assert!(!SmartString::<crate::LazyCompact>::is_empty(&string));
28    }
29}