Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions std/bigint.d
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,7 @@ unittest
*/
void divMod(const BigInt dividend, const BigInt divisor, out BigInt quotient, out BigInt remainder) pure nothrow @safe
{
assert(!divisor.isZero(), "BigInt division by zero");
BigUint q, r;
BigUint.divMod(dividend.data, divisor.data, q, r);
quotient.sign = dividend.sign != divisor.sign;
Expand Down Expand Up @@ -2352,6 +2353,26 @@ void divMod(const BigInt dividend, const BigInt divisor, out BigInt quotient, ou
assert(remainder == 0);
}

// https://github.com/dlang/phobos/issues/10784
@system unittest
{
import core.exception : AssertError;
BigInt quotient, remainder;
bool caught;
try
divMod(BigInt("1234"), BigInt(0), quotient, remainder);
catch (AssertError)
caught = true;
assert(caught, "divMod by zero should assert");
}

// https://github.com/dlang/phobos/issues/10784
@safe pure unittest
{
import std.exception : assertThrown;
assertThrown(BigInt(100) / BigInt(0));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails, does assertThrown only catch exceptions?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can catch any Throwable, but by default it only catches Exception.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fragile test either way, it assumes a specific checkaction for asserts. I would not write a unittest for this.

}

// https://issues.dlang.org/show_bug.cgi?id=19740
@safe unittest
{
Expand Down
Loading