add test for divCeil by 0

This commit is contained in:
John Murray 2023-11-20 23:27:24 -05:00
parent 863ecd8da5
commit abc92ded95
No known key found for this signature in database
2 changed files with 18 additions and 7 deletions

View file

@ -234,11 +234,9 @@ pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void {
comptime var f = struct {
fn func(a: T, b: T) callconv(.C) T {
return math.divCeil(T, a, b) catch {
roc_panic("integer divison by 0!", 0);
roc_panic("Integer divison by 0!", 0);
unreachable;
};
// return math.divCeil(T, a, b) catch @panic("TODO runtime exception for dividing by 0!");
}
}.func;
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
@ -384,7 +382,7 @@ pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void {
fn func(self: T, other: T) callconv(.C) T {
const result = addWithOverflow(T, self, other);
if (result.has_overflowed) {
roc_panic("integer addition overflowed!", 0);
roc_panic("Integer addition overflowed!", 0);
unreachable;
} else {
return result.value;
@ -442,7 +440,7 @@ pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void {
fn func(self: T, other: T) callconv(.C) T {
const result = subWithOverflow(T, self, other);
if (result.has_overflowed) {
roc_panic("integer subtraction overflowed!", 0);
roc_panic("Integer subtraction overflowed!", 0);
unreachable;
} else {
return result.value;
@ -627,7 +625,7 @@ pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []con
fn func(self: T, other: T) callconv(.C) T {
const result = @call(.always_inline, mulWithOverflow, .{ T, W, self, other });
if (result.has_overflowed) {
roc_panic("integer multiplication overflowed!", 0);
roc_panic("Integer multiplication overflowed!", 0);
unreachable;
} else {
return result.value;

View file

@ -801,11 +801,24 @@ fn gen_div_checked_by_zero_dec() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[should_panic(expected = r#"Roc failed with message: "Decimal divison by 0"#)]
#[should_panic(expected = r#"Roc failed with message: "Decimal divison by 0!"#)]
fn gen_div_dec_by_zero() {
assert_evals_to!("1dec / 0", RocDec::from_str_to_i128_unsafe("-1"), i128);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[should_panic(expected = r#"Roc failed with message: "Integer divison by 0!"#)]
fn gen_div_ceil_by_zero() {
assert_evals_to!(
r#"
Num.divCeil 5 0 == 0
"#,
false,
bool
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn gen_int_eq() {