Skip to content

Commit

Permalink
build(deps): bump regex-syntax from 0.6 to 0.7 (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjackman authored Jul 13, 2023
1 parent dcb181c commit f248d51
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 59 deletions.
2 changes: 2 additions & 0 deletions proptest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.2.0

- `regex-syntax` version 0.7 is now used.

### Breaking Changes

- `PROPTEST_` environment variables now take precedence over tests' non-default
Expand Down
4 changes: 2 additions & 2 deletions proptest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ features = ["libm"]
[dependencies.regex-syntax]
# If you change this, make sure to also bump the `regex` dependency to a
# version that also uses this version of regex-syntax.
version = "0.6.0"
version = "0.7"
optional = true

[dependencies.bit-set]
Expand Down Expand Up @@ -116,7 +116,7 @@ version = "0.52.0"
optional = true

[dev-dependencies]
regex = "1.0"
regex = "1"

[package.metadata.docs.rs]
all-features = true
Expand Down
97 changes: 40 additions & 57 deletions proptest/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ use core::mem;
use core::ops::RangeInclusive;
use core::u32;

use regex_syntax::hir::{
self, Hir,
HirKind::*,
Literal::*,
RepetitionKind::{self, *},
RepetitionRange::*,
};
use regex_syntax::hir::{self, Hir, HirKind::*, Repetition};
use regex_syntax::{Error as ParseError, Parser};

use crate::bool;
Expand Down Expand Up @@ -176,11 +170,7 @@ pub fn bytes_regex_parsed(expr: &Hir) -> ParseResult<Vec<u8>> {
match expr.kind() {
Empty => Ok(Just(vec![]).sboxed()),

Literal(lit) => Ok(Just(match lit {
Unicode(scalar) => to_bytes(*scalar),
Byte(byte) => vec![*byte],
})
.sboxed()),
Literal(lit) => Ok(Just(lit.0.to_vec()).sboxed()),

Class(class) => Ok(match class {
hir::Class::Unicode(class) => {
Expand All @@ -192,19 +182,13 @@ pub fn bytes_regex_parsed(expr: &Hir) -> ParseResult<Vec<u8>> {
}
}),

Repetition(rep) => Ok(vec(
bytes_regex_parsed(&rep.hir)?,
to_range(rep.kind.clone())?,
)
.prop_map(|parts| {
parts.into_iter().fold(vec![], |mut acc, child| {
acc.extend(child);
acc
})
})
.sboxed()),
Repetition(rep) => {
Ok(vec(bytes_regex_parsed(&rep.sub)?, to_range(rep)?)
.prop_map(|parts| parts.concat())
.sboxed())
}

Group(group) => bytes_regex_parsed(&group.hir).map(|v| v.0),
Capture(capture) => bytes_regex_parsed(&capture.sub).map(|v| v.0),

Concat(subs) => {
let subs = ConcatIter {
Expand Down Expand Up @@ -232,12 +216,8 @@ pub fn bytes_regex_parsed(expr: &Hir) -> ParseResult<Vec<u8>> {
Ok(Union::try_new(subs.iter().map(bytes_regex_parsed))?.sboxed())
}

Anchor(_) => {
unsupported("line/text anchors not supported for string generation")
}

WordBoundary(_) => unsupported(
"word boundary tests not supported for string generation",
Look(_) => unsupported(
"anchors/boundaries not supported for string generation",
),
}
.map(RegexGeneratorStrategy)
Expand Down Expand Up @@ -298,8 +278,7 @@ impl<'a, I: Iterator<Item = &'a Hir>> Iterator for ConcatIter<'a, I> {
while let Some(next) = self.iter.next() {
match next.kind() {
// A literal. Accumulate:
Literal(Unicode(scalar)) => self.buf.extend(to_bytes(*scalar)),
Literal(Byte(byte)) => self.buf.push(*byte),
Literal(literal) => self.buf.extend_from_slice(&literal.0),
// Encountered a non-literal.
_ => {
return if !self.buf.is_empty() {
Expand All @@ -324,31 +303,35 @@ impl<'a, I: Iterator<Item = &'a Hir>> Iterator for ConcatIter<'a, I> {
}
}

fn to_range(kind: RepetitionKind) -> Result<SizeRange, Error> {
Ok(match kind {
ZeroOrOne => size_range(0..=1),
ZeroOrMore => size_range(0..=32),
OneOrMore => size_range(1..=32),
Range(range) => match range {
Exactly(count) if u32::MAX == count => {
return unsupported(
"Cannot have repetition of exactly u32::MAX",
)
}
Exactly(count) => size_range(count as usize),
AtLeast(min) => {
let max = if min < u32::MAX as u32 / 2 {
min as usize * 2
} else {
u32::MAX as usize
};
size_range((min as usize)..max)
}
Bounded(_, max) if u32::MAX == max => {
return unsupported("Cannot have repetition max of u32::MAX")
}
Bounded(min, max) => size_range((min as usize)..(max as usize + 1)),
},
fn to_range(rep: &Repetition) -> Result<SizeRange, Error> {
Ok(match (rep.min, rep.max) {
// Zero or one
(0, Some(1)) => size_range(0..=1),
// Zero or more
(0, None) => size_range(0..=32),
// One or more
(1, None) => size_range(1..=32),
// Exact count of u32::MAX
(u32::MAX, Some(u32::MAX)) => {
return unsupported("Cannot have repetition of exactly u32::MAX");
}
// Exact count
(min, Some(max)) if min == max => size_range(min as usize),
// At least min
(min, None) => {
let max = if min < u32::MAX as u32 / 2 {
min as usize * 2
} else {
u32::MAX as usize
};
size_range((min as usize)..max)
}
// Bounded range with max of u32::MAX
(_, Some(u32::MAX)) => {
return unsupported("Cannot have repetition max of u32::MAX")
}
// Bounded range
(min, Some(max)) => size_range((min as usize)..(max as usize + 1)),
})
}

Expand Down

0 comments on commit f248d51

Please sign in to comment.