Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 11 additions & 3 deletions Lib/test/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,8 @@ def test_possessive_quantifiers(self):
self.assertIsNone(re.match("^x{}+$", "xxx"))
self.assertTrue(re.match("^x{}+$", "x{}"))

@unittest.expectedFailure # TODO: RUSTPYTHON
# correction #7183 make it successful as in Cpython3.14
#@unittest.expectedFailure # TODO: RUSTPYTHON
Comment thread
wvmscs marked this conversation as resolved.
Outdated
def test_fullmatch_possessive_quantifiers(self):
self.assertTrue(re.fullmatch(r'a++', 'a'))
self.assertTrue(re.fullmatch(r'a*+', 'a'))
Expand Down Expand Up @@ -2565,6 +2566,11 @@ def test_fullmatch_possessive_quantifiers(self):
self.assertTrue(re.fullmatch(r'(?:ab)?+c', 'abc'))
self.assertTrue(re.fullmatch(r'(?:ab){1,3}+c', 'abc'))

# added for test of correction #7183
def test_possessive_repeat(self):
Comment thread
wvmscs marked this conversation as resolved.
Outdated
self.assertTrue(re.fullmatch("([0-9]++(?:\.[0-9]+)*+)", "1.25.38"))
self.assertEqual(re.fullmatch("([0-9]++(?:\.[0-9]+)*+)", "1.25.38").groups()[0], "1.25.38")

def test_findall_possessive_quantifiers(self):
self.assertEqual(re.findall(r'a++', 'aab'), ['aa'])
self.assertEqual(re.findall(r'a*+', 'aab'), ['aa', '', ''])
Expand All @@ -2590,7 +2596,8 @@ def test_atomic_grouping(self):
self.assertIsNone(re.match(r'(?>x)++x', 'xxx'))
self.assertIsNone(re.match(r'(?>x++)x', 'xxx'))

@unittest.expectedFailure # TODO: RUSTPYTHON
# correction #7183 make it successful as in Cpython3.14
#@unittest.expectedFailure # TODO: RUSTPYTHON
Comment thread
wvmscs marked this conversation as resolved.
Outdated
def test_fullmatch_atomic_grouping(self):
self.assertTrue(re.fullmatch(r'(?>a+)', 'a'))
self.assertTrue(re.fullmatch(r'(?>a*)', 'a'))
Expand Down Expand Up @@ -2629,7 +2636,8 @@ def test_findall_atomic_grouping(self):
self.assertEqual(re.findall(r'(?>(?:ab)?)', 'ababc'), ['ab', 'ab', '', ''])
self.assertEqual(re.findall(r'(?>(?:ab){1,3})', 'ababc'), ['abab'])

@unittest.expectedFailure # TODO: RUSTPYTHON
# correction #7183 make it success as in Cpython3.14
#@unittest.expectedFailure # TODO: RUSTPYTHON
Comment thread
wvmscs marked this conversation as resolved.
Outdated
def test_bug_gh91616(self):
self.assertTrue(re.fullmatch(r'(?s:(?>.*?\.).*)\z', "a.txt")) # reproducer
self.assertTrue(re.fullmatch(r'(?s:(?=(?P<g0>.*?\.))(?P=g0).*)\z', "a.txt"))
Expand Down
4 changes: 4 additions & 0 deletions crates/sre_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ license.workspace = true
name = "benches"
harness = false

[[test]]
name = "tests"


