Skip to content

Commit 10730ce

Browse files
committed
Tests and chunk size
1 parent 69747d3 commit 10730ce

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/chunker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl Chunker {
195195

196196
self.call_stack.extend(removed_scripts.into_iter().rev());
197197
assert!(num_unclosed_ifs >= 0, "More OP_ENDIF's than OP_IF's after undo step. (This means there is a bug in the undo logic.)");
198-
assert_eq!(num_unclosed_ifs, 0, "Unable to make up for the OP_IF's in this chunk. Consider a larger target size or more tolerance. Unclosed OP_IF's: {:?}, removed_len: {}, undo.call_stack: {:?}, chunks: {:?}", num_unclosed_ifs, removed_len, undo_info.call_stack, self.chunks);
198+
assert_eq!(num_unclosed_ifs, 0, "Unable to make up for the OP_IF's in this chunk. Consider a larger target size or more tolerance. Unclosed OP_IF's: {:?}, removed_len: {}, undo.call_stack: {:?}, chunks: {:?}", num_unclosed_ifs, removed_len, undo_info.call_stack, self.chunks.iter().map(|chunk| chunk.size).collect::<Vec<_>>());
199199
(undo_info.call_stack, removed_len)
200200
}
201201

tests/test.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,39 @@ fn test_if_positions() {
310310
assert_eq!(script.extra_endif_positions(), vec![]);
311311
}
312312

313+
#[test]
314+
fn test_if_positions_opif() {
315+
let script = script! {
316+
OP_IF
317+
};
318+
319+
assert_eq!(script.num_unclosed_ifs(), 1);
320+
assert_eq!(script.unclosed_if_positions(), vec![0]);
321+
assert_eq!(script.extra_endif_positions(), vec![]);
322+
}
323+
324+
#[test]
325+
fn test_if_positions_opnotif() {
326+
let script = script! {
327+
OP_NOTIF
328+
};
329+
330+
assert_eq!(script.num_unclosed_ifs(), 1);
331+
assert_eq!(script.unclosed_if_positions(), vec![0]);
332+
assert_eq!(script.extra_endif_positions(), vec![]);
333+
}
334+
335+
#[test]
336+
fn test_if_positions_opendif() {
337+
let script = script! {
338+
OP_ENDIF
339+
};
340+
341+
assert_eq!(script.num_unclosed_ifs(), -1);
342+
assert_eq!(script.unclosed_if_positions(), vec![]);
343+
assert_eq!(script.extra_endif_positions(), vec![0]);
344+
}
345+
313346
pub fn if_sub_script() -> Script {
314347
script! {
315348
OP_IF

0 commit comments

Comments
 (0)