Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Cargo.lock
bench-log
.*.swp
wiki
tags
3 changes: 3 additions & 0 deletions regex-syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ description = "A regular expression parser."
[dev-dependencies]
quickcheck = "0.2"
rand = "0.3"

[profile.test]
codegen-units = 8
12 changes: 9 additions & 3 deletions regex-syntax/src/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,12 @@ impl Literals {
}
} else {
if let Some(i) = position(&lit2, &candidate) {
candidate.truncate(i);
candidate.cut();
lit2.cut();
let mut new_candidate = candidate.clone();
new_candidate.truncate(i);
new_candidate.cut();
old.push(new_candidate);
candidate.clear();
}
}
// Oops, the candidate is already represented in the set.
Expand Down Expand Up @@ -1385,14 +1388,17 @@ mod tests {
vec![M("Mo'"), M("Mu'"), M("Mo"), M("Mu")],
vec![C("Mo"), C("Mu")]);
test_unamb!(unambiguous11,
vec![M("zazb"), M("azb")], vec![C("azb"), C("z")]);
vec![M("zazb"), M("azb")], vec![C("a"), C("z")]);
test_unamb!(unambiguous12, vec![M("foo"), C("foo")], vec![C("foo")]);
test_unamb!(unambiguous13,
vec![M("ABCX"), M("CDAX"), M("BCX")],
vec![C("A"), C("BCX"), C("CD")]);
test_unamb!(unambiguous14,
vec![M("IMGX"), M("MVIX"), M("MGX"), M("DSX")],
vec![M("DSX"), C("I"), C("MGX"), C("MV")]);
test_unamb!(unambiguous15,
vec![M("IMG_"), M("MG_"), M("CIMG")],
vec![C("C"), C("I"), C("MG_")]);


// ************************************************************************
Expand Down
6 changes: 5 additions & 1 deletion tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ ismatch!(partial_anchor_alternate_begin, u!(r"^a|z"), "yyyyya", false);
ismatch!(partial_anchor_alternate_end, u!(r"a$|z"), "ayyyyy", false);

// See: https://github.com/rust-lang-nursery/regex/issues/289
mat!(lits_unambiguous, u!(r"(ABC|CDA|BC)X"), "CDAX", Some((0, 4)));
mat!(lits_unambiguous1, u!(r"(ABC|CDA|BC)X"), "CDAX", Some((0, 4)));

// See: https://github.com/rust-lang-nursery/regex/issues/291
mat!(lits_unambiguous2, u!(r"((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$"),
"CIMG2341", Some((0, 8)), Some((0, 4)), None, Some((0, 4)), Some((4, 8)));