make division by zero (integer) not trap

This commit is contained in:
Folkert 2024-01-28 21:16:13 +01:00
parent 0b0127f45e
commit 979128cf32
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
88 changed files with 549 additions and 545 deletions

View file

@ -1154,19 +1154,20 @@ fn gen_div_u64() {
assert_evals_to!("1000u64 // 10", 100, u64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
#[should_panic(expected = r#"User crash with message: "Integer division by 0!"#)]
fn gen_div_by_zero_i64() {
assert_evals_to!("1i64 // 0", 100, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn gen_div_checked_i64() {
assert_evals_to!(
indoc!(
r"
when Num.divTruncChecked 1000 10 is
Ok val -> val
Err _ -> -1
"
),
100,
i64
"Num.divTruncChecked 1000 10",
RocResult::ok(100),
RocResult<i64, ()>
);
}
@ -1174,15 +1175,9 @@ fn gen_div_checked_i64() {
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn gen_div_checked_by_zero_i64() {
assert_evals_to!(
indoc!(
r"
when Num.divTruncChecked 1000 0 is
Err DivByZero -> 99
_ -> -24
"
),
99,
i64
"Num.divTruncChecked 1000 0",
RocResult::err(()),
RocResult<i64, ()>
);
}