Comment thread
youknowone marked this conversation as resolved.
Outdated
[dependencies]
rustpython-wtf8 = { workspace = true }
num_enum = { workspace = true }
Expand Down
13 changes: 10 additions & 3 deletions crates/sre_engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@
Jump::PossessiveRepeat1 => {
let min_count = ctx.peek_code(req, 2) as isize;
if ctx.count < min_count {
break 'context ctx.next_offset(4, Jump::PossessiveRepeat2);
// modified next.toplevel from herited to false

Check warning on line 473 in crates/sre_engine/src/engine.rs

View workflow job for this annotation

GitHub Actions / Lint Rust & Python code

Unknown word (herited)
let mut next = ctx.next_offset(4, Jump::PossessiveRepeat2);
next.toplevel = false;
break 'context next;
Comment thread
wvmscs marked this conversation as resolved.
Outdated
}
// zero match protection
ctx.cursor.position = usize::MAX;
Expand All @@ -494,7 +497,9 @@
{
state.marks.push();
ctx.cursor = state.cursor;
break 'context ctx.next_offset(4, Jump::PossessiveRepeat4);
let mut next = ctx.next_offset(4, Jump::PossessiveRepeat4);
next.toplevel = false; // modified next.toplevel from herited to false

Check warning on line 501 in crates/sre_engine/src/engine.rs

View workflow job for this annotation

GitHub Actions / Lint Rust & Python code

Unknown word (herited)
break 'context next;
}
ctx.cursor = state.cursor;
ctx.skip_code_from(req, 1);
Expand Down Expand Up @@ -832,7 +837,9 @@
/* <ATOMIC_GROUP> <skip> pattern <SUCCESS> tail */
SreOpcode::ATOMIC_GROUP => {
state.cursor = ctx.cursor;
break 'context ctx.next_offset(2, Jump::AtomicGroup1);
let mut next_ctx = ctx.next_offset(2, Jump::AtomicGroup1);
next_ctx.toplevel = false; // modified next.toplevel from herited to false

Check warning on line 841 in crates/sre_engine/src/engine.rs

View workflow job for this annotation

GitHub Actions / Lint Rust & Python code

Unknown word (herited)
break 'context next_ctx;
}
/* <POSSESSIVE_REPEAT> <skip> <1=min> <2=max> pattern
<SUCCESS> tail */
Expand Down
12 changes: 12 additions & 0 deletions crates/sre_engine/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ fn test_possessive_quantifier() {
assert!(state.py_match(&req));
}

#[test]
fn test_possessive_repeat_fullmatch() {
// pattern p = re.compile("([0-9]++(?:\.[0-9]+)*+)", re.I )
// [INFO, 4, 0, 1, 4294967295, MARK, 0, POSSESSIVE_REPEAT_ONE, 10, 1, MAXREPEAT, IN, 5, RANGE, 48, 57, FAILURE, SUCCESS, POSSESSIVE_REPEAT, 16, 0, MAXREPEAT, LITERAL, 46, REPEAT_ONE, 10, 1, MAXREPEAT, IN, 5, RANGE, 48, 57, FAILURE, SUCCESS, SUCCESS, MARK, 1, SUCCESS]
// START GENERATED by generate_tests.py
#[rustfmt::skip] let p = Pattern { pattern: "([0-9]++(?:\\.[0-9]+)*+)", code: &[14, 4, 0, 1, 4294967295, 17, 0, 29, 10, 1, 4294967295, 13, 5, 22, 48, 57, 0, 1, 28, 16, 0, 4294967295, 16, 46, 24, 10, 1, 4294967295, 13, 5, 22, 48, 57, 0, 1, 1, 17, 1, 1] };
// END GENERATED
let (mut req, mut state) = p.state("1.25.38");
req.match_all = true;
assert!(state.py_match(&req), "should match");
}

#[test]
fn test_possessive_atomic_group() {
// pattern p = re.compile('(?>x)++x')
Expand Down
3 changes: 1 addition & 2 deletions crates/vm/src/stdlib/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,7 @@ mod sys {
Ok(exc) => {
// PyErr_Display: try traceback._print_exception_bltin first
if let Ok(tb_mod) = vm.import("traceback", 0)
&& let Ok(print_exc_builtin) =
tb_mod.get_attr("_print_exception_bltin", vm)
&& let Ok(print_exc_builtin) = tb_mod.get_attr("_print_exception_bltin", vm)
&& print_exc_builtin
.call((exc.as_object().to_owned(),), vm)
.is_ok()
Expand Down
Loading