Skip to content

Commit a9ed7de

Browse files
committed
fix _count general case
1 parent 39c0106 commit a9ed7de

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎src/engine.rs‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,19 +1904,17 @@ fn _count<S: StrDrive>(
19041904
/* General case */
19051905
let mut count = 0;
19061906

1907-
let reset_position = ctx.code_position;
1908-
19091907
while count < max_count {
1910-
ctx.code_position = reset_position;
1911-
if !_match(req, state, ctx) {
1908+
let sub_ctx = MatchContext {
1909+
toplevel: true,
1910+
jump: Jump::OpCode,
1911+
repeat_ctx_id: usize::MAX,
1912+
count: -1,
1913+
..ctx
1914+
};
1915+
if !_match(req, state, sub_ctx) {
19121916
break;
19131917
}
1914-
// let code = ctx.peek_code(req, 0);
1915-
// let code = SreOpcode::try_from(code).unwrap();
1916-
// dispatch(req, state, &mut ctx, code);
1917-
// if ctx.has_matched == Some(false) {
1918-
// break;
1919-
// }
19201918
count += 1;
19211919
}
19221920
return count;

‎tests/tests.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,13 @@ fn test_info_literal2() {
121121
let (req, mut state) = p.state("pythonpython");
122122
assert!(state.search(req));
123123
}
124+
125+
#[test]
126+
fn test_repeat_in_assertions() {
127+
// pattern p = re.compile('^([ab]*?)(?=(b)?)c', re.IGNORECASE)
128+
// START GENERATED by generate_tests.py
129+
#[rustfmt::skip] let p = Pattern { code: &[14, 4, 0, 1, 4294967295, 6, 0, 17, 0, 26, 10, 0, 4294967295, 39, 5, 22, 97, 98, 0, 1, 17, 1, 4, 14, 0, 23, 9, 0, 1, 17, 2, 40, 98, 17, 3, 18, 1, 40, 99, 1] };
130+
// END GENERATED
131+
let (req, mut state) = p.state("abc");
132+
assert!(state.search(req));
133+
}

0 commit comments

Comments
 (0)