mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
make division by zero (integer) not trap
This commit is contained in:
parent
0b0127f45e
commit
979128cf32
88 changed files with 549 additions and 545 deletions
|
@ -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, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue