Skip to content

Commit 7ad5761

Browse files
committed
Replace char::ANY with char::any().
The next version has breaking changes anyway, and this will allow changing the representation of `CharStrategy` to be more efficient in the future in order to address #16.
1 parent 495a36b commit 7ad5761

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
### Potential Breaking Changes
44

5+
- `proptest::char::ANY` replaced with `proptest::char::any()`.
6+
`proptest::char::ANY` is present but deprecated, and will be removed in
7+
proptest 0.5.0.
8+
59
- Instead of returning `-> Result<Self::Value, String>`, strategies are
610
expected to return `-> Result<Self::Value, Reason>` instead. `Reason` reduces
711
the amount of heap allocations, especially for `.prop_filter(..)` where you

src/char.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,18 @@ const WHOLE_RANGE: &[CharRange] = &[
190190
('\x00', ::std::char::MAX)
191191
];
192192

193-
/// The `CharStrategy` which picks from literally any character, with
194-
/// the default biases.
193+
/// Creates a `CharStrategy` which picks from literally any character, with the
194+
/// default biases.
195+
pub fn any() -> CharStrategy<'static> {
196+
CharStrategy {
197+
special: Cow::Borrowed(DEFAULT_SPECIAL_CHARS),
198+
preferred: Cow::Borrowed(DEFAULT_PREFERRED_RANGES),
199+
ranges: Cow::Borrowed(WHOLE_RANGE),
200+
}
201+
}
202+
203+
#[allow(missing_docs)]
204+
#[deprecated(since="0.4.0", note="replaced with proptest::char::any()")]
195205
pub const ANY: CharStrategy<'static> = CharStrategy {
196206
special: Cow::Borrowed(DEFAULT_SPECIAL_CHARS),
197207
preferred: Cow::Borrowed(DEFAULT_PREFERRED_RANGES),
@@ -336,7 +346,7 @@ mod test {
336346
let mut runner = TestRunner::default();
337347

338348
for _ in 0..1024 {
339-
let ch = ANY.new_value(&mut runner).unwrap().current();
349+
let ch = any().new_value(&mut runner).unwrap().current();
340350
if '🕴' == ch {
341351
men_in_business_suits_levitating += 1;
342352
} else if ch >= ' ' && ch <= '~' {
@@ -354,7 +364,7 @@ mod test {
354364
let mut runner = TestRunner::default();
355365

356366
for _ in 0..256 {
357-
let mut value = ANY.new_value(&mut runner).unwrap();
367+
let mut value = any().new_value(&mut runner).unwrap();
358368

359369
if value.current() <= ' ' { continue; }
360370

@@ -369,7 +379,7 @@ mod test {
369379

370380
#[test]
371381
fn test_sanity() {
372-
check_strategy_sanity(ANY, Some(CheckStrategySanityOptions {
382+
check_strategy_sanity(any(), Some(CheckStrategySanityOptions {
373383
// `simplify()` can itself `complicate()` back to the starting
374384
// position, so the overly strict complicate-after-simplify check
375385
// must be disabled.

src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn bytes_regex_parsed(expr: &rs::Expr)
123123
.collect::<Vec<_>>()).sboxed())
124124
},
125125

126-
AnyChar => Ok(char::ANY.prop_map(to_bytes).sboxed()),
126+
AnyChar => Ok(char::any().prop_map(to_bytes).sboxed()),
127127
AnyCharNoNL => {
128128
static NONL_RANGES: &[(char,char)] = &[
129129
('\x00', '\x09'),

0 commit comments

Comments
 (0)