On Wednesday, 20 November 2024 at 09:48:06 UTC, Jonathan M Davis wrote:
>On Tuesday, November 19, 2024 11:11:58 PM MST Sharif yt via
>...
Inspired by an idea I came across (and expanded upon), this
approach allows inline assertions using unittest() with
parentheses instead of braces {}...
...
So, IMHO, this would be adding more complication to the language just to try to make it easier to write inadequate tests, and I don't think think that we should be doing that.
I agree with Jonathan. In addition, instead of the ordinary assert()
, I use the following assert_eq()
, inspired by Rust. This gives me 2 extra usage featıres.
alias equal = assert_eq;
template assert_eq(string msg = "error", R)
{
enum pred = "a != b";
bool assert_eq(in R p, in R q)
{
static if (imported!"std.range".hasLength!R)
{
import std.algorithm : equal;
if (p.equal!pred(q))
goto _error_;
}
if (p != q)
_error_:
static if (msg.length) assert(0, msg);
else return 0;
return 1;
}
}
SDB@79