Skip to content

Commit 767c636

Browse files
committed
add test for complex pattern matching in match
1 parent 37cbc75 commit 767c636

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

examples/pattern_matching.simf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fn main() {
2+
let complex_pattern: Either<(u32, u32, (u1, u1)), [u1; 8]> = Left((32, 3, (0, 1)));
3+
4+
let a: u32 = match complex_pattern {
5+
Left((a, b,(c, d)): (u32, u32, (u1, u1))) => {
6+
assert!(jet::eq_32(b, 3));
7+
assert!(jet::eq_1(c, 0));
8+
assert!(jet::eq_1(d, 1));
9+
a
10+
}
11+
Right(_: [u1; 8]) => 0,
12+
};
13+
14+
assert!(jet::eq_32(a, 32));
15+
}

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,13 @@ pub(crate) mod tests {
491491
.assert_run_success();
492492
}
493493

494+
#[test]
495+
fn pattern_matching() {
496+
TestCase::program_file("./examples/pattern_matching.simf")
497+
.with_witness_values(WitnessValues::default())
498+
.assert_run_success();
499+
}
500+
494501
#[test]
495502
#[cfg(feature = "serde")]
496503
fn sighash_non_interactive_fee_bump() {

0 commit comments

Comments
 (0)