Skip to content

Commit b162a4f

Browse files
authored
test: Add exec tests for widen op (#2043)
1 parent fefa599 commit b162a4f

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

hugr-llvm/src/extension/int.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,35 +1463,43 @@ mod test {
14631463
}
14641464

14651465
#[rstest]
1466-
fn test_exec_widen(int_exec_ctx: TestContext) {
1467-
let from: u8 = 1;
1466+
#[case(-127)]
1467+
#[case(-1)]
1468+
#[case(0)]
1469+
#[case(1)]
1470+
#[case(127)]
1471+
fn test_exec_widen(int_exec_ctx: TestContext, #[case] num: i16) {
1472+
let from: u8 = 3;
14681473
let to: u8 = 6;
14691474
let ty = INT_TYPES[to as usize].clone();
1470-
let input = ConstInt::new_u(from, 1).unwrap();
14711475

1472-
let ext_op = int_ops::EXTENSION
1473-
.instantiate_extension_op(
1474-
"iwiden_u".as_ref(),
1475-
[u64::from(from).into(), u64::from(to).into()],
1476-
)
1477-
.unwrap();
1476+
if num >= 0 {
1477+
let input = ConstInt::new_u(from, num as u64).unwrap();
14781478

1479-
let hugr = test_int_op_with_results::<1>(ext_op, to, Some([input]), ty.clone());
1479+
let ext_op = int_ops::EXTENSION
1480+
.instantiate_extension_op(
1481+
"iwiden_u".as_ref(),
1482+
[(from as u64).into(), (to as u64).into()],
1483+
)
1484+
.unwrap();
14801485

1481-
assert_eq!(int_exec_ctx.exec_hugr_u64(hugr, "main"), 1);
1486+
let hugr = test_int_op_with_results::<1>(ext_op, to, Some([input]), ty.clone());
1487+
1488+
assert_eq!(int_exec_ctx.exec_hugr_u64(hugr, "main"), num as u64);
1489+
}
14821490

1483-
let input = ConstInt::new_s(from, 1).unwrap();
1491+
let input = ConstInt::new_s(from, num as i64).unwrap();
14841492

14851493
let ext_op = int_ops::EXTENSION
14861494
.instantiate_extension_op(
14871495
"iwiden_s".as_ref(),
1488-
[u64::from(from).into(), u64::from(to).into()],
1496+
[(from as u64).into(), (to as u64).into()],
14891497
)
14901498
.unwrap();
14911499

14921500
let hugr = test_int_op_with_results::<1>(ext_op, to, Some([input]), ty.clone());
14931501

1494-
assert_eq!(int_exec_ctx.exec_hugr_u64(hugr, "main"), 1);
1502+
assert_eq!(int_exec_ctx.exec_hugr_i64(hugr, "main"), num as i64);
14951503
}
14961504

14971505
#[rstest]

0 commit comments

Comments
 (0)